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