@switchbot/homebridge-switchbot 1.9.0 → 1.10.1
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/.eslintrc +14 -45
- package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
- package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
- package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
- package/.github/labeler.yml +1 -1
- package/.github/workflows/codeql-analysis.yml +29 -29
- package/.github/workflows/nodejs-beta.yml +1 -1
- package/.github/workflows/prerelease-beta.js +1 -1
- package/.github/workflows/stale.yml +1 -1
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +2 -4
- package/.vscode/settings.json +13 -1
- package/CHANGELOG.md +16 -0
- package/README.md +100 -99
- package/SECURITY.md +2 -2
- package/config.schema.json +8 -0
- package/dist/devices/bots.d.ts +2 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +91 -86
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +15 -15
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +60 -71
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +33 -31
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -2
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +71 -71
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +74 -76
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +2 -2
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +29 -27
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +34 -32
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +7 -7
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +18 -23
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +5 -2
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +61 -56
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +2 -2
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +12 -17
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +2 -2
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +10 -13
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +2 -2
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +15 -17
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +2 -2
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +10 -13
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +2 -2
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +10 -13
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +2 -2
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +22 -30
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +2 -2
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +11 -13
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +2 -2
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +10 -13
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +3 -3
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +13 -14
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +231 -245
- package/homebridge-ui/server.js +2 -4
- package/nodemon.json +2 -4
- package/package.json +15 -9
- package/src/devices/bots.ts +217 -186
- package/src/devices/colorbulb.ts +90 -84
- package/src/devices/contact.ts +85 -78
- package/src/devices/curtains.ts +152 -135
- package/src/devices/humidifiers.ts +162 -137
- package/src/devices/meters.ts +76 -73
- package/src/devices/motion.ts +87 -78
- package/src/devices/plugs.ts +27 -31
- package/src/irdevices/airconditioners.ts +91 -59
- package/src/irdevices/airpurifiers.ts +22 -23
- package/src/irdevices/cameras.ts +18 -19
- package/src/irdevices/fans.ts +27 -25
- package/src/irdevices/lights.ts +18 -20
- package/src/irdevices/others.ts +18 -19
- package/src/irdevices/tvs.ts +33 -41
- package/src/irdevices/vacuumcleaners.ts +19 -19
- package/src/irdevices/waterheaters.ts +21 -31
- package/src/platform.ts +32 -33
- package/src/settings.ts +9 -19
- package/tsconfig.json +5 -14
- package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
|
@@ -50,11 +50,7 @@ export class Humidifier {
|
|
|
50
50
|
humidifierUpdateInProgress!: boolean;
|
|
51
51
|
doHumidifierUpdate!: Subject<void>;
|
|
52
52
|
|
|
53
|
-
constructor(
|
|
54
|
-
private readonly platform: SwitchBotPlatform,
|
|
55
|
-
private accessory: PlatformAccessory,
|
|
56
|
-
public device: device & devicesConfig,
|
|
57
|
-
) {
|
|
53
|
+
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
58
54
|
// default placeholders
|
|
59
55
|
this.logs(device);
|
|
60
56
|
this.scan(device);
|
|
@@ -69,8 +65,10 @@ export class Humidifier {
|
|
|
69
65
|
this.WaterLevel = 0;
|
|
70
66
|
|
|
71
67
|
// Humidifiers Config
|
|
72
|
-
this.debugLog(
|
|
73
|
-
|
|
68
|
+
this.debugLog(
|
|
69
|
+
`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: ` +
|
|
70
|
+
`${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`,
|
|
71
|
+
);
|
|
74
72
|
|
|
75
73
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
76
74
|
this.doHumidifierUpdate = new Subject();
|
|
@@ -89,8 +87,8 @@ export class Humidifier {
|
|
|
89
87
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
90
88
|
// you can create multiple services for each accessory
|
|
91
89
|
(this.service =
|
|
92
|
-
accessory.getService(this.platform.Service.HumidifierDehumidifier) ||
|
|
93
|
-
|
|
90
|
+
accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
91
|
+
`${accessory.displayName} Humidifier`;
|
|
94
92
|
|
|
95
93
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
96
94
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -104,10 +102,7 @@ export class Humidifier {
|
|
|
104
102
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
105
103
|
|
|
106
104
|
// create handlers for required characteristics
|
|
107
|
-
this.service.setCharacteristic(
|
|
108
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
109
|
-
this.CurrentHumidifierDehumidifierState,
|
|
110
|
-
);
|
|
105
|
+
this.service.setCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
111
106
|
|
|
112
107
|
this.service
|
|
113
108
|
.getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
|
|
@@ -140,8 +135,8 @@ export class Humidifier {
|
|
|
140
135
|
} else if (!this.temperatureservice && !device.ble) {
|
|
141
136
|
this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
142
137
|
(this.temperatureservice =
|
|
143
|
-
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
144
|
-
|
|
138
|
+
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
139
|
+
`${accessory.displayName} Temperature Sensor`;
|
|
145
140
|
|
|
146
141
|
this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
147
142
|
|
|
@@ -185,12 +180,10 @@ export class Humidifier {
|
|
|
185
180
|
} catch (e: any) {
|
|
186
181
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
187
182
|
if (this.deviceLogging === 'debug') {
|
|
188
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
189
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
183
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
190
184
|
}
|
|
191
185
|
if (this.platform.debugMode) {
|
|
192
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
193
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
186
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
194
187
|
}
|
|
195
188
|
this.apiError(e);
|
|
196
189
|
}
|
|
@@ -257,8 +250,9 @@ export class Humidifier {
|
|
|
257
250
|
}
|
|
258
251
|
}
|
|
259
252
|
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
260
|
-
this.debugLog(
|
|
261
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}
|
|
253
|
+
this.debugLog(
|
|
254
|
+
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
255
|
+
);
|
|
262
256
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
263
257
|
// Active
|
|
264
258
|
switch (this.power) {
|
|
@@ -294,59 +288,68 @@ export class Humidifier {
|
|
|
294
288
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
295
289
|
const switchbot = await this.platform.connectBLE();
|
|
296
290
|
// Convert to BLE Address
|
|
297
|
-
this.device.bleMac =
|
|
291
|
+
this.device.bleMac = this.device
|
|
292
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
293
|
+
.join(':')
|
|
294
|
+
.toLowerCase();
|
|
298
295
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
299
296
|
// Start to monitor advertisement packets
|
|
300
297
|
if (switchbot !== false) {
|
|
301
|
-
switchbot
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
298
|
+
switchbot
|
|
299
|
+
.startScan({
|
|
300
|
+
model: 'e',
|
|
301
|
+
id: this.device.bleMac,
|
|
302
|
+
})
|
|
303
|
+
.then(() => {
|
|
304
|
+
// Set an event hander
|
|
305
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
306
|
+
this.serviceData = ad.serviceData;
|
|
307
|
+
this.autoMode = ad.serviceData.autoMode;
|
|
308
|
+
this.onState = ad.serviceData.onState;
|
|
309
|
+
this.percentage = ad.serviceData.percentage;
|
|
310
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
311
|
+
this.debugLog(
|
|
312
|
+
`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
313
|
+
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
if (this.serviceData) {
|
|
317
|
+
this.connected = true;
|
|
318
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
319
|
+
} else {
|
|
320
|
+
this.connected = false;
|
|
321
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
// Wait 2 seconds
|
|
325
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
326
|
+
})
|
|
327
|
+
.then(async () => {
|
|
328
|
+
// Stop to monitor
|
|
329
|
+
switchbot.stopScan();
|
|
330
|
+
if (this.connected) {
|
|
331
|
+
this.parseStatus();
|
|
332
|
+
this.updateHomeKitCharacteristics();
|
|
318
333
|
} else {
|
|
319
|
-
this.
|
|
320
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
334
|
+
await this.BLEconnection(switchbot);
|
|
321
335
|
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
if (this.platform.debugMode) {
|
|
341
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
342
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
343
|
-
}
|
|
344
|
-
if (this.platform.config.credentials?.openToken) {
|
|
345
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
346
|
-
await this.openAPIRefreshStatus();
|
|
347
|
-
}
|
|
348
|
-
this.apiError(e);
|
|
349
|
-
});
|
|
336
|
+
})
|
|
337
|
+
.catch(async (e: any) => {
|
|
338
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
339
|
+
if (this.deviceLogging === 'debug') {
|
|
340
|
+
this.errorLog(
|
|
341
|
+
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (this.platform.debugMode) {
|
|
345
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
346
|
+
}
|
|
347
|
+
if (this.platform.config.credentials?.openToken) {
|
|
348
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
349
|
+
await this.openAPIRefreshStatus();
|
|
350
|
+
}
|
|
351
|
+
this.apiError(e);
|
|
352
|
+
});
|
|
350
353
|
} else {
|
|
351
354
|
await this.BLEconnection(switchbot);
|
|
352
355
|
}
|
|
@@ -381,12 +384,13 @@ export class Humidifier {
|
|
|
381
384
|
} catch (e: any) {
|
|
382
385
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
383
386
|
if (this.deviceLogging === 'debug') {
|
|
384
|
-
this.errorLog(
|
|
385
|
-
|
|
387
|
+
this.errorLog(
|
|
388
|
+
`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
389
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
390
|
+
);
|
|
386
391
|
}
|
|
387
392
|
if (this.platform.debugMode) {
|
|
388
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
389
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
393
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
390
394
|
}
|
|
391
395
|
this.apiError(e);
|
|
392
396
|
}
|
|
@@ -414,30 +418,37 @@ export class Humidifier {
|
|
|
414
418
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
415
419
|
const switchbot = await this.platform.connectBLE();
|
|
416
420
|
// Convert to BLE Address
|
|
417
|
-
this.device.bleMac =
|
|
421
|
+
this.device.bleMac = this.device
|
|
422
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
423
|
+
.join(':')
|
|
424
|
+
.toLowerCase();
|
|
418
425
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
419
426
|
if (switchbot !== false) {
|
|
420
|
-
switchbot
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
427
|
+
switchbot
|
|
428
|
+
.discover({ model: 'e', quick: true, id: this.device.bleMac })
|
|
429
|
+
.then((device_list) => {
|
|
430
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
431
|
+
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
432
|
+
})
|
|
433
|
+
.then(() => {
|
|
434
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
|
|
435
|
+
})
|
|
436
|
+
.catch(async (e: any) => {
|
|
437
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
438
|
+
if (this.deviceLogging === 'debug') {
|
|
439
|
+
this.errorLog(
|
|
440
|
+
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
if (this.platform.debugMode) {
|
|
444
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
445
|
+
}
|
|
446
|
+
if (this.platform.config.credentials?.openToken) {
|
|
447
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
448
|
+
await this.openAPIpushChanges();
|
|
449
|
+
}
|
|
450
|
+
this.apiError(e);
|
|
451
|
+
});
|
|
441
452
|
} else {
|
|
442
453
|
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
443
454
|
if (this.platform.config.credentials?.openToken) {
|
|
@@ -451,8 +462,7 @@ export class Humidifier {
|
|
|
451
462
|
if (this.platform.config.credentials?.openToken) {
|
|
452
463
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
453
464
|
if (
|
|
454
|
-
this.TargetHumidifierDehumidifierState ===
|
|
455
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
465
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
456
466
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
457
467
|
) {
|
|
458
468
|
try {
|
|
@@ -463,28 +473,30 @@ export class Humidifier {
|
|
|
463
473
|
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
464
474
|
} as payload;
|
|
465
475
|
|
|
466
|
-
this.infoLog(
|
|
467
|
-
|
|
476
|
+
this.infoLog(
|
|
477
|
+
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
478
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
479
|
+
);
|
|
468
480
|
|
|
469
481
|
// Make the API request
|
|
470
|
-
const push: any =
|
|
482
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
471
483
|
this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
472
484
|
this.statusCode(push);
|
|
473
485
|
} catch (e: any) {
|
|
474
486
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
475
487
|
if (this.deviceLogging === 'debug') {
|
|
476
|
-
this.errorLog(
|
|
477
|
-
|
|
488
|
+
this.errorLog(
|
|
489
|
+
`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
490
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
491
|
+
);
|
|
478
492
|
}
|
|
479
493
|
if (this.platform.debugMode) {
|
|
480
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
481
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
494
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
482
495
|
}
|
|
483
496
|
this.apiError(e);
|
|
484
497
|
}
|
|
485
498
|
} else if (
|
|
486
|
-
this.TargetHumidifierDehumidifierState ===
|
|
487
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
499
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
488
500
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
489
501
|
) {
|
|
490
502
|
await this.pushAutoChanges();
|
|
@@ -500,8 +512,7 @@ export class Humidifier {
|
|
|
500
512
|
async pushAutoChanges() {
|
|
501
513
|
try {
|
|
502
514
|
if (
|
|
503
|
-
this.TargetHumidifierDehumidifierState ===
|
|
504
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
515
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
505
516
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
506
517
|
) {
|
|
507
518
|
this.debugLog('Pushing Auto!');
|
|
@@ -511,23 +522,26 @@ export class Humidifier {
|
|
|
511
522
|
parameter: 'auto',
|
|
512
523
|
} as payload;
|
|
513
524
|
|
|
514
|
-
this.infoLog(
|
|
515
|
-
|
|
525
|
+
this.infoLog(
|
|
526
|
+
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
527
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
528
|
+
);
|
|
516
529
|
|
|
517
530
|
// Make the API request
|
|
518
|
-
const push: any =
|
|
531
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
519
532
|
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
|
|
520
533
|
this.statusCode(push);
|
|
521
534
|
}
|
|
522
535
|
} catch (e: any) {
|
|
523
536
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
524
537
|
if (this.deviceLogging === 'debug') {
|
|
525
|
-
this.errorLog(
|
|
526
|
-
|
|
538
|
+
this.errorLog(
|
|
539
|
+
`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
|
|
540
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
541
|
+
);
|
|
527
542
|
}
|
|
528
543
|
if (this.platform.debugMode) {
|
|
529
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
530
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
544
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
531
545
|
}
|
|
532
546
|
this.apiError(e);
|
|
533
547
|
}
|
|
@@ -546,23 +560,26 @@ export class Humidifier {
|
|
|
546
560
|
parameter: 'default',
|
|
547
561
|
} as payload;
|
|
548
562
|
|
|
549
|
-
this.infoLog(
|
|
550
|
-
|
|
563
|
+
this.infoLog(
|
|
564
|
+
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
565
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
566
|
+
);
|
|
551
567
|
|
|
552
568
|
// Make the API request
|
|
553
|
-
const push: any =
|
|
569
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
554
570
|
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
|
|
555
571
|
this.statusCode(push);
|
|
556
572
|
}
|
|
557
573
|
} catch (e: any) {
|
|
558
574
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
559
575
|
if (this.deviceLogging === 'debug') {
|
|
560
|
-
this.errorLog(
|
|
561
|
-
|
|
576
|
+
this.errorLog(
|
|
577
|
+
`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
|
|
578
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
579
|
+
);
|
|
562
580
|
}
|
|
563
581
|
if (this.platform.debugMode) {
|
|
564
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
565
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
582
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
566
583
|
}
|
|
567
584
|
this.apiError(e);
|
|
568
585
|
}
|
|
@@ -576,8 +593,7 @@ export class Humidifier {
|
|
|
576
593
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
577
594
|
} else {
|
|
578
595
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
579
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
580
|
-
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
596
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
581
597
|
}
|
|
582
598
|
if (!this.device.ble) {
|
|
583
599
|
if (this.WaterLevel === undefined) {
|
|
@@ -591,15 +607,19 @@ export class Humidifier {
|
|
|
591
607
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
592
608
|
} else {
|
|
593
609
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
594
|
-
this.debugLog(
|
|
595
|
-
|
|
610
|
+
this.debugLog(
|
|
611
|
+
`Humidifier: ${this.accessory.displayName}` +
|
|
612
|
+
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
613
|
+
);
|
|
596
614
|
}
|
|
597
615
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
598
616
|
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
599
617
|
} else {
|
|
600
618
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
601
|
-
this.debugLog(
|
|
602
|
-
|
|
619
|
+
this.debugLog(
|
|
620
|
+
`Humidifier: ${this.accessory.displayName}` +
|
|
621
|
+
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
622
|
+
);
|
|
603
623
|
}
|
|
604
624
|
if (this.Active === undefined) {
|
|
605
625
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
@@ -608,12 +628,15 @@ export class Humidifier {
|
|
|
608
628
|
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
609
629
|
}
|
|
610
630
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
611
|
-
this.debugLog(
|
|
612
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}
|
|
631
|
+
this.debugLog(
|
|
632
|
+
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
633
|
+
);
|
|
613
634
|
} else {
|
|
614
635
|
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
615
|
-
this.debugLog(
|
|
616
|
-
|
|
636
|
+
this.debugLog(
|
|
637
|
+
`Humidifier: ${this.accessory.displayName}` +
|
|
638
|
+
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
639
|
+
);
|
|
617
640
|
}
|
|
618
641
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
619
642
|
if (this.CurrentTemperature === undefined) {
|
|
@@ -640,7 +663,7 @@ export class Humidifier {
|
|
|
640
663
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
641
664
|
}
|
|
642
665
|
|
|
643
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
666
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
644
667
|
switch (push.data.statusCode) {
|
|
645
668
|
case 151:
|
|
646
669
|
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -660,8 +683,10 @@ export class Humidifier {
|
|
|
660
683
|
this.offlineOff();
|
|
661
684
|
break;
|
|
662
685
|
case 190:
|
|
663
|
-
this.errorLog(
|
|
664
|
-
|
|
686
|
+
this.errorLog(
|
|
687
|
+
`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
688
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
689
|
+
);
|
|
665
690
|
break;
|
|
666
691
|
case 100:
|
|
667
692
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
|
|
@@ -783,8 +808,8 @@ export class Humidifier {
|
|
|
783
808
|
}
|
|
784
809
|
|
|
785
810
|
/**
|
|
786
|
-
|
|
787
|
-
|
|
811
|
+
* Logging for Device
|
|
812
|
+
*/
|
|
788
813
|
infoLog(...log: any[]) {
|
|
789
814
|
if (this.enablingDeviceLogging()) {
|
|
790
815
|
this.platform.log.info(String(...log));
|