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

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 +2 -0
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +53 -44
  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 +33 -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 +2 -0
  61. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  62. package/dist/device/robotvacuumcleaner.js +27 -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 +53 -41
  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 +32 -33
  109. package/src/device/hub.ts +30 -4
  110. package/src/device/humidifier.ts +8 -5
  111. package/src/device/iosensor.ts +10 -6
  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 +61 -54
  116. package/src/device/motion.ts +45 -27
  117. package/src/device/plug.ts +8 -5
  118. package/src/device/robotvacuumcleaner.ts +31 -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
package/src/device/bot.ts CHANGED
@@ -32,6 +32,8 @@ export class Bot {
32
32
  StatusLowBattery!: CharacteristicValue;
33
33
 
34
34
  // OpenAPI Others
35
+ Version: deviceStatus['version'];
36
+ Battery: deviceStatus['battery'];
35
37
  power: deviceStatus['power'];
36
38
  deviceStatus!: any; //deviceStatusResponse;
37
39
 
@@ -74,9 +76,9 @@ export class Bot {
74
76
  this.refreshRate(device);
75
77
  this.PressOrSwitch(device);
76
78
  this.allowPushChanges(device);
77
- this.config(device);
78
79
  this.context();
79
80
  this.DoublePress(device);
81
+ this.config(device);
80
82
 
81
83
  this.multiPressCount = 0;
82
84
 
@@ -113,7 +115,7 @@ export class Bot {
113
115
  // Add switchService
114
116
  (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
115
117
  `${accessory.displayName} Switch`;
116
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
118
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
117
119
 
118
120
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
119
121
  if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -135,7 +137,7 @@ export class Bot {
135
137
  (this.garageDoorService =
136
138
  accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
137
139
  `${accessory.displayName} Garage Door Opener`;
138
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
140
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
139
141
 
140
142
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
141
143
  if (!this.garageDoorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -157,7 +159,7 @@ export class Bot {
157
159
  // Add switchService
158
160
  (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
159
161
  `${accessory.displayName} Door`;
160
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
162
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
161
163
 
162
164
  this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
163
165
  if (!this.doorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -187,7 +189,7 @@ export class Bot {
187
189
  // Add switchService
188
190
  (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
189
191
  `${accessory.displayName} Window`;
190
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
192
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
191
193
 
192
194
  this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
193
195
  if (!this.windowService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -218,7 +220,7 @@ export class Bot {
218
220
  (this.windowCoveringService =
219
221
  accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
220
222
  `${accessory.displayName} Window Covering`;
221
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
223
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
222
224
 
223
225
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
224
226
  if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -248,7 +250,7 @@ export class Bot {
248
250
  // Add switchService
249
251
  (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
250
252
  `${accessory.displayName} Lock`;
251
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
253
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
252
254
 
253
255
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
254
256
  if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -269,7 +271,7 @@ export class Bot {
269
271
  // Add switchService
270
272
  (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
271
273
  `${accessory.displayName} Faucet`;
272
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
274
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
273
275
 
274
276
  this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
275
277
  if (!this.faucetService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -290,7 +292,7 @@ export class Bot {
290
292
  // Add switchService
291
293
  (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
292
294
  `${accessory.displayName} Fan`;
293
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
295
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
294
296
 
295
297
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
296
298
  if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -313,7 +315,7 @@ export class Bot {
313
315
  accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
314
316
  accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
315
317
  `${accessory.displayName} Stateful Programmable Switch`;
316
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
318
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
317
319
 
318
320
  this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
319
321
  if (!this.statefulProgrammableSwitchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -336,7 +338,7 @@ export class Bot {
336
338
  // Add outletService
337
339
  (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
338
340
  `${accessory.displayName} Outlet`;
339
- this.infoLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
341
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
340
342
 
341
343
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
342
344
  if (!this.outletService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -346,19 +348,16 @@ export class Bot {
346
348
  }
347
349
 
348
350
  // Battery Service
349
- if (!this.BLE) {
350
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
351
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
352
- accessory.removeService(this.batteryService!);
353
- } else if (this.BLE && !this.batteryService) {
351
+ if (!this.batteryService) {
354
352
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
355
353
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
356
354
  `${accessory.displayName} Battery`;
357
355
 
358
356
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
359
357
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
360
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
358
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
361
359
  }
360
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
362
361
  } else {
363
362
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
364
363
  }
@@ -461,6 +460,18 @@ export class Bot {
461
460
  }
462
461
  }
463
462
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
463
+
464
+ // Battery
465
+ this.BatteryLevel = Number(this.Battery);
466
+ if (this.BatteryLevel < 10) {
467
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
468
+ } else {
469
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
470
+ }
471
+ if (Number.isNaN(this.BatteryLevel)) {
472
+ this.BatteryLevel = 100;
473
+ }
474
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
464
475
  }
465
476
 
466
477
  /**
@@ -558,6 +569,8 @@ export class Bot {
558
569
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
559
570
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
560
571
  this.power = deviceStatus.body.power;
572
+ this.Battery = deviceStatus.body.battery;
573
+ this.Version = deviceStatus.body.version;
561
574
  this.openAPIparseStatus();
562
575
  this.updateHomeKitCharacteristics();
563
576
  } catch (e: any) {
@@ -985,23 +998,22 @@ export class Bot {
985
998
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
986
999
  }
987
1000
  }
988
- this.accessory.context.On = this.On;
989
- if (this.BLE) {
990
- if (this.BatteryLevel === undefined) {
991
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
992
- } else {
993
- this.accessory.context.BatteryLevel = this.BatteryLevel;
994
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
995
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
996
- }
997
- if (this.StatusLowBattery === undefined) {
998
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
999
- } else {
1000
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
1001
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
1002
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1003
- }
1001
+ if (this.BatteryLevel === undefined) {
1002
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
1003
+ } else {
1004
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
1005
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
1006
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
1007
+ }
1008
+ if (this.StatusLowBattery === undefined) {
1009
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
1010
+ } else {
1011
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
1012
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
1013
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1004
1014
  }
1015
+
1016
+ this.accessory.context.On = this.On;
1005
1017
  }
1006
1018
 
1007
1019
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
@@ -1289,10 +1301,8 @@ export class Bot {
1289
1301
  } else {
1290
1302
  this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
1291
1303
  }
1292
- if (this.BLE) {
1293
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1294
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1295
- }
1304
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1305
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1296
1306
  }
1297
1307
 
1298
1308
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
@@ -1302,10 +1312,12 @@ export class Bot {
1302
1312
  );
1303
1313
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1304
1314
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1305
- if (accessory.context.FirmwareRevision) {
1306
- FirmwareRevision = accessory.context.FirmwareRevision;
1307
- } else if (device.firmware) {
1315
+ if (device.firmware) {
1308
1316
  FirmwareRevision = device.firmware;
1317
+ } else if (device.version) {
1318
+ FirmwareRevision = JSON.stringify(device.version);
1319
+ } if (accessory.context.FirmwareRevision) {
1320
+ FirmwareRevision = accessory.context.FirmwareRevision;
1309
1321
  } else {
1310
1322
  FirmwareRevision = this.platform.version;
1311
1323
  }
@@ -1377,7 +1389,7 @@ export class Bot {
1377
1389
  config['maxRetry'] = device.maxRetry;
1378
1390
  }
1379
1391
  if (Object.entries(config).length !== 0) {
1380
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1392
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1381
1393
  }
1382
1394
  }
1383
1395
 
@@ -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';
@@ -24,6 +25,7 @@ export class CeilingLight {
24
25
  ColorTemperature?: CharacteristicValue;
25
26
 
26
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
27
29
  power: deviceStatus['power'];
28
30
  color: deviceStatus['color'];
29
31
  brightness: deviceStatus['brightness'];
@@ -72,8 +74,9 @@ export class CeilingLight {
72
74
  this.scan(device);
73
75
  this.refreshRate(device);
74
76
  this.adaptiveLighting(device);
75
- this.config(device);
76
77
  this.context();
78
+ this.config(device);
79
+
77
80
  // this is subject we use to track when we need to POST changes to the SwitchBot API
78
81
  this.doCeilingLightUpdate = new Subject();
79
82
  this.ceilingLightUpdateInProgress = false;
@@ -233,7 +236,8 @@ export class CeilingLight {
233
236
  async parseStatus(): Promise<void> {
234
237
  if (!this.device.enableCloudService && this.OpenAPI) {
235
238
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
236
- } /*if (this.BLE) {
239
+ }
240
+ /*if (this.BLE) {
237
241
  await this.BLEparseStatus();
238
242
  } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
239
243
  await this.openAPIparseStatus();
@@ -961,10 +965,12 @@ export class CeilingLight {
961
965
  );
962
966
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
963
967
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
964
- if (accessory.context.FirmwareRevision) {
965
- FirmwareRevision = accessory.context.FirmwareRevision;
966
- } else if (device.firmware) {
968
+ if (device.firmware) {
967
969
  FirmwareRevision = device.firmware;
970
+ } else if (device.version) {
971
+ FirmwareRevision = JSON.stringify(device.version);
972
+ } else if (accessory.context.FirmwareRevision) {
973
+ FirmwareRevision = accessory.context.FirmwareRevision;
968
974
  } else {
969
975
  FirmwareRevision = this.platform.version;
970
976
  }
@@ -1038,7 +1044,7 @@ export class CeilingLight {
1038
1044
  config['maxRetry'] = device.maxRetry;
1039
1045
  }
1040
1046
  if (Object.entries(config).length !== 0) {
1041
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1047
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1042
1048
  }
1043
1049
  }
1044
1050
 
@@ -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';
@@ -24,6 +25,7 @@ export class ColorBulb {
24
25
  ColorTemperature?: CharacteristicValue;
25
26
 
26
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
27
29
  power: deviceStatus['power'];
28
30
  color: deviceStatus['color'];
29
31
  brightness: deviceStatus['brightness'];
@@ -82,8 +84,9 @@ export class ColorBulb {
82
84
  this.scan(device);
83
85
  this.refreshRate(device);
84
86
  this.adaptiveLighting(device);
85
- this.config(device);
86
87
  this.context();
88
+ this.config(device);
89
+
87
90
  // this is subject we use to track when we need to POST changes to the SwitchBot API
88
91
  this.doColorBulbUpdate = new Subject();
89
92
  this.colorBulbUpdateInProgress = false;
@@ -1133,10 +1136,12 @@ export class ColorBulb {
1133
1136
  );
1134
1137
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1135
1138
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1136
- if (accessory.context.FirmwareRevision) {
1137
- FirmwareRevision = accessory.context.FirmwareRevision;
1138
- } else if (device.firmware) {
1139
+ if (device.firmware) {
1139
1140
  FirmwareRevision = device.firmware;
1141
+ } else if (device.version) {
1142
+ FirmwareRevision = JSON.stringify(device.version);
1143
+ } if (accessory.context.FirmwareRevision) {
1144
+ FirmwareRevision = accessory.context.FirmwareRevision;
1140
1145
  } else {
1141
1146
  FirmwareRevision = this.platform.version;
1142
1147
  }
@@ -1210,7 +1215,7 @@ export class ColorBulb {
1210
1215
  config['maxRetry'] = device.maxRetry;
1211
1216
  }
1212
1217
  if (Object.entries(config).length !== 0) {
1213
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1218
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1214
1219
  }
1215
1220
  }
1216
1221
 
@@ -27,6 +27,8 @@ export class Contact {
27
27
  StatusLowBattery!: CharacteristicValue;
28
28
 
29
29
  // OpenAPI others
30
+ Version: deviceStatus['version'];
31
+ Battery: deviceStatus['battery'];
30
32
  openState: deviceStatus['openState'];
31
33
  moveDetected: deviceStatus['moveDetected'];
32
34
  brightness: deviceStatus['brightness'];
@@ -71,8 +73,8 @@ export class Contact {
71
73
  this.logs(device);
72
74
  this.scan(device);
73
75
  this.refreshRate(device);
74
- this.config(device);
75
76
  this.context();
77
+ this.config(device);
76
78
 
77
79
  // this is subject we use to track when we need to POST changes to the SwitchBot API
78
80
  this.doContactUpdate = new Subject();
@@ -145,17 +147,16 @@ export class Contact {
145
147
  }
146
148
 
147
149
  // Battery Service
148
- if (!this.BLE) {
149
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
150
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
151
- accessory.removeService(this.batteryService!);
152
- } else if (this.BLE && !this.batteryService) {
150
+ if (!this.batteryService) {
153
151
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
154
152
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
155
153
  `${accessory.displayName} Battery`;
156
154
 
157
155
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
158
- this.batteryService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
156
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
157
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
158
+ }
159
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
159
160
  } else {
160
161
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
161
162
  }
@@ -284,6 +285,19 @@ export class Contact {
284
285
  }
285
286
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
286
287
  }
288
+ // Battery
289
+ if (this.battery === undefined) {
290
+ this.battery === 100;
291
+ }
292
+ this.BatteryLevel = Number(this.Battery);
293
+ if (this.BatteryLevel < 10) {
294
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
295
+ } else {
296
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
297
+ }
298
+ this.debugLog(
299
+ `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
300
+ );
287
301
  }
288
302
 
289
303
  /**
@@ -394,6 +408,8 @@ export class Contact {
394
408
  this.openState = deviceStatus.body.openState;
395
409
  this.moveDetected = deviceStatus.body.moveDetected;
396
410
  this.brightness = deviceStatus.body.brightness;
411
+ this.Battery = deviceStatus.body.battery;
412
+ this.Version = deviceStatus.body.version;
397
413
  this.openAPIparseStatus();
398
414
  this.updateHomeKitCharacteristics();
399
415
  } catch (e: any) {
@@ -437,21 +453,19 @@ export class Contact {
437
453
  );
438
454
  }
439
455
  }
440
- if (this.BLE) {
441
- if (this.BatteryLevel === undefined) {
442
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
443
- } else {
444
- this.accessory.context.BatteryLevel = this.BatteryLevel;
445
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
446
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
447
- }
448
- if (this.StatusLowBattery === undefined) {
449
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
450
- } else {
451
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
452
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
453
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
454
- }
456
+ if (this.BatteryLevel === undefined) {
457
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
458
+ } else {
459
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
460
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
461
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
462
+ }
463
+ if (this.StatusLowBattery === undefined) {
464
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
465
+ } else {
466
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
467
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
468
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
455
469
  }
456
470
  }
457
471
 
@@ -580,10 +594,8 @@ export class Contact {
580
594
  if (!this.device.contact?.hide_lightsensor) {
581
595
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
582
596
  }
583
- if (this.BLE) {
584
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
585
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
586
- }
597
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
598
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
587
599
  }
588
600
 
589
601
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
@@ -593,10 +605,12 @@ export class Contact {
593
605
  );
594
606
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
595
607
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
596
- if (accessory.context.FirmwareRevision) {
597
- FirmwareRevision = accessory.context.FirmwareRevision;
598
- } else if (device.firmware) {
608
+ if (device.firmware) {
599
609
  FirmwareRevision = device.firmware;
610
+ } else if (device.version) {
611
+ FirmwareRevision = JSON.stringify(device.version);
612
+ } else if (accessory.context.FirmwareRevision) {
613
+ FirmwareRevision = accessory.context.FirmwareRevision;
600
614
  } else {
601
615
  FirmwareRevision = this.platform.version;
602
616
  }
@@ -647,7 +661,7 @@ export class Contact {
647
661
  config['scanDuration'] = device.scanDuration;
648
662
  }
649
663
  if (Object.entries(config).length !== 0) {
650
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
664
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
651
665
  }
652
666
  }
653
667
 
@@ -26,6 +26,8 @@ export class Curtain {
26
26
  lastActivation?: number;
27
27
 
28
28
  // OpenAPI Others
29
+ Version: deviceStatus['version'];
30
+ Battery: deviceStatus['battery'];
29
31
  deviceStatus!: any; //deviceStatusResponse;
30
32
  slidePosition: deviceStatus['slidePosition'];
31
33
  moving: deviceStatus['moving'];
@@ -83,9 +85,9 @@ export class Curtain {
83
85
  this.logs(device);
84
86
  this.refreshRate(device);
85
87
  this.scan(device);
86
- this.config(device);
87
88
  this.setupMqtt(device);
88
89
  this.context();
90
+ this.config(device);
89
91
 
90
92
  // this is subject we use to track when we need to POST changes to the SwitchBot API
91
93
  this.doCurtainUpdate = new Subject();
@@ -170,11 +172,7 @@ export class Curtain {
170
172
  }
171
173
 
172
174
  // Battery Service
173
- if (!this.BLE) {
174
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
175
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
176
- accessory.removeService(this.batteryService!);
177
- } else if (this.BLE && !this.batteryService) {
175
+ if (!this.batteryService) {
178
176
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
179
177
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
180
178
  `${accessory.displayName} Battery`;
@@ -183,6 +181,7 @@ export class Curtain {
183
181
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
184
182
  this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
185
183
  }
184
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
186
185
  } else {
187
186
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
188
187
  }
@@ -568,6 +567,8 @@ export class Curtain {
568
567
  this.slidePosition = deviceStatus.body.slidePosition;
569
568
  this.moving = deviceStatus.body.moving;
570
569
  this.brightness = deviceStatus.body.brightness;
570
+ this.Battery = deviceStatus.body.battery;
571
+ this.Version = deviceStatus.body.version;
571
572
  this.openAPIparseStatus();
572
573
  this.updateHomeKitCharacteristics();
573
574
  } catch (e: any) {
@@ -823,27 +824,25 @@ export class Curtain {
823
824
  }
824
825
  }
825
826
  }
826
- if (this.BLE) {
827
- if (this.BatteryLevel === undefined) {
828
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
829
- } else {
830
- if (this.device.mqttURL) {
831
- this.mqttPublish('BatteryLevel', this.BatteryLevel);
832
- }
833
- this.accessory.context.BatteryLevel = this.BatteryLevel;
834
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
835
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
827
+ if (this.BatteryLevel === undefined) {
828
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
829
+ } else {
830
+ if (this.device.mqttURL) {
831
+ this.mqttPublish('BatteryLevel', this.BatteryLevel);
836
832
  }
837
- if (this.StatusLowBattery === undefined) {
838
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
839
- } else {
840
- if (this.device.mqttURL) {
841
- this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
842
- }
843
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
844
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
845
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
833
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
834
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
835
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
836
+ }
837
+ if (this.StatusLowBattery === undefined) {
838
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
839
+ } else {
840
+ if (this.device.mqttURL) {
841
+ this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
846
842
  }
843
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
844
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
845
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
847
846
  }
848
847
  }
849
848
 
@@ -1071,10 +1070,8 @@ export class Curtain {
1071
1070
  if (!this.device.curtain?.hide_lightsensor) {
1072
1071
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
1073
1072
  }
1074
- if (this.BLE) {
1075
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1076
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1077
- }
1073
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1074
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1078
1075
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1079
1076
  }
1080
1077
 
@@ -1085,10 +1082,12 @@ export class Curtain {
1085
1082
  );
1086
1083
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1087
1084
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1088
- if (accessory.context.FirmwareRevision) {
1089
- FirmwareRevision = accessory.context.FirmwareRevision;
1090
- } else if (device.firmware) {
1085
+ if (device.firmware) {
1091
1086
  FirmwareRevision = device.firmware;
1087
+ } else if (device.version) {
1088
+ FirmwareRevision = JSON.stringify(device.version);
1089
+ } if (accessory.context.FirmwareRevision) {
1090
+ FirmwareRevision = accessory.context.FirmwareRevision;
1092
1091
  } else {
1093
1092
  FirmwareRevision = this.platform.version;
1094
1093
  }
@@ -1188,7 +1187,7 @@ export class Curtain {
1188
1187
  config['maxRetry'] = device.maxRetry;
1189
1188
  }
1190
1189
  if (Object.entries(config).length !== 0) {
1191
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1190
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1192
1191
  }
1193
1192
  }
1194
1193