@switchbot/homebridge-switchbot 1.7.0 → 1.7.1-beta.11
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 +17 -0
- package/config.schema.json +101 -33
- package/dist/devices/bots.d.ts +9 -5
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +144 -77
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +9 -4
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +40 -37
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +10 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +92 -51
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +10 -3
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +52 -34
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +8 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -35
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +14 -12
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +63 -103
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +10 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +114 -68
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +3 -1
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +8 -1
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +1 -0
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +6 -0
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +1 -0
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +6 -0
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +1 -0
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +6 -0
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +1 -0
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +6 -0
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +1 -0
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +6 -0
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +1 -0
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +6 -0
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +1 -0
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +6 -0
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +1 -0
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +6 -0
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +1 -0
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +6 -0
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +14 -1
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +14 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +71 -71
- package/src/devices/bots.ts +140 -74
- package/src/devices/colorbulb.ts +46 -40
- package/src/devices/contact.ts +99 -55
- package/src/devices/curtains.ts +60 -36
- package/src/devices/humidifiers.ts +36 -36
- package/src/devices/meters.ts +79 -113
- package/src/devices/motion.ts +125 -74
- package/src/devices/plugs.ts +11 -2
- package/src/irdevices/airconditioners.ts +7 -0
- package/src/irdevices/airpurifiers.ts +7 -0
- package/src/irdevices/cameras.ts +7 -0
- package/src/irdevices/fans.ts +7 -0
- package/src/irdevices/lights.ts +7 -0
- package/src/irdevices/others.ts +7 -0
- package/src/irdevices/tvs.ts +7 -0
- package/src/irdevices/vacuumcleaners.ts +7 -0
- package/src/irdevices/waterheaters.ts +7 -0
- package/src/platform.ts +14 -1
- package/src/settings.ts +15 -0
package/src/devices/curtains.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
|
|
7
|
+
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
8
8
|
|
|
9
9
|
export class Curtain {
|
|
10
10
|
// Services
|
|
@@ -22,11 +22,16 @@ export class Curtain {
|
|
|
22
22
|
|
|
23
23
|
// OpenAPI Others
|
|
24
24
|
deviceStatus!: deviceStatusResponse;
|
|
25
|
+
slidePosition: deviceStatus['slidePosition'];
|
|
26
|
+
moving: deviceStatus['moving'];
|
|
27
|
+
brightness: deviceStatus['brightness'];
|
|
25
28
|
|
|
26
29
|
// BLE Others
|
|
27
30
|
connected?: boolean;
|
|
28
31
|
switchbot!: switchbot;
|
|
32
|
+
SwitchToOpenAPI?: boolean;
|
|
29
33
|
serviceData!: serviceData;
|
|
34
|
+
spaceBetweenLevels!: number;
|
|
30
35
|
calibration: serviceData['calibration'];
|
|
31
36
|
battery: serviceData['battery'];
|
|
32
37
|
position: serviceData['position'];
|
|
@@ -44,7 +49,6 @@ export class Curtain {
|
|
|
44
49
|
scanDuration!: number;
|
|
45
50
|
deviceLogging!: string;
|
|
46
51
|
deviceRefreshRate!: number;
|
|
47
|
-
spaceBetweenLevels!: number;
|
|
48
52
|
|
|
49
53
|
// Updates
|
|
50
54
|
curtainUpdateInProgress!: boolean;
|
|
@@ -60,6 +64,7 @@ export class Curtain {
|
|
|
60
64
|
this.scan();
|
|
61
65
|
this.setMinMax();
|
|
62
66
|
this.refreshRate();
|
|
67
|
+
this.config(device);
|
|
63
68
|
this.CurrentPosition = 0;
|
|
64
69
|
this.TargetPosition = 0;
|
|
65
70
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
@@ -142,6 +147,23 @@ export class Curtain {
|
|
|
142
147
|
this.debugLog(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
// Battery Service
|
|
151
|
+
if (!device.ble) {
|
|
152
|
+
this.debugLog(`Curtain: ${accessory.displayName} Removing Battery Service`);
|
|
153
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
154
|
+
accessory.removeService(this.batteryService!);
|
|
155
|
+
} else if (device.ble && !this.batteryService) {
|
|
156
|
+
this.debugLog(`Curtain: ${accessory.displayName} Add Battery Service`);
|
|
157
|
+
(this.batteryService =
|
|
158
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
159
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
160
|
+
|
|
161
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
162
|
+
|
|
163
|
+
} else {
|
|
164
|
+
this.debugLog(`Curtain: ${accessory.displayName} Battery Service Not Added`);
|
|
165
|
+
}
|
|
166
|
+
|
|
145
167
|
|
|
146
168
|
// Update Homekit
|
|
147
169
|
this.updateHomeKitCharacteristics();
|
|
@@ -193,6 +215,12 @@ export class Curtain {
|
|
|
193
215
|
});
|
|
194
216
|
}
|
|
195
217
|
|
|
218
|
+
config(device: device & devicesConfig) {
|
|
219
|
+
if (device.curtain !== undefined || device.ble !== undefined) {
|
|
220
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(device.curtain)}, BLE: ${device.ble}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
196
224
|
refreshRate() {
|
|
197
225
|
// refreshRate
|
|
198
226
|
if (this.device.refreshRate) {
|
|
@@ -253,30 +281,6 @@ export class Curtain {
|
|
|
253
281
|
}
|
|
254
282
|
}
|
|
255
283
|
|
|
256
|
-
public async connectBLE() {
|
|
257
|
-
let switchbot: any;
|
|
258
|
-
try {
|
|
259
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
260
|
-
const Switchbot = require('node-switchbot');
|
|
261
|
-
switchbot = new Switchbot();
|
|
262
|
-
// Convert to BLE Address
|
|
263
|
-
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
264
|
-
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
265
|
-
} catch (e: any) {
|
|
266
|
-
switchbot = false;
|
|
267
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
268
|
-
if (this.deviceLogging === 'debug') {
|
|
269
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
270
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
271
|
-
}
|
|
272
|
-
if (this.platform.debugMode) {
|
|
273
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
274
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return switchbot;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
284
|
private minStep(): number {
|
|
281
285
|
if (this.device.curtain?.set_minStep) {
|
|
282
286
|
this.set_minStep = this.device.curtain?.set_minStep;
|
|
@@ -304,16 +308,20 @@ export class Curtain {
|
|
|
304
308
|
return this.set_maxLux;
|
|
305
309
|
}
|
|
306
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Parse the device status from the SwitchBot api
|
|
313
|
+
*/
|
|
307
314
|
async parseStatus() {
|
|
308
|
-
if (this.device.ble) {
|
|
309
|
-
await this.BLEparseStatus();
|
|
310
|
-
} else {
|
|
315
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
311
316
|
await this.openAPIparseStatus();
|
|
317
|
+
} else {
|
|
318
|
+
await this.BLEparseStatus();
|
|
312
319
|
}
|
|
313
320
|
}
|
|
314
321
|
|
|
315
322
|
private async BLEparseStatus() {
|
|
316
323
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
|
|
324
|
+
// CurrentPosition
|
|
317
325
|
this.setMinMax();
|
|
318
326
|
this.CurrentPosition = 100 - Number(this.position);
|
|
319
327
|
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
@@ -339,6 +347,7 @@ export class Curtain {
|
|
|
339
347
|
// If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
|
|
340
348
|
this.TargetPosition = this.CurrentPosition;
|
|
341
349
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
350
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Stopped`);
|
|
342
351
|
}
|
|
343
352
|
}
|
|
344
353
|
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
@@ -407,17 +416,20 @@ export class Curtain {
|
|
|
407
416
|
}
|
|
408
417
|
|
|
409
418
|
private async openAPIparseStatus() {
|
|
419
|
+
if (this.device.ble) {
|
|
420
|
+
this.SwitchToOpenAPI = false;
|
|
421
|
+
}
|
|
410
422
|
if (this.platform.config.credentials?.openToken) {
|
|
411
423
|
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
412
424
|
// CurrentPosition
|
|
413
425
|
this.setMinMax();
|
|
414
|
-
this.CurrentPosition = 100 - this.
|
|
426
|
+
this.CurrentPosition = 100 - Number(this.slidePosition);
|
|
415
427
|
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
416
428
|
if (this.setNewTarget) {
|
|
417
|
-
this.infoLog(`
|
|
429
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
|
|
418
430
|
}
|
|
419
431
|
|
|
420
|
-
if (this.
|
|
432
|
+
if (this.setNewTarget && this.moving) {
|
|
421
433
|
this.setMinMax();
|
|
422
434
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
423
435
|
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
@@ -435,6 +447,7 @@ export class Curtain {
|
|
|
435
447
|
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
|
|
436
448
|
this.TargetPosition = this.CurrentPosition;
|
|
437
449
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
450
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Stopped`);
|
|
438
451
|
}
|
|
439
452
|
}
|
|
440
453
|
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
@@ -444,7 +457,7 @@ export class Curtain {
|
|
|
444
457
|
this.set_minLux = this.minLux();
|
|
445
458
|
this.set_maxLux = this.maxLux();
|
|
446
459
|
// Brightness
|
|
447
|
-
switch (this.
|
|
460
|
+
switch (this.brightness) {
|
|
448
461
|
case 'dim':
|
|
449
462
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
450
463
|
break;
|
|
@@ -467,8 +480,10 @@ export class Curtain {
|
|
|
467
480
|
|
|
468
481
|
private async BLERefreshStatus() {
|
|
469
482
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
470
|
-
|
|
471
|
-
|
|
483
|
+
const switchbot = await this.platform.connectBLE();
|
|
484
|
+
// Convert to BLE Address
|
|
485
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
486
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
472
487
|
// Start to monitor advertisement packets
|
|
473
488
|
if (switchbot !== false) {
|
|
474
489
|
switchbot.startScan({
|
|
@@ -506,6 +521,7 @@ export class Curtain {
|
|
|
506
521
|
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
507
522
|
if (this.platform.config.credentials?.openToken) {
|
|
508
523
|
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
524
|
+
this.SwitchToOpenAPI = true;
|
|
509
525
|
await this.openAPIRefreshStatus();
|
|
510
526
|
}
|
|
511
527
|
}
|
|
@@ -521,6 +537,7 @@ export class Curtain {
|
|
|
521
537
|
}
|
|
522
538
|
if (this.platform.config.credentials?.openToken) {
|
|
523
539
|
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
540
|
+
this.SwitchToOpenAPI = true;
|
|
524
541
|
await this.openAPIRefreshStatus();
|
|
525
542
|
}
|
|
526
543
|
this.apiError(e);
|
|
@@ -534,6 +551,7 @@ export class Curtain {
|
|
|
534
551
|
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
535
552
|
if (this.platform.config.credentials?.openToken) {
|
|
536
553
|
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
554
|
+
this.SwitchToOpenAPI = true;
|
|
537
555
|
await this.openAPIRefreshStatus();
|
|
538
556
|
}
|
|
539
557
|
}
|
|
@@ -544,6 +562,9 @@ export class Curtain {
|
|
|
544
562
|
try {
|
|
545
563
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
546
564
|
this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
565
|
+
this.slidePosition = this.deviceStatus.body.slidePosition;
|
|
566
|
+
this.moving = this.deviceStatus.body.moving;
|
|
567
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
547
568
|
this.parseStatus();
|
|
548
569
|
this.updateHomeKitCharacteristics();
|
|
549
570
|
} catch (e: any) {
|
|
@@ -578,7 +599,10 @@ export class Curtain {
|
|
|
578
599
|
private async BLEpushChanges() {
|
|
579
600
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
580
601
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
581
|
-
const switchbot = await this.connectBLE();
|
|
602
|
+
const switchbot = await this.platform.connectBLE();
|
|
603
|
+
// Convert to BLE Address
|
|
604
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
605
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
582
606
|
if (switchbot !== false) {
|
|
583
607
|
switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
584
608
|
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
@@ -3,7 +3,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
|
-
import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload } from '../settings';
|
|
6
|
+
import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
@@ -25,6 +25,12 @@ export class Humidifier {
|
|
|
25
25
|
WaterLevel!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI
|
|
28
|
+
auto: deviceStatus['auto'];
|
|
29
|
+
power: deviceStatus['power'];
|
|
30
|
+
humidity: deviceStatus['humidity'];
|
|
31
|
+
lackWater: deviceStatus['lackWater'];
|
|
32
|
+
temperature: deviceStatus['temperature'];
|
|
33
|
+
nebulizationEfficiency: deviceStatus['nebulizationEfficiency'];
|
|
28
34
|
deviceStatus!: deviceStatusResponse;
|
|
29
35
|
|
|
30
36
|
// BLE Others
|
|
@@ -53,6 +59,7 @@ export class Humidifier {
|
|
|
53
59
|
this.logs();
|
|
54
60
|
this.scan();
|
|
55
61
|
this.refreshRate();
|
|
62
|
+
this.config(device);
|
|
56
63
|
this.CurrentRelativeHumidity = 0;
|
|
57
64
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
58
65
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
@@ -191,6 +198,12 @@ export class Humidifier {
|
|
|
191
198
|
});
|
|
192
199
|
}
|
|
193
200
|
|
|
201
|
+
config(device: device & devicesConfig) {
|
|
202
|
+
if (device.humidifier !== undefined || device.ble !== undefined) {
|
|
203
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(device.humidifier)}, BLE: ${device.ble}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
194
207
|
refreshRate() {
|
|
195
208
|
if (this.device.refreshRate) {
|
|
196
209
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
@@ -276,15 +289,15 @@ export class Humidifier {
|
|
|
276
289
|
if (this.platform.config.credentials?.openToken) {
|
|
277
290
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
278
291
|
// Current Relative Humidity
|
|
279
|
-
this.CurrentRelativeHumidity = this.
|
|
292
|
+
this.CurrentRelativeHumidity = this.humidity!;
|
|
280
293
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
281
294
|
// Current Temperature
|
|
282
295
|
if (!this.device.humidifier?.hide_temperature) {
|
|
283
|
-
this.CurrentTemperature =
|
|
296
|
+
this.CurrentTemperature = this.temperature!;
|
|
284
297
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
285
298
|
}
|
|
286
299
|
// Target Humidifier Dehumidifier State
|
|
287
|
-
switch (this.
|
|
300
|
+
switch (this.auto) {
|
|
288
301
|
case true:
|
|
289
302
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
290
303
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
@@ -292,10 +305,10 @@ export class Humidifier {
|
|
|
292
305
|
break;
|
|
293
306
|
default:
|
|
294
307
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
295
|
-
if (this.
|
|
308
|
+
if (this.nebulizationEfficiency! > 100) {
|
|
296
309
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
297
310
|
} else {
|
|
298
|
-
this.RelativeHumidityHumidifierThreshold = this.
|
|
311
|
+
this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
|
|
299
312
|
}
|
|
300
313
|
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
301
314
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
@@ -310,7 +323,7 @@ export class Humidifier {
|
|
|
310
323
|
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
311
324
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
312
325
|
// Active
|
|
313
|
-
switch (this.
|
|
326
|
+
switch (this.power) {
|
|
314
327
|
case 'on':
|
|
315
328
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
316
329
|
break;
|
|
@@ -319,7 +332,7 @@ export class Humidifier {
|
|
|
319
332
|
}
|
|
320
333
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
321
334
|
// Water Level
|
|
322
|
-
if (this.
|
|
335
|
+
if (this.lackWater) {
|
|
323
336
|
this.WaterLevel = 0;
|
|
324
337
|
} else {
|
|
325
338
|
this.WaterLevel = 100;
|
|
@@ -339,34 +352,12 @@ export class Humidifier {
|
|
|
339
352
|
}
|
|
340
353
|
}
|
|
341
354
|
|
|
342
|
-
public async connectBLE() {
|
|
343
|
-
let switchbot: any;
|
|
344
|
-
try {
|
|
345
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
346
|
-
const Switchbot = require('node-switchbot');
|
|
347
|
-
switchbot = new Switchbot();
|
|
348
|
-
// Convert to BLE Address
|
|
349
|
-
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
350
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
351
|
-
} catch (e: any) {
|
|
352
|
-
switchbot = false;
|
|
353
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
354
|
-
if (this.deviceLogging === 'debug') {
|
|
355
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
356
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
357
|
-
}
|
|
358
|
-
if (this.platform.debugMode) {
|
|
359
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
360
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return switchbot;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
355
|
private async BLERefreshStatus() {
|
|
367
356
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
368
|
-
|
|
369
|
-
|
|
357
|
+
const switchbot = await this.platform.connectBLE();
|
|
358
|
+
// Convert to BLE Address
|
|
359
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
360
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
370
361
|
// Start to monitor advertisement packets
|
|
371
362
|
if (switchbot !== false) {
|
|
372
363
|
switchbot.startScan({
|
|
@@ -438,10 +429,16 @@ export class Humidifier {
|
|
|
438
429
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
439
430
|
if (this.deviceStatus.message === 'success') {
|
|
440
431
|
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
432
|
+
this.auto = this.deviceStatus.body.auto;
|
|
433
|
+
this.power = this.deviceStatus.body.power;
|
|
434
|
+
this.lackWater = this.deviceStatus.body.lackWater;
|
|
435
|
+
this.humidity = this.deviceStatus.body.humidity;
|
|
436
|
+
this.temperature = this.deviceStatus.body.temperature;
|
|
437
|
+
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
441
438
|
this.parseStatus();
|
|
442
439
|
this.updateHomeKitCharacteristics();
|
|
443
440
|
} else {
|
|
444
|
-
this.
|
|
441
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} message: ${JSON.stringify(this.deviceStatus.message)}`);
|
|
445
442
|
}
|
|
446
443
|
} catch (e: any) {
|
|
447
444
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
@@ -477,7 +474,10 @@ export class Humidifier {
|
|
|
477
474
|
|
|
478
475
|
private async BLEpushChanges() {
|
|
479
476
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
480
|
-
const switchbot = await this.connectBLE();
|
|
477
|
+
const switchbot = await this.platform.connectBLE();
|
|
478
|
+
// Convert to BLE Address
|
|
479
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
480
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
481
481
|
if (switchbot !== false) {
|
|
482
482
|
switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
483
483
|
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|