@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.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 (126) hide show
  1. package/README.md +16 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +32 -126
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +3 -5
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +1 -1
  9. package/dist/device/ceilinglight.d.ts.map +1 -1
  10. package/dist/device/ceilinglight.js +14 -47
  11. package/dist/device/ceilinglight.js.map +1 -1
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +9 -46
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts.map +1 -1
  16. package/dist/device/contact.js +20 -56
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts +1 -0
  19. package/dist/device/curtain.d.ts.map +1 -1
  20. package/dist/device/curtain.js +34 -147
  21. package/dist/device/curtain.js.map +1 -1
  22. package/dist/device/device.d.ts +25 -2
  23. package/dist/device/device.d.ts.map +1 -1
  24. package/dist/device/device.js +75 -5
  25. package/dist/device/device.js.map +1 -1
  26. package/dist/device/fan.d.ts.map +1 -1
  27. package/dist/device/fan.js +34 -50
  28. package/dist/device/fan.js.map +1 -1
  29. package/dist/device/hub.d.ts.map +1 -1
  30. package/dist/device/hub.js +2 -3
  31. package/dist/device/hub.js.map +1 -1
  32. package/dist/device/humidifier.d.ts.map +1 -1
  33. package/dist/device/humidifier.js +3 -5
  34. package/dist/device/humidifier.js.map +1 -1
  35. package/dist/device/iosensor.d.ts.map +1 -1
  36. package/dist/device/iosensor.js +2 -3
  37. package/dist/device/iosensor.js.map +1 -1
  38. package/dist/device/lightstrip.d.ts.map +1 -1
  39. package/dist/device/lightstrip.js +3 -5
  40. package/dist/device/lightstrip.js.map +1 -1
  41. package/dist/device/lock.d.ts.map +1 -1
  42. package/dist/device/lock.js +3 -5
  43. package/dist/device/lock.js.map +1 -1
  44. package/dist/device/meter.d.ts.map +1 -1
  45. package/dist/device/meter.js +2 -3
  46. package/dist/device/meter.js.map +1 -1
  47. package/dist/device/meterplus.d.ts.map +1 -1
  48. package/dist/device/meterplus.js +2 -3
  49. package/dist/device/meterplus.js.map +1 -1
  50. package/dist/device/motion.d.ts.map +1 -1
  51. package/dist/device/motion.js +2 -3
  52. package/dist/device/motion.js.map +1 -1
  53. package/dist/device/plug.d.ts.map +1 -1
  54. package/dist/device/plug.js +3 -5
  55. package/dist/device/plug.js.map +1 -1
  56. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  57. package/dist/device/robotvacuumcleaner.js +7 -11
  58. package/dist/device/robotvacuumcleaner.js.map +1 -1
  59. package/dist/device/waterdetector.d.ts.map +1 -1
  60. package/dist/device/waterdetector.js +2 -3
  61. package/dist/device/waterdetector.js.map +1 -1
  62. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  63. package/dist/irdevice/airconditioner.js +2 -3
  64. package/dist/irdevice/airconditioner.js.map +1 -1
  65. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  66. package/dist/irdevice/airpurifier.js +2 -3
  67. package/dist/irdevice/airpurifier.js.map +1 -1
  68. package/dist/irdevice/camera.d.ts.map +1 -1
  69. package/dist/irdevice/camera.js +2 -3
  70. package/dist/irdevice/camera.js.map +1 -1
  71. package/dist/irdevice/fan.d.ts.map +1 -1
  72. package/dist/irdevice/fan.js +2 -3
  73. package/dist/irdevice/fan.js.map +1 -1
  74. package/dist/irdevice/irdevice.d.ts +1 -0
  75. package/dist/irdevice/irdevice.d.ts.map +1 -1
  76. package/dist/irdevice/irdevice.js +4 -0
  77. package/dist/irdevice/irdevice.js.map +1 -1
  78. package/dist/irdevice/light.d.ts.map +1 -1
  79. package/dist/irdevice/light.js +2 -3
  80. package/dist/irdevice/light.js.map +1 -1
  81. package/dist/irdevice/other.d.ts.map +1 -1
  82. package/dist/irdevice/other.js +2 -3
  83. package/dist/irdevice/other.js.map +1 -1
  84. package/dist/irdevice/tv.d.ts.map +1 -1
  85. package/dist/irdevice/tv.js +2 -3
  86. package/dist/irdevice/tv.js.map +1 -1
  87. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  88. package/dist/irdevice/vacuumcleaner.js +2 -3
  89. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  90. package/dist/irdevice/waterheater.d.ts.map +1 -1
  91. package/dist/irdevice/waterheater.js +2 -3
  92. package/dist/irdevice/waterheater.js.map +1 -1
  93. package/dist/settings.d.ts +3 -2
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js.map +1 -1
  96. package/package.json +5 -5
  97. package/src/device/blindtilt.ts +42 -124
  98. package/src/device/bot.ts +3 -5
  99. package/src/device/ceilinglight.ts +19 -42
  100. package/src/device/colorbulb.ts +14 -41
  101. package/src/device/contact.ts +29 -55
  102. package/src/device/curtain.ts +43 -140
  103. package/src/device/device.ts +89 -7
  104. package/src/device/fan.ts +36 -51
  105. package/src/device/hub.ts +2 -3
  106. package/src/device/humidifier.ts +3 -5
  107. package/src/device/iosensor.ts +2 -3
  108. package/src/device/lightstrip.ts +3 -5
  109. package/src/device/lock.ts +3 -5
  110. package/src/device/meter.ts +2 -3
  111. package/src/device/meterplus.ts +2 -3
  112. package/src/device/motion.ts +2 -3
  113. package/src/device/plug.ts +3 -5
  114. package/src/device/robotvacuumcleaner.ts +7 -11
  115. package/src/device/waterdetector.ts +2 -3
  116. package/src/irdevice/airconditioner.ts +2 -3
  117. package/src/irdevice/airpurifier.ts +2 -3
  118. package/src/irdevice/camera.ts +2 -3
  119. package/src/irdevice/fan.ts +2 -3
  120. package/src/irdevice/irdevice.ts +5 -0
  121. package/src/irdevice/light.ts +2 -3
  122. package/src/irdevice/other.ts +2 -3
  123. package/src/irdevice/tv.ts +2 -3
  124. package/src/irdevice/vacuumcleaner.ts +2 -3
  125. package/src/irdevice/waterheater.ts +2 -3
  126. package/src/settings.ts +3 -2
@@ -265,14 +265,13 @@ export class BlindTilt extends deviceBase {
265
265
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},`
266
266
  + ` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
267
267
 
268
- if (!this.device.blindTilt?.hide_lightsensor) {
269
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
270
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
271
- const spaceBetweenLevels = 9;
272
-
268
+ if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
273
269
  if (this.LightSensor?.CurrentAmbientLightLevel === 0) {
274
270
  this.LightSensor!.CurrentAmbientLightLevel = 0.0001;
275
271
  }
272
+ const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
273
+ const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
274
+ const spaceBetweenLevels = 9;
276
275
 
277
276
  // Brightness
278
277
  switch (serviceData.lightLevel) {
@@ -465,9 +464,9 @@ export class BlindTilt extends deviceBase {
465
464
  if (switchbot === undefined) {
466
465
  await this.BLERefreshConnection(switchbot);
467
466
  } else {
468
- // Start to monitor advertisement packets
469
- (async () => {
470
467
  // Start to monitor advertisement packets
468
+ (async () => {
469
+ // Start to monitor advertisement packets
471
470
  const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
472
471
  // Update HomeKit
473
472
  if (serviceData.model !== '' && serviceData.modelName !== '') {
@@ -495,9 +494,8 @@ export class BlindTilt extends deviceBase {
495
494
  await this.statusCodes(statusCode, deviceStatus);
496
495
  }
497
496
  } catch (e: any) {
498
- this.apiError(e);
499
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
500
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
497
+ await this.apiError(e);
498
+ await this.openAPIRefreshError(e);
501
499
  }
502
500
  }
503
501
 
@@ -518,7 +516,7 @@ export class BlindTilt extends deviceBase {
518
516
  if (!device.blindTilt?.hide_lightsensor) {
519
517
  this.LightSensor!.CurrentAmbientLightLevel = lightLevel;
520
518
  }
521
- this.updateHomeKitCharacteristics();
519
+ await this.updateHomeKitCharacteristics();
522
520
  } catch (e: any) {
523
521
  this.errorLog(`${device.deviceType}: ${accessory.displayName} failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
524
522
  }
@@ -537,8 +535,7 @@ export class BlindTilt extends deviceBase {
537
535
  await this.openAPIpushChanges();
538
536
  } else {
539
537
  await this.offlineOff();
540
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
541
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
538
+ await this.pushChangeDisabled();
542
539
  }
543
540
  // Refresh the status from the API
544
541
  interval(15000)
@@ -575,13 +572,12 @@ export class BlindTilt extends deviceBase {
575
572
  + `Target Position: ${this.WindowCovering.TargetPosition} sent over BLE, sent successfully`);
576
573
  })
577
574
  .catch(async (e: any) => {
578
- this.apiError(e);
579
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
580
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
575
+ await this.apiError(e);
576
+ await this.failedBLEChanges(e);
581
577
  await this.BLEPushConnection();
582
578
  });
583
579
  } else {
584
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
580
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection,`);
585
581
  await this.BLEPushConnection();
586
582
  }
587
583
  } else {
@@ -652,36 +648,31 @@ export class BlindTilt extends deviceBase {
652
648
  * Handle requests to set the value of the "Target Horizontal Tilt" characteristic
653
649
  */
654
650
  async TargetHorizontalTiltAngleSet(value: CharacteristicValue): Promise<void> {
655
- if (this.WindowCovering.TargetHorizontalTiltAngle === this.accessory.context.TargetHorizontalTiltAngle) {
656
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetHorizontalTiltAngle: ${value}`);
651
+ if (this.WindowCovering.TargetHorizontalTiltAngle !== this.accessory.context.TargetHorizontalTiltAngle) {
652
+ await this.changeSet(value, 'TargetHorizontalTiltAngle');
657
653
  } else {
658
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHorizontalTiltAngle: ${value}`);
654
+ await this.noChangeSet(value, 'TargetHorizontalTiltAngle');
659
655
  }
660
656
 
661
657
  //value = value < 0 ? -90 : 90;
662
658
  this.WindowCovering.TargetHorizontalTiltAngle = value;
663
- if (this.device.mqttURL) {
664
- this.mqttPublish('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle.toString());
665
- }
666
-
667
- this.startUpdatingBlindTiltIfNeeded();
659
+ await this.mqtt('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle);
660
+ await this.startUpdatingBlindTiltIfNeeded();
668
661
  }
669
662
 
670
663
  /**
671
664
  * Handle requests to set the value of the "Target Position" characteristic
672
665
  */
673
666
  async TargetPositionSet(value: CharacteristicValue): Promise<void> {
674
- if (this.WindowCovering.TargetPosition === this.accessory.context.TargetPosition) {
675
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetPosition: ${value}`);
667
+ if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
668
+ await this.changeSet(value, 'TargetPosition');
676
669
  } else {
677
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
670
+ await this.noChangeSet(value, 'TargetPosition');
678
671
  }
679
672
 
680
673
  this.WindowCovering.TargetPosition = value;
681
- if (this.device.mqttURL) {
682
- this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
683
- }
684
- this.startUpdatingBlindTiltIfNeeded();
674
+ await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
675
+ await this.startUpdatingBlindTiltIfNeeded();
685
676
  }
686
677
 
687
678
  async startUpdatingBlindTiltIfNeeded(): Promise<void> {
@@ -726,106 +717,33 @@ export class BlindTilt extends deviceBase {
726
717
  await this.setMinMax();
727
718
  // CurrentHorizontalTiltAngle
728
719
  if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
729
- if (this.WindowCovering.CurrentHorizontalTiltAngle === undefined || Number.isNaN(this.WindowCovering.CurrentHorizontalTiltAngle)) {
730
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
731
- + ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
732
- } else {
733
- if (this.device.mqttURL) {
734
- this.mqttPublish('CurrentHorizontalTiltAngle', this.WindowCovering.CurrentHorizontalTiltAngle.toString());
735
- }
736
- this.accessory.context.CurrentHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
737
- this.WindowCovering.Service.updateCharacteristic(
738
- this.hap.Characteristic.CurrentHorizontalTiltAngle,
739
- Number(this.WindowCovering.CurrentHorizontalTiltAngle));
740
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
741
- updateCharacteristic CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
742
- }
720
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentHorizontalTiltAngle,
721
+ this.WindowCovering.CurrentHorizontalTiltAngle, 'CurrentHorizontalTiltAngle');
743
722
  }
744
723
  // CurrentPosition
745
- if (this.WindowCovering.CurrentPosition === undefined || Number.isNaN(this.WindowCovering.CurrentPosition)) {
746
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
747
- } else {
748
- if (this.device.mqttURL) {
749
- this.mqttPublish('CurrentPosition', this.WindowCovering.CurrentPosition.toString());
750
- }
751
- this.accessory.context.CurrentPosition = this.WindowCovering.CurrentPosition;
752
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.WindowCovering.CurrentPosition));
753
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
754
- + ` updateCharacteristic CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
755
- }
724
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition,
725
+ this.WindowCovering.CurrentPosition, 'CurrentPosition');
756
726
  // PositionState
757
- if (this.WindowCovering.PositionState === undefined) {
758
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.WindowCovering.PositionState}`);
759
- } else {
760
- if (this.device.mqttURL) {
761
- this.mqttPublish('PositionState', this.WindowCovering.PositionState.toString());
762
- }
763
- this.accessory.context.PositionState = this.WindowCovering.PositionState;
764
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
765
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
766
- + ` PositionState: ${this.WindowCovering.PositionState}`);
767
- }
727
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState,
728
+ this.WindowCovering.PositionState, 'PositionState');
768
729
  // TargetPosition
769
- if (this.WindowCovering.TargetPosition === undefined || Number.isNaN(this.WindowCovering.TargetPosition)) {
770
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
771
- } else {
772
- if (this.device.mqttURL) {
773
- this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
774
- }
775
- this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
776
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
777
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
778
- + ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
779
- }
730
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition,
731
+ this.WindowCovering.TargetPosition, 'TargetPosition');
780
732
  // CurrentAmbientLightLevel
781
- if (!this.device.blindTilt?.hide_lightsensor) {
782
- if (this.LightSensor!.CurrentAmbientLightLevel === undefined || Number.isNaN(this.LightSensor!.CurrentAmbientLightLevel)) {
783
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
784
- + ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
785
- } else {
786
- if (this.device.mqttURL) {
787
- this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor!.CurrentAmbientLightLevel.toString());
788
- }
789
- this.accessory.context.CurrentAmbientLightLevel = this.LightSensor!.CurrentAmbientLightLevel;
790
- this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor!.CurrentAmbientLightLevel);
791
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
792
- + ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
793
- }
733
+ if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
734
+ const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel };
735
+ await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
736
+ this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
794
737
  }
795
738
  // BatteryLevel
796
- if (this.Battery.BatteryLevel === undefined) {
797
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
798
- } else {
799
- if (this.device.mqttURL) {
800
- this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
801
- }
802
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
803
- this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
804
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
805
- }
739
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
740
+ this.Battery.BatteryLevel, 'BatteryLevel');
806
741
  // StatusLowBattery
807
- if (this.Battery.StatusLowBattery === undefined) {
808
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
809
- } else {
810
- if (this.device.mqttURL) {
811
- this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
812
- }
813
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
814
- this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
815
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
816
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
817
- }
818
- if (this.Battery.ChargingState === undefined) {
819
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
820
- } else {
821
- if (this.device.mqttURL) {
822
- this.mqttPublish('ChargingState', this.Battery.ChargingState.toString());
823
- }
824
- this.accessory.context.ChargingState = this.Battery.ChargingState;
825
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
826
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
827
- + ` ChargingState: ${this.Battery.ChargingState}`);
828
- }
742
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
743
+ this.Battery.StatusLowBattery, 'StatusLowBattery');
744
+ // ChargingState
745
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
746
+ this.Battery.ChargingState, 'ChargingState');
829
747
  }
830
748
 
831
749
  async BLEPushConnection() {
package/src/device/bot.ts CHANGED
@@ -632,9 +632,8 @@ export class Bot extends deviceBase {
632
632
  await this.statusCodes(statusCode, deviceStatus);
633
633
  }
634
634
  } catch (e: any) {
635
- this.apiError(e);
636
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
637
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
635
+ await this.apiError(e);
636
+ await this.openAPIRefreshError(e);
638
637
  }
639
638
  }
640
639
 
@@ -679,8 +678,7 @@ export class Bot extends deviceBase {
679
678
  await this.openAPIpushChanges();
680
679
  } else {
681
680
  await this.offlineOff();
682
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
683
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
681
+ await this.pushChangeDisabled();
684
682
  }
685
683
  // Refresh the status from the API
686
684
  interval(15000)
@@ -314,9 +314,8 @@ export class CeilingLight extends deviceBase {
314
314
  await this.statusCodes(statusCode, deviceStatus);
315
315
  }
316
316
  } catch (e: any) {
317
- this.apiError(e);
318
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
319
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
317
+ await this.apiError(e);
318
+ await this.openAPIRefreshError(e);
320
319
  }
321
320
  }
322
321
 
@@ -387,8 +386,7 @@ export class CeilingLight extends deviceBase {
387
386
  await this.openAPIpushChanges();
388
387
  } else {
389
388
  await this.offlineOff();
390
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
391
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
389
+ await this.pushChangeDisabled();
392
390
  }
393
391
  // Refresh the status from the API
394
392
  interval(15000)
@@ -691,42 +689,21 @@ export class CeilingLight extends deviceBase {
691
689
  }
692
690
 
693
691
  async updateHomeKitCharacteristics(): Promise<void> {
694
- if (this.LightBulb.On === undefined) {
695
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
696
- } else {
697
- this.accessory.context.On = this.LightBulb.On;
698
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
699
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
700
- }
701
- if (this.LightBulb.Brightness === undefined) {
702
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
703
- } else {
704
- this.accessory.context.Brightness = this.LightBulb.Brightness;
705
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
706
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
707
- }
708
- if (this.LightBulb.ColorTemperature === undefined) {
709
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
710
- } else {
711
- this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
712
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
713
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
714
- + ` updateCharacteristic ColorTemperature: ${this.LightBulb.ColorTemperature}`);
715
- }
716
- if (this.LightBulb.Hue === undefined) {
717
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
718
- } else {
719
- this.accessory.context.Hue = this.LightBulb.Hue;
720
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
721
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
722
- }
723
- if (this.LightBulb.Saturation === undefined) {
724
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
725
- } else {
726
- this.accessory.context.Saturation = this.LightBulb.Saturation;
727
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
728
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
729
- }
692
+ // On
693
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
694
+ this.LightBulb.On, 'On');
695
+ // Brightness
696
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
697
+ this.LightBulb.Brightness, 'Brightness');
698
+ // ColorTemperature
699
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
700
+ this.LightBulb.ColorTemperature, 'ColorTemperature');
701
+ // Hue
702
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
703
+ this.LightBulb.Hue, 'Hue');
704
+ // Saturation
705
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
706
+ this.LightBulb.Saturation, 'Saturation');
730
707
  }
731
708
 
732
709
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -761,7 +738,7 @@ export class CeilingLight extends deviceBase {
761
738
  }
762
739
  }
763
740
 
764
- apiError(e: any): void {
741
+ async apiError(e: any): Promise<void> {
765
742
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
766
743
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
767
744
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
@@ -341,9 +341,8 @@ export class ColorBulb extends deviceBase {
341
341
  await this.statusCodes(statusCode, deviceStatus);
342
342
  }
343
343
  } catch (e: any) {
344
- this.apiError(e);
345
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
346
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
344
+ await this.apiError(e);
345
+ await this.openAPIRefreshError(e);
347
346
  }
348
347
  }
349
348
 
@@ -440,8 +439,7 @@ export class ColorBulb extends deviceBase {
440
439
  await this.openAPIpushChanges();
441
440
  } else {
442
441
  await this.offlineOff();
443
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
444
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
442
+ await this.pushChangeDisabled();
445
443
  }
446
444
  // Refresh the status from the API
447
445
  interval(15000)
@@ -499,6 +497,7 @@ export class ColorBulb extends deviceBase {
499
497
  if (this.LightBulb.On) {
500
498
  await this.BLEpushRGBChanges();
501
499
  }
500
+ await this.updateHomeKitCharacteristics();
502
501
  } else {
503
502
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, On: ${this.LightBulb.On},`
504
503
  + ` OnCached: ${this.accessory.context.On}`);
@@ -852,46 +851,20 @@ export class ColorBulb extends deviceBase {
852
851
 
853
852
  async updateHomeKitCharacteristics(): Promise<void> {
854
853
  // On
855
- if (this.LightBulb.On === undefined) {
856
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
857
- } else {
858
- this.accessory.context.On = this.LightBulb.On;
859
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
860
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
861
- }
854
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
855
+ this.LightBulb.On, 'On');
862
856
  // Brightness
863
- if (this.LightBulb.Brightness === undefined) {
864
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
865
- } else {
866
- this.accessory.context.Brightness = this.LightBulb.Brightness;
867
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
868
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
869
- }
857
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
858
+ this.LightBulb.Brightness, 'Brightness');
870
859
  // ColorTemperature
871
- if (this.LightBulb.ColorTemperature === undefined) {
872
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
873
- } else {
874
- this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
875
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
876
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
877
- + ` ColorTemperature: ${this.LightBulb.ColorTemperature}`);
878
- }
860
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
861
+ this.LightBulb.ColorTemperature, 'ColorTemperature');
879
862
  // Hue
880
- if (this.LightBulb.Hue === undefined) {
881
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
882
- } else {
883
- this.accessory.context.Hue = this.LightBulb.Hue;
884
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
885
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
886
- }
863
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
864
+ this.LightBulb.Hue, 'Hue');
887
865
  // Saturation
888
- if (this.LightBulb.Saturation === undefined) {
889
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
890
- } else {
891
- this.accessory.context.Saturation = this.LightBulb.Saturation;
892
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
893
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
894
- }
866
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
867
+ this.LightBulb.Saturation, 'Saturation');
895
868
  }
896
869
 
897
870
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -340,9 +340,8 @@ export class Contact extends deviceBase {
340
340
  await this.statusCodes(statusCode, deviceStatus);
341
341
  }
342
342
  } catch (e: any) {
343
- this.apiError(e);
344
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
345
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
343
+ await this.apiError(e);
344
+ await this.openAPIRefreshError(e);
346
345
  }
347
346
  }
348
347
 
@@ -381,50 +380,25 @@ export class Contact extends deviceBase {
381
380
  * Updates the status for each of the HomeKit Characteristics
382
381
  */
383
382
  async updateHomeKitCharacteristics(): Promise<void> {
384
- if (this.ContactSensor.ContactSensorState === undefined) {
385
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
386
- } else {
387
- this.accessory.context.ContactSensorState = this.ContactSensor.ContactSensorState;
388
- this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensor.ContactSensorState);
389
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
390
- + ` ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
383
+ // ContactSensorState
384
+ await this.updateCharacteristic(this.ContactSensor.Service, this.hap.Characteristic.ContactSensorState,
385
+ this.ContactSensor.ContactSensorState, 'ContactSensorState');
386
+ // MotionDetected
387
+ if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
388
+ await this.updateCharacteristic(this.MotionSensor.Service, this.hap.Characteristic.MotionDetected,
389
+ this.MotionSensor.MotionDetected, 'MotionDetected');
391
390
  }
392
- if (!this.device.contact?.hide_motionsensor) {
393
- if (this.MotionSensor!.MotionDetected === undefined) {
394
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionSensor!.MotionDetected}`);
395
- } else {
396
- this.accessory.context.MotionDetected = this.MotionSensor!.MotionDetected;
397
- this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, this.MotionSensor!.MotionDetected);
398
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
399
- + ` MotionDetected: ${this.MotionSensor!.MotionDetected}`);
400
- }
401
- }
402
- if (!this.device.contact?.hide_lightsensor) {
403
- if (this.LightSensor?.CurrentAmbientLightLevel === undefined) {
404
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
405
- + ` CurrentAmbientLightLevel: ${this.LightSensor?.CurrentAmbientLightLevel}`);
406
- } else {
407
- this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
408
- this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
409
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
410
- + ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
411
- }
412
- }
413
- if (this.Battery.BatteryLevel === undefined) {
414
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
415
- } else {
416
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
417
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
418
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
419
- }
420
- if (this.Battery.StatusLowBattery === undefined) {
421
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
422
- } else {
423
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
424
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
425
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
426
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
391
+ // CurrentAmbientLightLevel
392
+ if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
393
+ await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
394
+ this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel');
427
395
  }
396
+ // BatteryLevel
397
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
398
+ this.Battery.BatteryLevel, 'BatteryLevel');
399
+ // StatusLowBattery
400
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
401
+ this.Battery.StatusLowBattery, 'StatusLowBattery');
428
402
  }
429
403
 
430
404
  async BLERefreshConnection(switchbot: any): Promise<void> {
@@ -440,11 +414,11 @@ export class Contact extends deviceBase {
440
414
  if (this.device.offline) {
441
415
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState,
442
416
  this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED);
443
- if (!this.device.contact?.hide_motionsensor) {
444
- this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, false);
417
+ if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
418
+ this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, false);
445
419
  }
446
- if (!this.device.contact?.hide_lightsensor) {
447
- this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, 100);
420
+ if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
421
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, 100);
448
422
  }
449
423
  }
450
424
  }
@@ -452,13 +426,13 @@ export class Contact extends deviceBase {
452
426
  async apiError(e: any): Promise<void> {
453
427
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
454
428
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
455
- if (!this.device.contact?.hide_motionsensor) {
456
- this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
457
- this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
429
+ if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
430
+ this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
431
+ this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
458
432
  }
459
- if (!this.device.contact?.hide_lightsensor) {
460
- this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
461
- this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
433
+ if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
434
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
435
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
462
436
  }
463
437
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
464
438
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);