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