@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +117 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +4 -1
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
|
@@ -18,12 +18,9 @@ class Humidifier {
|
|
|
18
18
|
this.platform = platform;
|
|
19
19
|
this.accessory = accessory;
|
|
20
20
|
this.device = device;
|
|
21
|
-
this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
|
|
22
|
-
this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
23
|
-
// Humidifiers Config
|
|
24
|
-
this.platform.device(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
|
|
25
|
-
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
|
|
26
21
|
// default placeholders
|
|
22
|
+
this.refreshRate();
|
|
23
|
+
this.logs();
|
|
27
24
|
this.CurrentRelativeHumidity = 0;
|
|
28
25
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
29
26
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
@@ -31,6 +28,9 @@ class Humidifier {
|
|
|
31
28
|
this.RelativeHumidityHumidifierThreshold = 0;
|
|
32
29
|
this.CurrentTemperature = 0;
|
|
33
30
|
this.WaterLevel = 0;
|
|
31
|
+
// Humidifiers Config
|
|
32
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
|
|
33
|
+
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
|
|
34
34
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
35
35
|
this.doHumidifierUpdate = new rxjs_1.Subject();
|
|
36
36
|
this.humidifierUpdateInProgress = false;
|
|
@@ -79,12 +79,12 @@ class Humidifier {
|
|
|
79
79
|
// create a new Temperature Sensor service
|
|
80
80
|
// Temperature Sensor Service
|
|
81
81
|
if (device.humidifier?.hide_temperature || device.ble) {
|
|
82
|
-
this.
|
|
82
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
83
83
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
84
84
|
accessory.removeService(this.temperatureservice);
|
|
85
85
|
}
|
|
86
86
|
else if (!this.temperatureservice && !device.ble) {
|
|
87
|
-
this.
|
|
87
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
88
88
|
(this.temperatureservice =
|
|
89
89
|
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
90
90
|
this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
|
|
@@ -102,14 +102,12 @@ class Humidifier {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
|
-
|
|
106
|
-
this.platform.device(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
107
|
-
}
|
|
105
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
108
106
|
}
|
|
109
107
|
// Retrieve initial values and updateHomekit
|
|
110
108
|
this.updateHomeKitCharacteristics();
|
|
111
109
|
// Start an update interval
|
|
112
|
-
(0, rxjs_1.interval)(this.
|
|
110
|
+
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
113
111
|
.pipe((0, operators_1.skipWhile)(() => this.humidifierUpdateInProgress))
|
|
114
112
|
.subscribe(() => {
|
|
115
113
|
this.refreshStatus();
|
|
@@ -125,20 +123,54 @@ class Humidifier {
|
|
|
125
123
|
await this.pushChanges();
|
|
126
124
|
}
|
|
127
125
|
catch (e) {
|
|
128
|
-
this.
|
|
129
|
-
if (this.
|
|
130
|
-
this.
|
|
126
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
127
|
+
if (this.deviceLogging === 'debug') {
|
|
128
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
131
129
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
132
130
|
}
|
|
133
|
-
if (this.
|
|
134
|
-
this.
|
|
131
|
+
if (this.platform.debugMode) {
|
|
132
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
135
133
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
136
134
|
}
|
|
137
|
-
this.apiError(
|
|
135
|
+
this.apiError();
|
|
138
136
|
}
|
|
139
137
|
this.humidifierUpdateInProgress = false;
|
|
140
138
|
});
|
|
141
139
|
}
|
|
140
|
+
refreshRate() {
|
|
141
|
+
if (this.device.refreshRate) {
|
|
142
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
143
|
+
if (this.platform.debugMode) {
|
|
144
|
+
this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (this.platform.config.options.refreshRate) {
|
|
148
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
149
|
+
if (this.platform.debugMode) {
|
|
150
|
+
this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
logs() {
|
|
155
|
+
if (this.device.logging) {
|
|
156
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
157
|
+
if (this.platform.debugMode) {
|
|
158
|
+
this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (this.platform.config.options?.logging) {
|
|
162
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
163
|
+
if (this.platform.debugMode) {
|
|
164
|
+
this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
169
|
+
if (this.platform.debugMode) {
|
|
170
|
+
this.warnLog('Using Device Standard Logging');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
142
174
|
minStep() {
|
|
143
175
|
if (this.device.humidifier?.set_minStep) {
|
|
144
176
|
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
@@ -160,10 +192,10 @@ class Humidifier {
|
|
|
160
192
|
}
|
|
161
193
|
}
|
|
162
194
|
BLEparseStatus() {
|
|
163
|
-
this.
|
|
195
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
|
|
164
196
|
// Current Relative Humidity
|
|
165
197
|
this.CurrentRelativeHumidity = this.percentage;
|
|
166
|
-
this.
|
|
198
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
167
199
|
// Active
|
|
168
200
|
if (this.onState) {
|
|
169
201
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
@@ -171,18 +203,18 @@ class Humidifier {
|
|
|
171
203
|
else {
|
|
172
204
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
173
205
|
}
|
|
174
|
-
this.
|
|
206
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
175
207
|
}
|
|
176
208
|
openAPIparseStatus() {
|
|
177
209
|
if (this.platform.config.credentials?.openToken) {
|
|
178
|
-
this.
|
|
210
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
179
211
|
// Current Relative Humidity
|
|
180
212
|
this.CurrentRelativeHumidity = this.deviceStatus.body.humidity;
|
|
181
|
-
this.
|
|
213
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
182
214
|
// Current Temperature
|
|
183
215
|
if (!this.device.humidifier?.hide_temperature) {
|
|
184
216
|
this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
|
|
185
|
-
this.
|
|
217
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
186
218
|
}
|
|
187
219
|
// Target Humidifier Dehumidifier State
|
|
188
220
|
switch (this.deviceStatus.body.auto) {
|
|
@@ -209,10 +241,10 @@ class Humidifier {
|
|
|
209
241
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
210
242
|
}
|
|
211
243
|
}
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
244
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
245
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
214
246
|
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
215
|
-
this.
|
|
247
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
216
248
|
// Active
|
|
217
249
|
switch (this.deviceStatus.body.power) {
|
|
218
250
|
case 'on':
|
|
@@ -221,7 +253,7 @@ class Humidifier {
|
|
|
221
253
|
default:
|
|
222
254
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
223
255
|
}
|
|
224
|
-
this.
|
|
256
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
225
257
|
// Water Level
|
|
226
258
|
if (this.deviceStatus.body.lackWater) {
|
|
227
259
|
this.WaterLevel = 0;
|
|
@@ -229,7 +261,7 @@ class Humidifier {
|
|
|
229
261
|
else {
|
|
230
262
|
this.WaterLevel = 100;
|
|
231
263
|
}
|
|
232
|
-
this.
|
|
264
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
233
265
|
}
|
|
234
266
|
}
|
|
235
267
|
/**
|
|
@@ -246,11 +278,11 @@ class Humidifier {
|
|
|
246
278
|
connectBLE() {
|
|
247
279
|
const switchbot = new node_switchbot_1.default();
|
|
248
280
|
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
249
|
-
this.
|
|
281
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
250
282
|
return switchbot;
|
|
251
283
|
}
|
|
252
284
|
async BLERefreshStatus() {
|
|
253
|
-
this.
|
|
285
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
254
286
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
255
287
|
const switchbot = this.connectBLE();
|
|
256
288
|
// Start to monitor advertisement packets
|
|
@@ -264,16 +296,16 @@ class Humidifier {
|
|
|
264
296
|
this.autoMode = ad.serviceData.autoMode;
|
|
265
297
|
this.onState = ad.serviceData.onState;
|
|
266
298
|
this.percentage = ad.serviceData.percentage;
|
|
267
|
-
this.
|
|
268
|
-
this.
|
|
299
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
300
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
|
|
269
301
|
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
|
|
270
302
|
if (this.serviceData) {
|
|
271
303
|
this.connected = true;
|
|
272
|
-
this.
|
|
304
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
273
305
|
}
|
|
274
306
|
else {
|
|
275
307
|
this.connected = false;
|
|
276
|
-
this.
|
|
308
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
277
309
|
}
|
|
278
310
|
};
|
|
279
311
|
// Wait 10 seconds
|
|
@@ -286,54 +318,54 @@ class Humidifier {
|
|
|
286
318
|
this.updateHomeKitCharacteristics();
|
|
287
319
|
}
|
|
288
320
|
else {
|
|
289
|
-
this.
|
|
321
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
290
322
|
if (this.platform.config.credentials?.openToken) {
|
|
291
|
-
this.
|
|
323
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
292
324
|
await this.openAPIRefreshStatus();
|
|
293
325
|
}
|
|
294
326
|
}
|
|
295
327
|
}).catch(async (e) => {
|
|
296
|
-
this.
|
|
297
|
-
if (this.
|
|
298
|
-
this.
|
|
328
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
329
|
+
if (this.deviceLogging === 'debug') {
|
|
330
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
299
331
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
300
332
|
}
|
|
301
|
-
if (this.
|
|
302
|
-
this.
|
|
333
|
+
if (this.platform.debugMode) {
|
|
334
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
303
335
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
304
336
|
}
|
|
305
337
|
if (this.platform.config.credentials?.openToken) {
|
|
306
|
-
this.
|
|
338
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
307
339
|
await this.openAPIRefreshStatus();
|
|
308
340
|
}
|
|
309
|
-
this.apiError(
|
|
341
|
+
this.apiError();
|
|
310
342
|
});
|
|
311
343
|
}
|
|
312
344
|
async openAPIRefreshStatus() {
|
|
313
345
|
if (this.platform.config.credentials?.openToken) {
|
|
314
|
-
this.
|
|
346
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
315
347
|
try {
|
|
316
348
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
317
349
|
if (this.deviceStatus.message === 'success') {
|
|
318
|
-
this.
|
|
350
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
319
351
|
this.parseStatus();
|
|
320
352
|
this.updateHomeKitCharacteristics();
|
|
321
353
|
}
|
|
322
354
|
else {
|
|
323
|
-
this.
|
|
355
|
+
this.debugLog(this.deviceStatus);
|
|
324
356
|
}
|
|
325
357
|
}
|
|
326
358
|
catch (e) {
|
|
327
|
-
this.
|
|
328
|
-
if (this.
|
|
329
|
-
this.
|
|
359
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
360
|
+
if (this.deviceLogging === 'debug') {
|
|
361
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
330
362
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
331
363
|
}
|
|
332
|
-
if (this.
|
|
333
|
-
this.
|
|
364
|
+
if (this.platform.debugMode) {
|
|
365
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
334
366
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
335
367
|
}
|
|
336
|
-
this.apiError(
|
|
368
|
+
this.apiError();
|
|
337
369
|
}
|
|
338
370
|
}
|
|
339
371
|
}
|
|
@@ -354,61 +386,61 @@ class Humidifier {
|
|
|
354
386
|
});
|
|
355
387
|
}
|
|
356
388
|
async BLEpushChanges() {
|
|
357
|
-
this.
|
|
389
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
358
390
|
const switchbot = this.connectBLE();
|
|
359
391
|
switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
360
|
-
this.
|
|
392
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
361
393
|
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
362
394
|
}).then(() => {
|
|
363
|
-
this.
|
|
395
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
|
|
364
396
|
}).catch(async (e) => {
|
|
365
|
-
this.
|
|
366
|
-
if (this.
|
|
367
|
-
this.
|
|
397
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
398
|
+
if (this.deviceLogging === 'debug') {
|
|
399
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
368
400
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
369
401
|
}
|
|
370
|
-
if (this.
|
|
371
|
-
this.
|
|
402
|
+
if (this.platform.debugMode) {
|
|
403
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
372
404
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
373
405
|
}
|
|
374
406
|
if (this.platform.config.credentials?.openToken) {
|
|
375
|
-
this.
|
|
407
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
376
408
|
await this.OpenAPIpushChanges();
|
|
377
409
|
}
|
|
378
|
-
this.apiError(
|
|
410
|
+
this.apiError();
|
|
379
411
|
});
|
|
380
412
|
}
|
|
381
413
|
async OpenAPIpushChanges() {
|
|
382
414
|
if (this.platform.config.credentials?.openToken) {
|
|
383
|
-
this.
|
|
415
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
384
416
|
if (this.TargetHumidifierDehumidifierState ===
|
|
385
417
|
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
386
418
|
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
387
419
|
try {
|
|
388
|
-
this.
|
|
420
|
+
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
389
421
|
const payload = {
|
|
390
422
|
commandType: 'command',
|
|
391
423
|
command: 'setMode',
|
|
392
424
|
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
393
425
|
};
|
|
394
|
-
this.
|
|
426
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
395
427
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
396
428
|
// Make the API request
|
|
397
429
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
398
|
-
this.
|
|
430
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
399
431
|
this.statusCode(push);
|
|
400
432
|
}
|
|
401
433
|
catch (e) {
|
|
402
|
-
this.
|
|
403
|
-
if (this.
|
|
404
|
-
this.
|
|
434
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
435
|
+
if (this.deviceLogging === 'debug') {
|
|
436
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
405
437
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
406
438
|
}
|
|
407
|
-
if (this.
|
|
408
|
-
this.
|
|
439
|
+
if (this.platform.debugMode) {
|
|
440
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
409
441
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
410
442
|
}
|
|
411
|
-
this.apiError(
|
|
443
|
+
this.apiError();
|
|
412
444
|
}
|
|
413
445
|
}
|
|
414
446
|
else if (this.TargetHumidifierDehumidifierState ===
|
|
@@ -429,31 +461,31 @@ class Humidifier {
|
|
|
429
461
|
if (this.TargetHumidifierDehumidifierState ===
|
|
430
462
|
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
431
463
|
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
432
|
-
this.
|
|
464
|
+
this.debugLog('Pushing Auto!');
|
|
433
465
|
const payload = {
|
|
434
466
|
commandType: 'command',
|
|
435
467
|
command: 'setMode',
|
|
436
468
|
parameter: 'auto',
|
|
437
469
|
};
|
|
438
|
-
this.
|
|
470
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
439
471
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
440
472
|
// Make the API request
|
|
441
473
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
442
|
-
this.
|
|
474
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
|
|
443
475
|
this.statusCode(push);
|
|
444
476
|
}
|
|
445
477
|
}
|
|
446
478
|
catch (e) {
|
|
447
|
-
this.
|
|
448
|
-
if (this.
|
|
449
|
-
this.
|
|
479
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
480
|
+
if (this.deviceLogging === 'debug') {
|
|
481
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
450
482
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
451
483
|
}
|
|
452
|
-
if (this.
|
|
453
|
-
this.
|
|
484
|
+
if (this.platform.debugMode) {
|
|
485
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
454
486
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
455
487
|
}
|
|
456
|
-
this.apiError(
|
|
488
|
+
this.apiError();
|
|
457
489
|
}
|
|
458
490
|
}
|
|
459
491
|
/**
|
|
@@ -462,31 +494,31 @@ class Humidifier {
|
|
|
462
494
|
async pushActiveChanges() {
|
|
463
495
|
try {
|
|
464
496
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
465
|
-
this.
|
|
497
|
+
this.debugLog('Pushing Off!');
|
|
466
498
|
const payload = {
|
|
467
499
|
commandType: 'command',
|
|
468
500
|
command: 'turnOff',
|
|
469
501
|
parameter: 'default',
|
|
470
502
|
};
|
|
471
|
-
this.
|
|
503
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
472
504
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
473
505
|
// Make the API request
|
|
474
506
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
475
|
-
this.
|
|
507
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
|
|
476
508
|
this.statusCode(push);
|
|
477
509
|
}
|
|
478
510
|
}
|
|
479
511
|
catch (e) {
|
|
480
|
-
this.
|
|
481
|
-
if (this.
|
|
482
|
-
this.
|
|
512
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
513
|
+
if (this.deviceLogging === 'debug') {
|
|
514
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
483
515
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
484
516
|
}
|
|
485
|
-
if (this.
|
|
486
|
-
this.
|
|
517
|
+
if (this.platform.debugMode) {
|
|
518
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
487
519
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
488
520
|
}
|
|
489
|
-
this.apiError(
|
|
521
|
+
this.apiError();
|
|
490
522
|
}
|
|
491
523
|
}
|
|
492
524
|
/**
|
|
@@ -494,105 +526,95 @@ class Humidifier {
|
|
|
494
526
|
*/
|
|
495
527
|
updateHomeKitCharacteristics() {
|
|
496
528
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
497
|
-
this.
|
|
529
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
498
530
|
}
|
|
499
531
|
else {
|
|
500
532
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
501
|
-
this.
|
|
533
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
502
534
|
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
503
535
|
}
|
|
504
536
|
if (!this.device.ble) {
|
|
505
537
|
if (this.WaterLevel === undefined) {
|
|
506
|
-
this.
|
|
538
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
507
539
|
}
|
|
508
540
|
else {
|
|
509
541
|
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
510
|
-
this.
|
|
542
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
511
543
|
}
|
|
512
544
|
}
|
|
513
545
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
514
|
-
this.
|
|
546
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
515
547
|
}
|
|
516
548
|
else {
|
|
517
549
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
518
|
-
this.
|
|
550
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
519
551
|
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
520
552
|
}
|
|
521
553
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
522
|
-
this.
|
|
554
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
523
555
|
}
|
|
524
556
|
else {
|
|
525
557
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
526
|
-
this.
|
|
558
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
527
559
|
+ ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
528
560
|
}
|
|
529
561
|
if (this.Active === undefined) {
|
|
530
|
-
this.
|
|
562
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
531
563
|
}
|
|
532
564
|
else {
|
|
533
565
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
534
|
-
this.
|
|
566
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
535
567
|
}
|
|
536
568
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
537
|
-
this.
|
|
569
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
538
570
|
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
539
571
|
}
|
|
540
572
|
else {
|
|
541
573
|
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
542
|
-
this.
|
|
574
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
543
575
|
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
544
576
|
}
|
|
545
577
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
546
578
|
if (this.CurrentTemperature === undefined) {
|
|
547
|
-
this.
|
|
579
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
548
580
|
}
|
|
549
581
|
else {
|
|
550
582
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
551
|
-
this.
|
|
583
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
552
584
|
}
|
|
553
585
|
}
|
|
554
586
|
}
|
|
555
|
-
apiError(
|
|
556
|
-
this.
|
|
557
|
-
if (!this.device.ble) {
|
|
558
|
-
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
559
|
-
}
|
|
560
|
-
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
561
|
-
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
562
|
-
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
563
|
-
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
564
|
-
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
565
|
-
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
566
|
-
}
|
|
587
|
+
apiError() {
|
|
588
|
+
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */);
|
|
567
589
|
}
|
|
568
590
|
statusCode(push) {
|
|
569
591
|
switch (push.data.statusCode) {
|
|
570
592
|
case 151:
|
|
571
|
-
this.
|
|
593
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
572
594
|
break;
|
|
573
595
|
case 152:
|
|
574
|
-
this.
|
|
596
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
|
|
575
597
|
break;
|
|
576
598
|
case 160:
|
|
577
|
-
this.
|
|
599
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
|
|
578
600
|
break;
|
|
579
601
|
case 161:
|
|
580
|
-
this.
|
|
602
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
|
|
581
603
|
this.offlineOff();
|
|
582
604
|
break;
|
|
583
605
|
case 171:
|
|
584
|
-
this.
|
|
606
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
585
607
|
this.offlineOff();
|
|
586
608
|
break;
|
|
587
609
|
case 190:
|
|
588
|
-
this.
|
|
610
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
589
611
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
590
612
|
break;
|
|
591
613
|
case 100:
|
|
592
|
-
this.
|
|
614
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
|
|
593
615
|
break;
|
|
594
616
|
default:
|
|
595
|
-
this.
|
|
617
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
|
|
596
618
|
}
|
|
597
619
|
}
|
|
598
620
|
offlineOff() {
|
|
@@ -605,7 +627,7 @@ class Humidifier {
|
|
|
605
627
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
606
628
|
*/
|
|
607
629
|
handleTargetHumidifierDehumidifierStateSet(value) {
|
|
608
|
-
this.
|
|
630
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
|
|
609
631
|
this.TargetHumidifierDehumidifierState = value;
|
|
610
632
|
this.doHumidifierUpdate.next();
|
|
611
633
|
}
|
|
@@ -613,7 +635,7 @@ class Humidifier {
|
|
|
613
635
|
* Handle requests to set the "Active" characteristic
|
|
614
636
|
*/
|
|
615
637
|
handleActiveSet(value) {
|
|
616
|
-
this.
|
|
638
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
|
|
617
639
|
this.Active = value;
|
|
618
640
|
this.doHumidifierUpdate.next();
|
|
619
641
|
}
|
|
@@ -621,7 +643,7 @@ class Humidifier {
|
|
|
621
643
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
622
644
|
*/
|
|
623
645
|
handleRelativeHumidityHumidifierThresholdSet(value) {
|
|
624
|
-
this.
|
|
646
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
625
647
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
626
648
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
627
649
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
@@ -629,6 +651,37 @@ class Humidifier {
|
|
|
629
651
|
}
|
|
630
652
|
this.doHumidifierUpdate.next();
|
|
631
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Logging for Device
|
|
656
|
+
*/
|
|
657
|
+
infoLog(...log) {
|
|
658
|
+
if (this.enablingDeviceLogging()) {
|
|
659
|
+
this.platform.log.info(String(...log));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
warnLog(...log) {
|
|
663
|
+
if (this.enablingDeviceLogging()) {
|
|
664
|
+
this.platform.log.warn(String(...log));
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
errorLog(...log) {
|
|
668
|
+
if (this.enablingDeviceLogging()) {
|
|
669
|
+
this.platform.log.error(String(...log));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
debugLog(...log) {
|
|
673
|
+
if (this.enablingDeviceLogging()) {
|
|
674
|
+
if (this.deviceLogging === 'debug') {
|
|
675
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
this.platform.log.debug(String(...log));
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
enablingDeviceLogging() {
|
|
683
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
684
|
+
}
|
|
632
685
|
}
|
|
633
686
|
exports.Humidifier = Humidifier;
|
|
634
687
|
//# sourceMappingURL=humidifiers.js.map
|