@switchbot/homebridge-switchbot 2.8.0-beta.1 → 2.8.0-beta.10

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 (129) hide show
  1. package/dist/device/blindtilt.d.ts +1 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +9 -6
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -0
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +8 -5
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +1 -0
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +12 -9
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +1 -0
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +8 -5
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +2 -0
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +45 -34
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +2 -0
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +31 -36
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/hub.d.ts +3 -1
  26. package/dist/device/hub.d.ts.map +1 -1
  27. package/dist/device/hub.js +29 -4
  28. package/dist/device/hub.js.map +1 -1
  29. package/dist/device/humidifier.d.ts.map +1 -1
  30. package/dist/device/humidifier.js +9 -6
  31. package/dist/device/humidifier.js.map +1 -1
  32. package/dist/device/iosensor.d.ts +1 -0
  33. package/dist/device/iosensor.d.ts.map +1 -1
  34. package/dist/device/iosensor.js +10 -6
  35. package/dist/device/iosensor.js.map +1 -1
  36. package/dist/device/lightstrip.d.ts +1 -0
  37. package/dist/device/lightstrip.d.ts.map +1 -1
  38. package/dist/device/lightstrip.js +9 -6
  39. package/dist/device/lightstrip.js.map +1 -1
  40. package/dist/device/lock.d.ts +2 -0
  41. package/dist/device/lock.d.ts.map +1 -1
  42. package/dist/device/lock.js +11 -6
  43. package/dist/device/lock.js.map +1 -1
  44. package/dist/device/meter.d.ts +2 -0
  45. package/dist/device/meter.d.ts.map +1 -1
  46. package/dist/device/meter.js +12 -8
  47. package/dist/device/meter.js.map +1 -1
  48. package/dist/device/meterplus.d.ts +4 -3
  49. package/dist/device/meterplus.d.ts.map +1 -1
  50. package/dist/device/meterplus.js +56 -54
  51. package/dist/device/meterplus.js.map +1 -1
  52. package/dist/device/motion.d.ts +2 -0
  53. package/dist/device/motion.d.ts.map +1 -1
  54. package/dist/device/motion.js +46 -31
  55. package/dist/device/motion.js.map +1 -1
  56. package/dist/device/plug.d.ts +1 -0
  57. package/dist/device/plug.d.ts.map +1 -1
  58. package/dist/device/plug.js +9 -6
  59. package/dist/device/plug.js.map +1 -1
  60. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  61. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  62. package/dist/device/robotvacuumcleaner.js +26 -2
  63. package/dist/device/robotvacuumcleaner.js.map +1 -1
  64. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  65. package/dist/irdevice/airconditioner.js +7 -5
  66. package/dist/irdevice/airconditioner.js.map +1 -1
  67. package/dist/irdevice/airpurifier.d.ts +1 -1
  68. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  69. package/dist/irdevice/airpurifier.js +3 -3
  70. package/dist/irdevice/airpurifier.js.map +1 -1
  71. package/dist/irdevice/camera.d.ts +1 -1
  72. package/dist/irdevice/camera.d.ts.map +1 -1
  73. package/dist/irdevice/camera.js +3 -3
  74. package/dist/irdevice/camera.js.map +1 -1
  75. package/dist/irdevice/fan.d.ts +2 -2
  76. package/dist/irdevice/fan.d.ts.map +1 -1
  77. package/dist/irdevice/fan.js +3 -3
  78. package/dist/irdevice/fan.js.map +1 -1
  79. package/dist/irdevice/light.d.ts +1 -1
  80. package/dist/irdevice/light.d.ts.map +1 -1
  81. package/dist/irdevice/light.js +3 -3
  82. package/dist/irdevice/light.js.map +1 -1
  83. package/dist/irdevice/other.d.ts +1 -1
  84. package/dist/irdevice/other.d.ts.map +1 -1
  85. package/dist/irdevice/other.js +3 -3
  86. package/dist/irdevice/other.js.map +1 -1
  87. package/dist/irdevice/tv.d.ts +2 -2
  88. package/dist/irdevice/tv.d.ts.map +1 -1
  89. package/dist/irdevice/tv.js +3 -3
  90. package/dist/irdevice/tv.js.map +1 -1
  91. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  92. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  93. package/dist/irdevice/vacuumcleaner.js +3 -3
  94. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  95. package/dist/irdevice/waterheater.d.ts +1 -1
  96. package/dist/irdevice/waterheater.d.ts.map +1 -1
  97. package/dist/irdevice/waterheater.js +3 -3
  98. package/dist/irdevice/waterheater.js.map +1 -1
  99. package/dist/platform.d.ts.map +1 -1
  100. package/dist/platform.js +3 -2
  101. package/dist/platform.js.map +1 -1
  102. package/package.json +3 -3
  103. package/src/device/blindtilt.ts +8 -6
  104. package/src/device/bot.ts +8 -5
  105. package/src/device/ceilinglight.ts +12 -6
  106. package/src/device/colorbulb.ts +10 -5
  107. package/src/device/contact.ts +44 -30
  108. package/src/device/curtain.ts +30 -33
  109. package/src/device/hub.ts +30 -4
  110. package/src/device/humidifier.ts +8 -5
  111. package/src/device/iosensor.ts +9 -5
  112. package/src/device/lightstrip.ts +10 -5
  113. package/src/device/lock.ts +12 -5
  114. package/src/device/meter.ts +12 -7
  115. package/src/device/meterplus.ts +60 -53
  116. package/src/device/motion.ts +45 -27
  117. package/src/device/plug.ts +8 -5
  118. package/src/device/robotvacuumcleaner.ts +29 -2
  119. package/src/irdevice/airconditioner.ts +7 -5
  120. package/src/irdevice/airpurifier.ts +5 -5
  121. package/src/irdevice/camera.ts +5 -5
  122. package/src/irdevice/fan.ts +5 -5
  123. package/src/irdevice/light.ts +5 -5
  124. package/src/irdevice/other.ts +5 -5
  125. package/src/irdevice/tv.ts +5 -5
  126. package/src/irdevice/vacuumcleaner.ts +5 -5
  127. package/src/irdevice/waterheater.ts +5 -5
  128. package/src/platform.ts +3 -2
  129. package/src/settings.ts +1 -1
@@ -1,14 +1,14 @@
1
- import { Context } from 'vm';
2
- import { hostname } from 'os';
3
- import { request } from 'undici';
4
- import { sleep } from '../utils';
5
- import { MqttClient } from 'mqtt';
6
- import { interval, Subject } from 'rxjs';
7
1
  import { connectAsync } from 'async-mqtt';
2
+ import { CharacteristicValue, PlatformAccessory, Service, Units } from 'homebridge';
3
+ import { MqttClient } from 'mqtt';
4
+ import { hostname } from 'os';
5
+ import { Subject, interval } from 'rxjs';
8
6
  import { skipWhile } from 'rxjs/operators';
7
+ import { request } from 'undici';
8
+ import { Context } from 'vm';
9
9
  import { SwitchBotPlatform } from '../platform';
10
- import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
11
- import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, Devices } from '../settings';
10
+ import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, switchbot, temperature } from '../settings';
11
+ import { sleep } from '../utils';
12
12
 
13
13
  /**
14
14
  * Platform Accessory
@@ -29,6 +29,7 @@ export class MeterPlus {
29
29
  StatusLowBattery?: CharacteristicValue;
30
30
 
31
31
  // OpenAPI Others
32
+ Version: deviceStatus['version'];
32
33
  Battery: deviceStatus['battery'];
33
34
  Temperature: deviceStatus['temperature'];
34
35
  Humidity: deviceStatus['humidity'];
@@ -73,10 +74,10 @@ export class MeterPlus {
73
74
  this.logs(device);
74
75
  this.scan(device);
75
76
  this.refreshRate(device);
76
- this.config(device);
77
77
  this.context();
78
78
  this.setupHistoryService(device);
79
79
  this.setupMqtt(device);
80
+ this.config(device);
80
81
 
81
82
  // this is subject we use to track when we need to POST changes to the SwitchBot API
82
83
  this.doMeterUpdate = new Subject();
@@ -154,11 +155,7 @@ export class MeterPlus {
154
155
  }
155
156
 
156
157
  // Battery Service
157
- if (!this.BLE) {
158
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
159
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
160
- accessory.removeService(this.batteryService!);
161
- } else if (this.BLE && !this.batteryService) {
158
+ if (!this.batteryService) {
162
159
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
163
160
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
164
161
  `${accessory.displayName} Battery`;
@@ -229,6 +226,16 @@ export class MeterPlus {
229
226
 
230
227
  async openAPIparseStatus(): Promise<void> {
231
228
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
229
+
230
+ // Battery
231
+ this.BatteryLevel = Number(this.Battery);
232
+ if (this.BatteryLevel < 15) {
233
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
234
+ } else {
235
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
236
+ }
237
+ this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
238
+
232
239
  // Current Relative Humidity
233
240
  if (!this.device.meter?.hide_humidity) {
234
241
  this.CurrentRelativeHumidity = this.Humidity!;
@@ -345,6 +352,7 @@ export class MeterPlus {
345
352
  this.Humidity = deviceStatus.body.humidity!;
346
353
  this.Temperature = deviceStatus.body.temperature!;
347
354
  this.Battery = deviceStatus.body.battery!;
355
+ this.Version = deviceStatus.body.version!;
348
356
  this.openAPIparseStatus();
349
357
  this.updateHomeKitCharacteristics();
350
358
  } catch (e: any) {
@@ -395,28 +403,29 @@ export class MeterPlus {
395
403
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
396
404
  }
397
405
  }
398
- if (this.BLE) {
399
- if (this.BatteryLevel === undefined) {
400
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
401
- } else {
402
- if (this.device.mqttURL) {
403
- mqttmessage.push(`"battery": ${this.BatteryLevel}`);
404
- }
405
- this.accessory.context.BatteryLevel = this.BatteryLevel;
406
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
407
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
406
+
407
+ if (this.BatteryLevel === undefined) {
408
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
409
+ } else {
410
+ if (this.device.mqttURL) {
411
+ mqttmessage.push(`"battery": ${this.BatteryLevel}`);
408
412
  }
409
- if (this.StatusLowBattery === undefined) {
410
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
411
- } else {
412
- if (this.device.mqttURL) {
413
- mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
414
- }
415
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
416
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
417
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
413
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
414
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
415
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
416
+ }
417
+
418
+ if (this.StatusLowBattery === undefined) {
419
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
420
+ } else {
421
+ if (this.device.mqttURL) {
422
+ mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
418
423
  }
424
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
425
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
426
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
419
427
  }
428
+
420
429
  if (this.device.mqttURL) {
421
430
  this.mqttPublish(`{${mqttmessage.join(',')}}`);
422
431
  }
@@ -593,10 +602,8 @@ export class MeterPlus {
593
602
  if (!this.device.meter?.hide_temperature) {
594
603
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
595
604
  }
596
- if (this.BLE) {
597
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
598
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
599
- }
605
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
606
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
600
607
  }
601
608
 
602
609
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
@@ -606,10 +613,12 @@ export class MeterPlus {
606
613
  );
607
614
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
608
615
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
609
- if (accessory.context.FirmwareRevision) {
610
- FirmwareRevision = accessory.context.FirmwareRevision;
611
- } else if (device.firmware) {
616
+ if (device.firmware) {
612
617
  FirmwareRevision = device.firmware;
618
+ } else if (device.version) {
619
+ FirmwareRevision = JSON.stringify(device.version);
620
+ } else if (accessory.context.FirmwareRevision) {
621
+ FirmwareRevision = accessory.context.FirmwareRevision;
613
622
  } else {
614
623
  FirmwareRevision = this.platform.version;
615
624
  }
@@ -627,18 +636,16 @@ export class MeterPlus {
627
636
  } else {
628
637
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
629
638
  }
630
- if (this.BLE) {
631
- if (this.BatteryLevel === undefined) {
632
- this.BatteryLevel = 100;
633
- } else {
634
- this.BatteryLevel = this.accessory.context.BatteryLevel;
635
- }
636
- if (this.StatusLowBattery === undefined) {
637
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
638
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
639
- } else {
640
- this.StatusLowBattery = this.accessory.context.StatusLowBattery;
641
- }
639
+ if (this.BatteryLevel === undefined) {
640
+ this.BatteryLevel = 100;
641
+ } else {
642
+ this.BatteryLevel = this.accessory.context.BatteryLevel;
643
+ }
644
+ if (this.StatusLowBattery === undefined) {
645
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
646
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
647
+ } else {
648
+ this.StatusLowBattery = this.accessory.context.StatusLowBattery;
642
649
  }
643
650
  }
644
651
 
@@ -676,7 +683,7 @@ export class MeterPlus {
676
683
  config['scanDuration'] = device.scanDuration;
677
684
  }
678
685
  if (Object.entries(config).length !== 0) {
679
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
686
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
680
687
  }
681
688
  }
682
689
 
@@ -25,6 +25,8 @@ export class Motion {
25
25
  StatusLowBattery?: CharacteristicValue;
26
26
 
27
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
29
+ Battery: deviceStatus['battery'];
28
30
  deviceStatus!: any; //deviceStatusResponse;
29
31
  moveDetected: deviceStatus['moveDetected'];
30
32
  brightness: deviceStatus['brightness'];
@@ -68,8 +70,8 @@ export class Motion {
68
70
  this.logs(device);
69
71
  this.scan(device);
70
72
  this.refreshRate(device);
71
- this.config(device);
72
73
  this.context();
74
+ this.config(device);
73
75
 
74
76
  // this is subject we use to track when we need to POST changes to the SwitchBot API
75
77
  this.doMotionUpdate = new Subject();
@@ -124,17 +126,16 @@ export class Motion {
124
126
  }
125
127
 
126
128
  // Battery Service
127
- if (!this.BLE) {
128
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
129
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
130
- accessory.removeService(this.batteryService!);
131
- } else if (this.BLE && !this.batteryService) {
129
+ if (!this.batteryService) {
132
130
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
133
131
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
134
132
  `${accessory.displayName} Battery`;
135
133
 
136
134
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
137
- this.batteryService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
135
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
136
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
137
+ }
138
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
138
139
  } else {
139
140
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
140
141
  }
@@ -230,6 +231,19 @@ export class Motion {
230
231
  }
231
232
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
232
233
  }
234
+ // Battery
235
+ if (this.battery === undefined) {
236
+ this.battery = 100;
237
+ }
238
+ this.BatteryLevel = this.Battery!;
239
+ if (this.BatteryLevel < 10) {
240
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
241
+ } else {
242
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
243
+ }
244
+ this.debugLog(
245
+ `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
246
+ );
233
247
  }
234
248
 
235
249
  /**
@@ -350,6 +364,8 @@ export class Motion {
350
364
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
351
365
  this.moveDetected = deviceStatus.body.moveDetected;
352
366
  this.brightness = deviceStatus.body.brightness;
367
+ this.Battery = deviceStatus.body.battery!;
368
+ this.Version = deviceStatus.body.version!;
353
369
  this.openAPIparseStatus();
354
370
  this.updateHomeKitCharacteristics();
355
371
  } catch (e: any) {
@@ -372,21 +388,21 @@ export class Motion {
372
388
  this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
373
389
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
374
390
  }
391
+ if (this.BatteryLevel === undefined) {
392
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
393
+ } else {
394
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
395
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
396
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
397
+ }
398
+ if (this.StatusLowBattery === undefined) {
399
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
400
+ } else {
401
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
402
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
403
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
404
+ }
375
405
  if (this.BLE) {
376
- if (this.BatteryLevel === undefined) {
377
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
378
- } else {
379
- this.accessory.context.BatteryLevel = this.BatteryLevel;
380
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
381
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
382
- }
383
- if (this.StatusLowBattery === undefined) {
384
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
385
- } else {
386
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
387
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
388
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
389
- }
390
406
  if (this.CurrentAmbientLightLevel === undefined) {
391
407
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
392
408
  } else {
@@ -539,9 +555,9 @@ export class Motion {
539
555
 
540
556
  async apiError(e: any): Promise<void> {
541
557
  this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
558
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
559
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
542
560
  if (this.BLE) {
543
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
544
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
545
561
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
546
562
  }
547
563
  }
@@ -553,10 +569,12 @@ export class Motion {
553
569
  );
554
570
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
555
571
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
556
- if (accessory.context.FirmwareRevision) {
557
- FirmwareRevision = accessory.context.FirmwareRevision;
558
- } else if (device.firmware) {
572
+ if (device.firmware) {
559
573
  FirmwareRevision = device.firmware;
574
+ } else if (device.version) {
575
+ FirmwareRevision = JSON.stringify(device.version);
576
+ } else if (accessory.context.FirmwareRevision) {
577
+ FirmwareRevision = accessory.context.FirmwareRevision;
560
578
  } else {
561
579
  FirmwareRevision = this.platform.version;
562
580
  }
@@ -605,7 +623,7 @@ export class Motion {
605
623
  config['offline'] = device.offline;
606
624
  }
607
625
  if (Object.entries(config).length !== 0) {
608
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
626
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
609
627
  }
610
628
  }
611
629
 
@@ -15,6 +15,7 @@ export class Plug {
15
15
  On!: CharacteristicValue;
16
16
 
17
17
  // OpenAPI Others
18
+ Version: deviceStatus['version'];
18
19
  power: deviceStatus['power'];
19
20
  deviceStatus!: any; //deviceStatusResponse;
20
21
 
@@ -53,8 +54,8 @@ export class Plug {
53
54
  this.logs(device);
54
55
  this.scan(device);
55
56
  this.refreshRate(device);
56
- this.config(device);
57
57
  this.context();
58
+ this.config(device);
58
59
 
59
60
  // this is subject we use to track when we need to POST changes to the SwitchBot API
60
61
  this.doPlugUpdate = new Subject();
@@ -583,10 +584,12 @@ export class Plug {
583
584
  );
584
585
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
585
586
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
586
- if (accessory.context.FirmwareRevision) {
587
- FirmwareRevision = accessory.context.FirmwareRevision;
588
- } else if (device.firmware) {
587
+ if (device.firmware) {
589
588
  FirmwareRevision = device.firmware;
589
+ } else if (device.version) {
590
+ FirmwareRevision = JSON.stringify(device.version);
591
+ } else if (accessory.context.FirmwareRevision) {
592
+ FirmwareRevision = accessory.context.FirmwareRevision;
590
593
  } else {
591
594
  FirmwareRevision = this.platform.version;
592
595
  }
@@ -638,7 +641,7 @@ export class Plug {
638
641
  config['maxRetry'] = device.maxRetry;
639
642
  }
640
643
  if (Object.entries(config).length !== 0) {
641
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
644
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
642
645
  }
643
646
  }
644
647
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable brace-style */
1
2
  import { Context } from 'vm';
2
3
  import { request } from 'undici';
3
4
  import { sleep } from '../utils';
@@ -19,6 +20,7 @@ export class RobotVacuumCleaner {
19
20
  StatusLowBattery?: CharacteristicValue;
20
21
 
21
22
  // OpenAPI Others
23
+ Battery: deviceStatus['battery'];
22
24
  power: deviceStatus['power'];
23
25
  deviceStatus!: any; //deviceStatusResponse;
24
26
 
@@ -51,8 +53,8 @@ export class RobotVacuumCleaner {
51
53
  this.logs(device);
52
54
  this.scan(device);
53
55
  this.refreshRate(device);
54
- this.config(device);
55
56
  this.context();
57
+ this.config(device);
56
58
 
57
59
  // this is subject we use to track when we need to POST changes to the SwitchBot API
58
60
  this.doRobotVacuumCleanerUpdate = new Subject();
@@ -107,6 +109,21 @@ export class RobotVacuumCleaner {
107
109
  })
108
110
  .onSet(this.BrightnessSet.bind(this));
109
111
 
112
+ // Battery Service
113
+ if (!this.batteryService) {
114
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
115
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
116
+ `${accessory.displayName} Battery`;
117
+
118
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
119
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
120
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
121
+ }
122
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
123
+ } else {
124
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
125
+ }
126
+
110
127
  // Update Homekit
111
128
  this.updateHomeKitCharacteristics();
112
129
 
@@ -186,6 +203,15 @@ export class RobotVacuumCleaner {
186
203
  this.On = false;
187
204
  }
188
205
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
206
+
207
+ // Battery
208
+ this.BatteryLevel = Number(this.Battery);
209
+ if (this.BatteryLevel < 15) {
210
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
211
+ } else {
212
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
213
+ }
214
+ this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
189
215
  }
190
216
 
191
217
  /**
@@ -282,6 +308,7 @@ export class RobotVacuumCleaner {
282
308
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
283
309
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
284
310
  this.power = deviceStatus.body.power;
311
+ this.Battery = deviceStatus.body.battery;
285
312
  this.openAPIparseStatus();
286
313
  this.updateHomeKitCharacteristics();
287
314
  } catch (e: any) {
@@ -758,7 +785,7 @@ export class RobotVacuumCleaner {
758
785
  config['maxRetry'] = device.maxRetry;
759
786
  }
760
787
  if (Object.entries(config).length !== 0) {
761
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
788
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
762
789
  }
763
790
  }
764
791
 
@@ -50,11 +50,11 @@ export class AirConditioner {
50
50
  ) {
51
51
  // default placeholders
52
52
  this.logs({ device });
53
- this.config({ device });
54
53
  this.context();
55
54
  this.disablePushOnChanges({ device });
56
55
  this.disablePushOffChanges({ device });
57
56
  this.disablePushDetailChanges({ device });
57
+ this.config({ device });
58
58
 
59
59
  // set accessory information
60
60
  accessory
@@ -252,7 +252,7 @@ export class AirConditioner {
252
252
  async pushChanges(bodyChange: any): Promise<void> {
253
253
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
254
254
  if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
255
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
255
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
256
256
  try {
257
257
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
258
258
  body: bodyChange,
@@ -291,7 +291,8 @@ export class AirConditioner {
291
291
  this.meter.getService(this.platform.Service.TemperatureSensor)?.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value ||
292
292
  24;
293
293
  this.debugLog(
294
- `${this.device.remoteType}: ${this.accessory.displayName} Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
294
+ `${this.device.remoteType}: ${this.accessory.displayName} `
295
+ + `Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
295
296
  );
296
297
  } else if (this.CurrentTemperature === undefined) {
297
298
  this.CurrentTemperature = 24;
@@ -309,7 +310,8 @@ export class AirConditioner {
309
310
  this.meter.getService(this.platform.Service.HumiditySensor)?.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value ||
310
311
  0;
311
312
  this.debugLog(
312
- `${this.device.remoteType}: ${this.accessory.displayName} Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
313
+ `${this.device.remoteType}: ${this.accessory.displayName} `
314
+ + `Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
313
315
  );
314
316
  } else if (this.CurrentRelativeHumidity === undefined) {
315
317
  this.CurrentRelativeHumidity = 0;
@@ -715,7 +717,7 @@ export class AirConditioner {
715
717
  config['disablePushDetail'] = device.disablePushDetail;
716
718
  }
717
719
  if (Object.entries(config).length !== 0) {
718
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
720
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
719
721
  }
720
722
  }
721
723
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -45,10 +45,10 @@ export class AirPurifier {
45
45
  ) {
46
46
  // default placeholders
47
47
  this.logs(device);
48
- this.config(device);
49
48
  this.context();
50
49
  this.disablePushOnChanges({ device });
51
50
  this.disablePushOffChanges({ device });
51
+ this.config(device);
52
52
 
53
53
  // set accessory information
54
54
  accessory
@@ -211,7 +211,7 @@ export class AirPurifier {
211
211
  async pushChanges(bodyChange: any): Promise<void> {
212
212
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
213
213
  if (this.device.connectionType === 'OpenAPI') {
214
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
214
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
215
215
  try {
216
216
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
217
217
  body: bodyChange,
@@ -420,7 +420,7 @@ export class AirPurifier {
420
420
  config['disablePushOff'] = device.disablePushOff;
421
421
  }
422
422
  if (Object.entries(config).length !== 0) {
423
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
423
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
424
424
  }
425
425
  }
426
426
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -27,10 +27,10 @@ export class Camera {
27
27
  ) {
28
28
  // default placeholders
29
29
  this.logs(device);
30
- this.config(device);
31
30
  this.context();
32
31
  this.disablePushOnChanges({ device });
33
32
  this.disablePushOffChanges({ device });
33
+ this.config(device);
34
34
 
35
35
  // set accessory information
36
36
  accessory
@@ -116,7 +116,7 @@ export class Camera {
116
116
  async pushChanges(bodyChange: any): Promise<void> {
117
117
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
118
118
  if (this.device.connectionType === 'OpenAPI') {
119
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
119
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
120
120
  try {
121
121
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
122
122
  body: bodyChange,
@@ -298,7 +298,7 @@ export class Camera {
298
298
  config['disablePushOff'] = device.disablePushOff;
299
299
  }
300
300
  if (Object.entries(config).length !== 0) {
301
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
301
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
302
302
  }
303
303
  }
304
304
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
- import { irdevice, irDevicesConfig, Devices } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -37,10 +37,10 @@ export class Fan {
37
37
  ) {
38
38
  // default placeholders
39
39
  this.logs(device);
40
- this.config(device);
41
40
  this.context();
42
41
  this.disablePushOnChanges({ device });
43
42
  this.disablePushOffChanges({ device });
43
+ this.config(device);
44
44
 
45
45
  // set accessory information
46
46
  accessory
@@ -236,7 +236,7 @@ export class Fan {
236
236
  async pushChanges(bodyChange: any): Promise<void> {
237
237
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
238
238
  if (this.device.connectionType === 'OpenAPI') {
239
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
239
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
240
240
  try {
241
241
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
242
242
  body: bodyChange,
@@ -434,7 +434,7 @@ export class Fan {
434
434
  config['disablePushOff'] = device.disablePushOff;
435
435
  }
436
436
  if (Object.entries(config).length !== 0) {
437
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
437
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
438
438
  }
439
439
  }
440
440
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -27,10 +27,10 @@ export class Light {
27
27
  ) {
28
28
  // default placeholders
29
29
  this.logs(device);
30
- this.config(device);
31
30
  this.context();
32
31
  this.disablePushOnChanges({ device });
33
32
  this.disablePushOffChanges({ device });
33
+ this.config(device);
34
34
 
35
35
  // set accessory information
36
36
  accessory
@@ -140,7 +140,7 @@ export class Light {
140
140
  async pushChanges(bodyChange: any): Promise<void> {
141
141
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
142
142
  if (this.device.connectionType === 'OpenAPI') {
143
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
143
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
144
144
  try {
145
145
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
146
146
  body: bodyChange,
@@ -323,7 +323,7 @@ export class Light {
323
323
  config['disablePushOff'] = device.disablePushOff;
324
324
  }
325
325
  if (Object.entries(config).length !== 0) {
326
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
326
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
327
327
  }
328
328
  }
329
329