@switchbot/homebridge-switchbot 1.10.2-beta.8 → 1.12.0
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 +27 -3
- package/config.schema.json +58 -0
- package/dist/device/bot.d.ts +51 -40
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +58 -32
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +25 -21
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +176 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -15
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +14 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +25 -22
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -37
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +23 -20
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -38
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +16 -13
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +14 -14
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -15
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +14 -14
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +13 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +17 -17
- package/dist/device/plug.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +44 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +20 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +11 -11
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +29 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +17 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +25 -25
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +13 -13
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +16 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/settings.d.ts +5 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +82 -55
- package/src/device/colorbulb.ts +206 -157
- package/src/device/contact.ts +31 -30
- package/src/device/curtain.ts +68 -57
- package/src/device/humidifier.ts +65 -53
- package/src/device/lock.ts +22 -22
- package/src/device/meter.ts +25 -25
- package/src/device/motion.ts +27 -27
- package/src/device/plug.ts +20 -20
- package/src/irdevice/airconditioner.ts +54 -54
- package/src/irdevice/airpurifier.ts +30 -30
- package/src/irdevice/camera.ts +19 -19
- package/src/irdevice/fan.ts +40 -40
- package/src/irdevice/light.ts +23 -23
- package/src/irdevice/other.ts +25 -25
- package/src/irdevice/tv.ts +42 -42
- package/src/irdevice/vacuumcleaner.ts +21 -21
- package/src/irdevice/waterheater.ts +24 -24
- package/src/platform.ts +4 -4
- package/src/settings.ts +6 -1
package/src/device/humidifier.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse
|
|
|
12
12
|
*/
|
|
13
13
|
export class Humidifier {
|
|
14
14
|
// Services
|
|
15
|
-
|
|
15
|
+
humidifierService: Service;
|
|
16
16
|
temperatureservice?: Service;
|
|
17
17
|
|
|
18
18
|
// Characteristic Values
|
|
@@ -75,12 +75,12 @@ export class Humidifier {
|
|
|
75
75
|
accessory
|
|
76
76
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
77
77
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
78
|
-
.setCharacteristic(this.platform.Characteristic.Model, '
|
|
78
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'W0801800')
|
|
79
79
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
80
80
|
|
|
81
81
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
82
82
|
// you can create multiple services for each accessory
|
|
83
|
-
(this.
|
|
83
|
+
(this.humidifierService =
|
|
84
84
|
accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
85
85
|
`${accessory.displayName} Humidifier`;
|
|
86
86
|
|
|
@@ -90,15 +90,18 @@ export class Humidifier {
|
|
|
90
90
|
|
|
91
91
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
92
92
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
93
|
-
this.
|
|
93
|
+
this.humidifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
94
94
|
|
|
95
95
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
96
96
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
97
97
|
|
|
98
98
|
// create handlers for required characteristics
|
|
99
|
-
this.
|
|
99
|
+
this.humidifierService.setCharacteristic(
|
|
100
|
+
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
101
|
+
this.CurrentHumidifierDehumidifierState,
|
|
102
|
+
);
|
|
100
103
|
|
|
101
|
-
this.
|
|
104
|
+
this.humidifierService
|
|
102
105
|
.getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
|
|
103
106
|
.setProps({
|
|
104
107
|
validValueRanges: [0, 1],
|
|
@@ -108,9 +111,9 @@ export class Humidifier {
|
|
|
108
111
|
})
|
|
109
112
|
.onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
|
|
110
113
|
|
|
111
|
-
this.
|
|
114
|
+
this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
|
|
112
115
|
|
|
113
|
-
this.
|
|
116
|
+
this.humidifierService
|
|
114
117
|
.getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
115
118
|
.setProps({
|
|
116
119
|
validValueRanges: [0, 100],
|
|
@@ -188,15 +191,15 @@ export class Humidifier {
|
|
|
188
191
|
/**
|
|
189
192
|
* Parse the device status from the SwitchBot api
|
|
190
193
|
*/
|
|
191
|
-
parseStatus() {
|
|
194
|
+
async parseStatus(): Promise<void> {
|
|
192
195
|
if (this.device.ble) {
|
|
193
|
-
this.BLEparseStatus();
|
|
196
|
+
await this.BLEparseStatus();
|
|
194
197
|
} else {
|
|
195
|
-
this.openAPIparseStatus();
|
|
198
|
+
await this.openAPIparseStatus();
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
|
|
199
|
-
|
|
202
|
+
async BLEparseStatus(): Promise<void> {
|
|
200
203
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
|
|
201
204
|
// Current Relative Humidity
|
|
202
205
|
this.CurrentRelativeHumidity = this.percentage!;
|
|
@@ -210,7 +213,7 @@ export class Humidifier {
|
|
|
210
213
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
|
|
216
|
+
async openAPIparseStatus(): Promise<void> {
|
|
214
217
|
if (this.platform.config.credentials?.openToken) {
|
|
215
218
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
216
219
|
// Current Relative Humidity
|
|
@@ -270,7 +273,7 @@ export class Humidifier {
|
|
|
270
273
|
/**
|
|
271
274
|
* Asks the SwitchBot API for the latest device information
|
|
272
275
|
*/
|
|
273
|
-
async refreshStatus() {
|
|
276
|
+
async refreshStatus(): Promise<void> {
|
|
274
277
|
if (this.device.ble) {
|
|
275
278
|
await this.BLERefreshStatus();
|
|
276
279
|
} else {
|
|
@@ -278,7 +281,7 @@ export class Humidifier {
|
|
|
278
281
|
}
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
|
|
284
|
+
async BLERefreshStatus(): Promise<void> {
|
|
282
285
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
283
286
|
const switchbot = await this.platform.connectBLE();
|
|
284
287
|
// Convert to BLE Address
|
|
@@ -349,7 +352,7 @@ export class Humidifier {
|
|
|
349
352
|
}
|
|
350
353
|
}
|
|
351
354
|
|
|
352
|
-
|
|
355
|
+
async BLEconnection(switchbot: any): Promise<void> {
|
|
353
356
|
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
354
357
|
if (this.platform.config.credentials?.openToken) {
|
|
355
358
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -357,7 +360,7 @@ export class Humidifier {
|
|
|
357
360
|
}
|
|
358
361
|
}
|
|
359
362
|
|
|
360
|
-
|
|
363
|
+
async openAPIRefreshStatus(): Promise<void> {
|
|
361
364
|
if (this.platform.config.credentials?.openToken) {
|
|
362
365
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
363
366
|
try {
|
|
@@ -394,7 +397,7 @@ export class Humidifier {
|
|
|
394
397
|
/**
|
|
395
398
|
* Pushes the requested changes to the SwitchBot API
|
|
396
399
|
*/
|
|
397
|
-
async pushChanges() {
|
|
400
|
+
async pushChanges(): Promise<void> {
|
|
398
401
|
//if (this.device.ble) {
|
|
399
402
|
// await this.BLEpushChanges();
|
|
400
403
|
//} else {
|
|
@@ -403,12 +406,12 @@ export class Humidifier {
|
|
|
403
406
|
interval(5000)
|
|
404
407
|
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
405
408
|
.pipe(take(1))
|
|
406
|
-
.subscribe(() => {
|
|
407
|
-
this.refreshStatus();
|
|
409
|
+
.subscribe(async () => {
|
|
410
|
+
await this.refreshStatus();
|
|
408
411
|
});
|
|
409
412
|
}
|
|
410
413
|
|
|
411
|
-
|
|
414
|
+
async BLEpushChanges(): Promise<void> {
|
|
412
415
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
413
416
|
const switchbot = await this.platform.connectBLE();
|
|
414
417
|
// Convert to BLE Address
|
|
@@ -452,7 +455,7 @@ export class Humidifier {
|
|
|
452
455
|
}
|
|
453
456
|
}
|
|
454
457
|
|
|
455
|
-
|
|
458
|
+
async openAPIpushChanges(): Promise<void> {
|
|
456
459
|
if (this.platform.config.credentials?.openToken) {
|
|
457
460
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
458
461
|
if (
|
|
@@ -503,7 +506,7 @@ export class Humidifier {
|
|
|
503
506
|
/**
|
|
504
507
|
* Pushes the requested changes to the SwitchBot API
|
|
505
508
|
*/
|
|
506
|
-
async pushAutoChanges() {
|
|
509
|
+
async pushAutoChanges(): Promise<void> {
|
|
507
510
|
try {
|
|
508
511
|
if (
|
|
509
512
|
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
@@ -544,7 +547,7 @@ export class Humidifier {
|
|
|
544
547
|
/**
|
|
545
548
|
* Pushes the requested changes to the SwitchBot API
|
|
546
549
|
*/
|
|
547
|
-
async pushActiveChanges() {
|
|
550
|
+
async pushActiveChanges(): Promise<void> {
|
|
548
551
|
try {
|
|
549
552
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
550
553
|
this.debugLog('Pushing Off!');
|
|
@@ -582,25 +585,28 @@ export class Humidifier {
|
|
|
582
585
|
/**
|
|
583
586
|
* Updates the status for each of the HomeKit Characteristics
|
|
584
587
|
*/
|
|
585
|
-
updateHomeKitCharacteristics() {
|
|
588
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
586
589
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
587
590
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
588
591
|
} else {
|
|
589
|
-
this.
|
|
592
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
590
593
|
this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
591
594
|
}
|
|
592
595
|
if (!this.device.ble) {
|
|
593
596
|
if (this.WaterLevel === undefined) {
|
|
594
597
|
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
595
598
|
} else {
|
|
596
|
-
this.
|
|
599
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
597
600
|
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
598
601
|
}
|
|
599
602
|
}
|
|
600
603
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
601
604
|
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
602
605
|
} else {
|
|
603
|
-
this.
|
|
606
|
+
this.humidifierService.updateCharacteristic(
|
|
607
|
+
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
608
|
+
this.CurrentHumidifierDehumidifierState,
|
|
609
|
+
);
|
|
604
610
|
this.debugLog(
|
|
605
611
|
`Humidifier: ${this.accessory.displayName}` +
|
|
606
612
|
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
@@ -609,7 +615,10 @@ export class Humidifier {
|
|
|
609
615
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
610
616
|
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
611
617
|
} else {
|
|
612
|
-
this.
|
|
618
|
+
this.humidifierService.updateCharacteristic(
|
|
619
|
+
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
620
|
+
this.TargetHumidifierDehumidifierState,
|
|
621
|
+
);
|
|
613
622
|
this.debugLog(
|
|
614
623
|
`Humidifier: ${this.accessory.displayName}` +
|
|
615
624
|
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
@@ -618,7 +627,7 @@ export class Humidifier {
|
|
|
618
627
|
if (this.Active === undefined) {
|
|
619
628
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
620
629
|
} else {
|
|
621
|
-
this.
|
|
630
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
622
631
|
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
623
632
|
}
|
|
624
633
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
@@ -626,7 +635,10 @@ export class Humidifier {
|
|
|
626
635
|
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
627
636
|
);
|
|
628
637
|
} else {
|
|
629
|
-
this.
|
|
638
|
+
this.humidifierService.updateCharacteristic(
|
|
639
|
+
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
640
|
+
this.RelativeHumidityHumidifierThreshold,
|
|
641
|
+
);
|
|
630
642
|
this.debugLog(
|
|
631
643
|
`Humidifier: ${this.accessory.displayName}` +
|
|
632
644
|
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
@@ -642,22 +654,22 @@ export class Humidifier {
|
|
|
642
654
|
}
|
|
643
655
|
}
|
|
644
656
|
|
|
645
|
-
|
|
646
|
-
this.
|
|
657
|
+
async apiError(e: any): Promise<void> {
|
|
658
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
647
659
|
if (!this.device.ble) {
|
|
648
|
-
this.
|
|
660
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
649
661
|
}
|
|
650
|
-
this.
|
|
651
|
-
this.
|
|
652
|
-
this.
|
|
653
|
-
this.
|
|
662
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
663
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
664
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
665
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
654
666
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
655
667
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
656
668
|
}
|
|
657
669
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
658
670
|
}
|
|
659
671
|
|
|
660
|
-
|
|
672
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
661
673
|
switch (push.data.statusCode) {
|
|
662
674
|
case 151:
|
|
663
675
|
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -690,17 +702,17 @@ export class Humidifier {
|
|
|
690
702
|
}
|
|
691
703
|
}
|
|
692
704
|
|
|
693
|
-
offlineOff() {
|
|
705
|
+
async offlineOff(): Promise<void> {
|
|
694
706
|
if (this.device.offline) {
|
|
695
707
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
696
|
-
this.
|
|
708
|
+
this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
|
|
697
709
|
}
|
|
698
710
|
}
|
|
699
711
|
|
|
700
712
|
/**
|
|
701
713
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
702
714
|
*/
|
|
703
|
-
handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue) {
|
|
715
|
+
async handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
704
716
|
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
|
|
705
717
|
|
|
706
718
|
this.TargetHumidifierDehumidifierState = value;
|
|
@@ -710,7 +722,7 @@ export class Humidifier {
|
|
|
710
722
|
/**
|
|
711
723
|
* Handle requests to set the "Active" characteristic
|
|
712
724
|
*/
|
|
713
|
-
handleActiveSet(value: CharacteristicValue) {
|
|
725
|
+
async handleActiveSet(value: CharacteristicValue): Promise<void> {
|
|
714
726
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
|
|
715
727
|
this.Active = value;
|
|
716
728
|
this.doHumidifierUpdate.next();
|
|
@@ -719,7 +731,7 @@ export class Humidifier {
|
|
|
719
731
|
/**
|
|
720
732
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
721
733
|
*/
|
|
722
|
-
handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue) {
|
|
734
|
+
async handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
723
735
|
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
724
736
|
|
|
725
737
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
@@ -730,7 +742,7 @@ export class Humidifier {
|
|
|
730
742
|
this.doHumidifierUpdate.next();
|
|
731
743
|
}
|
|
732
744
|
|
|
733
|
-
config(device: device & devicesConfig) {
|
|
745
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
734
746
|
let config = {};
|
|
735
747
|
if (device.humidifier) {
|
|
736
748
|
config = device.humidifier;
|
|
@@ -755,7 +767,7 @@ export class Humidifier {
|
|
|
755
767
|
}
|
|
756
768
|
}
|
|
757
769
|
|
|
758
|
-
refreshRate(device: device & devicesConfig) {
|
|
770
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
759
771
|
if (device.refreshRate) {
|
|
760
772
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
761
773
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
@@ -765,7 +777,7 @@ export class Humidifier {
|
|
|
765
777
|
}
|
|
766
778
|
}
|
|
767
779
|
|
|
768
|
-
scan(device: device & devicesConfig) {
|
|
780
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
769
781
|
if (device.scanDuration) {
|
|
770
782
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
771
783
|
if (device.ble) {
|
|
@@ -779,7 +791,7 @@ export class Humidifier {
|
|
|
779
791
|
}
|
|
780
792
|
}
|
|
781
793
|
|
|
782
|
-
logs(device: device & devicesConfig) {
|
|
794
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
783
795
|
if (this.platform.debugMode) {
|
|
784
796
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
785
797
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -795,7 +807,7 @@ export class Humidifier {
|
|
|
795
807
|
}
|
|
796
808
|
}
|
|
797
809
|
|
|
798
|
-
|
|
810
|
+
minStep(): number {
|
|
799
811
|
if (this.device.humidifier?.set_minStep) {
|
|
800
812
|
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
801
813
|
} else {
|
|
@@ -807,25 +819,25 @@ export class Humidifier {
|
|
|
807
819
|
/**
|
|
808
820
|
* Logging for Device
|
|
809
821
|
*/
|
|
810
|
-
infoLog(...log: any[]) {
|
|
822
|
+
infoLog(...log: any[]): void {
|
|
811
823
|
if (this.enablingDeviceLogging()) {
|
|
812
824
|
this.platform.log.info(String(...log));
|
|
813
825
|
}
|
|
814
826
|
}
|
|
815
827
|
|
|
816
|
-
warnLog(...log: any[]) {
|
|
828
|
+
warnLog(...log: any[]): void {
|
|
817
829
|
if (this.enablingDeviceLogging()) {
|
|
818
830
|
this.platform.log.warn(String(...log));
|
|
819
831
|
}
|
|
820
832
|
}
|
|
821
833
|
|
|
822
|
-
errorLog(...log: any[]) {
|
|
834
|
+
errorLog(...log: any[]): void {
|
|
823
835
|
if (this.enablingDeviceLogging()) {
|
|
824
836
|
this.platform.log.error(String(...log));
|
|
825
837
|
}
|
|
826
838
|
}
|
|
827
839
|
|
|
828
|
-
debugLog(...log: any[]) {
|
|
840
|
+
debugLog(...log: any[]): void {
|
|
829
841
|
if (this.enablingDeviceLogging()) {
|
|
830
842
|
if (this.deviceLogging === 'debug') {
|
|
831
843
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/device/lock.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, device
|
|
|
7
7
|
|
|
8
8
|
export class Lock {
|
|
9
9
|
// Services
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
lockService: Service;
|
|
11
|
+
contactSensorService?: Service;
|
|
12
12
|
|
|
13
13
|
// Characteristic Values
|
|
14
14
|
LockCurrentState!: CharacteristicValue;
|
|
@@ -52,7 +52,7 @@ export class Lock {
|
|
|
52
52
|
accessory
|
|
53
53
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
54
54
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
55
|
-
.setCharacteristic(this.platform.Characteristic.Model, '
|
|
55
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
|
|
56
56
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
57
57
|
|
|
58
58
|
// get the LockMechanism service if it exists, otherwise create a new LockMechanism service
|
|
@@ -80,8 +80,8 @@ export class Lock {
|
|
|
80
80
|
// Start an update interval
|
|
81
81
|
interval(this.deviceRefreshRate * 1000)
|
|
82
82
|
.pipe(skipWhile(() => this.lockUpdateInProgress))
|
|
83
|
-
.subscribe(() => {
|
|
84
|
-
this.refreshStatus();
|
|
83
|
+
.subscribe(async () => {
|
|
84
|
+
await this.refreshStatus();
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
// Watch for Lock change events
|
|
@@ -110,7 +110,7 @@ export class Lock {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
parseStatus() {
|
|
113
|
+
async parseStatus(): Promise<void> {
|
|
114
114
|
switch (this.lockState) {
|
|
115
115
|
case 'on':
|
|
116
116
|
this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
|
|
@@ -121,7 +121,7 @@ export class Lock {
|
|
|
121
121
|
this.debugLog(`Lock: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
async refreshStatus(): Promise<void> {
|
|
125
125
|
try {
|
|
126
126
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
127
127
|
this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
@@ -151,7 +151,7 @@ export class Lock {
|
|
|
151
151
|
* Lock - "command" "????" "????" = set to ???? state
|
|
152
152
|
* Lock - "command" "????" "????" = set to ???? state - LockCurrentState
|
|
153
153
|
*/
|
|
154
|
-
async pushChanges() {
|
|
154
|
+
async pushChanges(): Promise<void> {
|
|
155
155
|
if (this.LockTargetState !== this.LockTargetStateCached) {
|
|
156
156
|
const payload = {
|
|
157
157
|
commandType: 'command',
|
|
@@ -179,12 +179,12 @@ export class Lock {
|
|
|
179
179
|
interval(5000)
|
|
180
180
|
.pipe(skipWhile(() => this.lockUpdateInProgress))
|
|
181
181
|
.pipe(take(1))
|
|
182
|
-
.subscribe(() => {
|
|
183
|
-
this.refreshStatus();
|
|
182
|
+
.subscribe(async () => {
|
|
183
|
+
await this.refreshStatus();
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
updateHomeKitCharacteristics() {
|
|
187
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
188
188
|
if (this.LockTargetState === undefined) {
|
|
189
189
|
this.debugLog(`Lock: ${this.accessory.displayName} LockTargetState: ${this.LockTargetState}`);
|
|
190
190
|
} else {
|
|
@@ -199,13 +199,13 @@ export class Lock {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
async apiError(e: any): Promise<void> {
|
|
203
203
|
this.lockService.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
|
|
204
204
|
this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
|
|
205
205
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
209
209
|
switch (push.data.statusCode) {
|
|
210
210
|
case 151:
|
|
211
211
|
this.errorLog(`Lock: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -239,14 +239,14 @@ export class Lock {
|
|
|
239
239
|
/**
|
|
240
240
|
* Handle requests to set the value of the "On" characteristic
|
|
241
241
|
*/
|
|
242
|
-
LockTargetStateSet(value: CharacteristicValue) {
|
|
242
|
+
async LockTargetStateSet(value: CharacteristicValue): Promise<void> {
|
|
243
243
|
this.debugLog(`Lock: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
244
244
|
|
|
245
245
|
this.LockTargetState = value;
|
|
246
246
|
this.doLockUpdate.next();
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
config(device: device & devicesConfig) {
|
|
249
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
250
250
|
let config = {};
|
|
251
251
|
if (device.lock) {
|
|
252
252
|
config = device.lock;
|
|
@@ -268,7 +268,7 @@ export class Lock {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
refreshRate(device: device & devicesConfig) {
|
|
271
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
272
272
|
if (device.refreshRate) {
|
|
273
273
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
274
274
|
this.debugLog(`Lock: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
@@ -278,7 +278,7 @@ export class Lock {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
scan(device: device & devicesConfig) {
|
|
281
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
282
282
|
if (device.scanDuration) {
|
|
283
283
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
284
284
|
if (device.ble) {
|
|
@@ -292,7 +292,7 @@ export class Lock {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
logs(device: device & devicesConfig) {
|
|
295
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
296
296
|
if (this.platform.debugMode) {
|
|
297
297
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
298
298
|
this.debugLog(`Lock: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -311,25 +311,25 @@ export class Lock {
|
|
|
311
311
|
/**
|
|
312
312
|
* Logging for Device
|
|
313
313
|
*/
|
|
314
|
-
infoLog(...log: any[]) {
|
|
314
|
+
infoLog(...log: any[]): void {
|
|
315
315
|
if (this.enablingDeviceLogging()) {
|
|
316
316
|
this.platform.log.info(String(...log));
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
warnLog(...log: any[]) {
|
|
320
|
+
warnLog(...log: any[]): void {
|
|
321
321
|
if (this.enablingDeviceLogging()) {
|
|
322
322
|
this.platform.log.warn(String(...log));
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
errorLog(...log: any[]) {
|
|
326
|
+
errorLog(...log: any[]): void {
|
|
327
327
|
if (this.enablingDeviceLogging()) {
|
|
328
328
|
this.platform.log.error(String(...log));
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
debugLog(...log: any[]) {
|
|
332
|
+
debugLog(...log: any[]): void {
|
|
333
333
|
if (this.enablingDeviceLogging()) {
|
|
334
334
|
if (this.deviceLogging === 'debug') {
|
|
335
335
|
this.platform.log.info('[DEBUG]', String(...log));
|