@switchbot/homebridge-switchbot 1.10.2-beta.7 → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +20 -3
  2. package/config.schema.json +49 -0
  3. package/dist/device/bot.d.ts +43 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +26 -26
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +176 -140
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +38 -38
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +17 -17
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -11
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +14 -14
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +13 -13
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +19 -19
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/irdevice/airconditioner.d.ts +22 -22
  40. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  41. package/dist/irdevice/airconditioner.js +44 -44
  42. package/dist/irdevice/airconditioner.js.map +1 -1
  43. package/dist/irdevice/airpurifier.d.ts +12 -9
  44. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  45. package/dist/irdevice/airpurifier.js +20 -20
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.d.ts +10 -7
  48. package/dist/irdevice/camera.d.ts.map +1 -1
  49. package/dist/irdevice/camera.js +11 -11
  50. package/dist/irdevice/camera.js.map +1 -1
  51. package/dist/irdevice/fan.d.ts +12 -9
  52. package/dist/irdevice/fan.d.ts.map +1 -1
  53. package/dist/irdevice/fan.js +29 -29
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/light.d.ts +10 -7
  56. package/dist/irdevice/light.d.ts.map +1 -1
  57. package/dist/irdevice/light.js +13 -13
  58. package/dist/irdevice/light.js.map +1 -1
  59. package/dist/irdevice/other.d.ts +12 -9
  60. package/dist/irdevice/other.d.ts.map +1 -1
  61. package/dist/irdevice/other.js +17 -17
  62. package/dist/irdevice/other.js.map +1 -1
  63. package/dist/irdevice/tv.d.ts +13 -10
  64. package/dist/irdevice/tv.d.ts.map +1 -1
  65. package/dist/irdevice/tv.js +25 -25
  66. package/dist/irdevice/tv.js.map +1 -1
  67. package/dist/irdevice/vacuumcleaner.d.ts +10 -7
  68. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  69. package/dist/irdevice/vacuumcleaner.js +13 -13
  70. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  71. package/dist/irdevice/waterheater.d.ts +10 -7
  72. package/dist/irdevice/waterheater.d.ts.map +1 -1
  73. package/dist/irdevice/waterheater.js +16 -16
  74. package/dist/irdevice/waterheater.js.map +1 -1
  75. package/dist/platform.d.ts.map +1 -1
  76. package/dist/settings.d.ts +4 -1
  77. package/dist/settings.d.ts.map +1 -1
  78. package/dist/settings.js.map +1 -1
  79. package/package.json +76 -76
  80. package/src/device/bot.ts +50 -50
  81. package/src/device/colorbulb.ts +206 -157
  82. package/src/device/contact.ts +31 -30
  83. package/src/device/curtain.ts +68 -57
  84. package/src/device/humidifier.ts +65 -53
  85. package/src/device/lock.ts +25 -25
  86. package/src/device/meter.ts +25 -25
  87. package/src/device/motion.ts +27 -27
  88. package/src/device/plug.ts +22 -22
  89. package/src/irdevice/airconditioner.ts +54 -54
  90. package/src/irdevice/airpurifier.ts +30 -30
  91. package/src/irdevice/camera.ts +19 -19
  92. package/src/irdevice/fan.ts +40 -40
  93. package/src/irdevice/light.ts +23 -23
  94. package/src/irdevice/other.ts +25 -25
  95. package/src/irdevice/tv.ts +42 -42
  96. package/src/irdevice/vacuumcleaner.ts +21 -21
  97. package/src/irdevice/waterheater.ts +24 -24
  98. package/src/platform.ts +4 -4
  99. package/src/settings.ts +5 -1
@@ -12,7 +12,7 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse
12
12
  */
13
13
  export class Humidifier {
14
14
  // Services
15
- private service: Service;
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, 'SWITCHBOT-HUMIDIFIER-W0801800')
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.service =
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.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
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.service.setCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
99
+ this.humidifierService.setCharacteristic(
100
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState,
101
+ this.CurrentHumidifierDehumidifierState,
102
+ );
100
103
 
101
- this.service
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.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
114
+ this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
112
115
 
113
- this.service
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
- private BLEparseStatus() {
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
- private openAPIparseStatus() {
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
- private async BLERefreshStatus() {
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
- public async BLEconnection(switchbot: any) {
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
- private async openAPIRefreshStatus() {
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
- private async BLEpushChanges() {
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
- private async openAPIpushChanges() {
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.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
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.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
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.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
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.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
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.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
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.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
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
- public apiError(e: any) {
646
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
657
+ async apiError(e: any): Promise<void> {
658
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
647
659
  if (!this.device.ble) {
648
- this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
660
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
649
661
  }
650
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
651
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
652
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
653
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
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
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
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.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
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
- private minStep(): number | undefined {
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));
@@ -7,8 +7,8 @@ import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, device
7
7
 
8
8
  export class Lock {
9
9
  // Services
10
- private lockService: Service;
11
- private doorService?: Service;
10
+ lockService: Service;
11
+ contactSensorService?: Service;
12
12
 
13
13
  // Characteristic Values
14
14
  LockCurrentState!: CharacteristicValue;
@@ -52,12 +52,12 @@ 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, 'SWITCHBOT-LOCK-W1601700')
55
+ .setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
56
56
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
57
57
 
58
- // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
58
+ // get the LockMechanism service if it exists, otherwise create a new LockMechanism service
59
59
  // you can create multiple services for each accessory
60
- (this.lockService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
60
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
61
61
  `${device.deviceName} ${device.deviceType}`;
62
62
 
63
63
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -69,7 +69,7 @@ export class Lock {
69
69
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
70
70
 
71
71
  // each service must implement at-minimum the "required characteristics" for the given service type
72
- // see https://developers.homebridge.io/#/service/WindowCovering
72
+ // see https://developers.homebridge.io/#/service/LockMechanism
73
73
 
74
74
  // create handlers for required characteristics
75
75
  this.lockService.getCharacteristic(this.platform.Characteristic.LockCurrentState).onSet(this.LockTargetStateSet.bind(this));
@@ -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
- private async refreshStatus() {
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
- public apiError(e: any) {
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
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
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));