@switchbot/homebridge-switchbot 2.8.0-beta.2 → 2.8.0-beta.20

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 (132) hide show
  1. package/CHANGELOG.md +4 -2
  2. package/README.md +1 -1
  3. package/dist/device/blindtilt.d.ts +1 -0
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +9 -6
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +2 -0
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +66 -52
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +1 -0
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +12 -9
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +1 -0
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +8 -5
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +2 -0
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +45 -34
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +2 -0
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +33 -36
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/hub.d.ts +3 -1
  28. package/dist/device/hub.d.ts.map +1 -1
  29. package/dist/device/hub.js +30 -5
  30. package/dist/device/hub.js.map +1 -1
  31. package/dist/device/humidifier.d.ts.map +1 -1
  32. package/dist/device/humidifier.js +9 -6
  33. package/dist/device/humidifier.js.map +1 -1
  34. package/dist/device/iosensor.d.ts +1 -0
  35. package/dist/device/iosensor.d.ts.map +1 -1
  36. package/dist/device/iosensor.js +10 -6
  37. package/dist/device/iosensor.js.map +1 -1
  38. package/dist/device/lightstrip.d.ts +1 -0
  39. package/dist/device/lightstrip.d.ts.map +1 -1
  40. package/dist/device/lightstrip.js +9 -6
  41. package/dist/device/lightstrip.js.map +1 -1
  42. package/dist/device/lock.d.ts +2 -0
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +11 -6
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts +2 -0
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +12 -8
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts +4 -3
  51. package/dist/device/meterplus.d.ts.map +1 -1
  52. package/dist/device/meterplus.js +56 -54
  53. package/dist/device/meterplus.js.map +1 -1
  54. package/dist/device/motion.d.ts +2 -0
  55. package/dist/device/motion.d.ts.map +1 -1
  56. package/dist/device/motion.js +46 -31
  57. package/dist/device/motion.js.map +1 -1
  58. package/dist/device/plug.d.ts +1 -0
  59. package/dist/device/plug.d.ts.map +1 -1
  60. package/dist/device/plug.js +9 -6
  61. package/dist/device/plug.js.map +1 -1
  62. package/dist/device/robotvacuumcleaner.d.ts +2 -0
  63. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  64. package/dist/device/robotvacuumcleaner.js +27 -2
  65. package/dist/device/robotvacuumcleaner.js.map +1 -1
  66. package/dist/irdevice/airconditioner.d.ts +2 -0
  67. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  68. package/dist/irdevice/airconditioner.js +71 -88
  69. package/dist/irdevice/airconditioner.js.map +1 -1
  70. package/dist/irdevice/airpurifier.d.ts +1 -1
  71. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  72. package/dist/irdevice/airpurifier.js +3 -3
  73. package/dist/irdevice/airpurifier.js.map +1 -1
  74. package/dist/irdevice/camera.d.ts +1 -1
  75. package/dist/irdevice/camera.d.ts.map +1 -1
  76. package/dist/irdevice/camera.js +3 -3
  77. package/dist/irdevice/camera.js.map +1 -1
  78. package/dist/irdevice/fan.d.ts +2 -2
  79. package/dist/irdevice/fan.d.ts.map +1 -1
  80. package/dist/irdevice/fan.js +3 -3
  81. package/dist/irdevice/fan.js.map +1 -1
  82. package/dist/irdevice/light.d.ts +1 -1
  83. package/dist/irdevice/light.d.ts.map +1 -1
  84. package/dist/irdevice/light.js +3 -3
  85. package/dist/irdevice/light.js.map +1 -1
  86. package/dist/irdevice/other.d.ts +1 -1
  87. package/dist/irdevice/other.d.ts.map +1 -1
  88. package/dist/irdevice/other.js +3 -3
  89. package/dist/irdevice/other.js.map +1 -1
  90. package/dist/irdevice/tv.d.ts +2 -2
  91. package/dist/irdevice/tv.d.ts.map +1 -1
  92. package/dist/irdevice/tv.js +3 -3
  93. package/dist/irdevice/tv.js.map +1 -1
  94. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  95. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  96. package/dist/irdevice/vacuumcleaner.js +3 -3
  97. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  98. package/dist/irdevice/waterheater.d.ts +1 -1
  99. package/dist/irdevice/waterheater.d.ts.map +1 -1
  100. package/dist/irdevice/waterheater.js +3 -3
  101. package/dist/irdevice/waterheater.js.map +1 -1
  102. package/dist/platform.d.ts.map +1 -1
  103. package/dist/platform.js +67 -65
  104. package/dist/platform.js.map +1 -1
  105. package/package.json +11 -11
  106. package/src/device/blindtilt.ts +10 -8
  107. package/src/device/bot.ts +66 -50
  108. package/src/device/ceilinglight.ts +17 -11
  109. package/src/device/colorbulb.ts +15 -10
  110. package/src/device/contact.ts +45 -31
  111. package/src/device/curtain.ts +34 -35
  112. package/src/device/hub.ts +32 -6
  113. package/src/device/humidifier.ts +12 -9
  114. package/src/device/iosensor.ts +11 -7
  115. package/src/device/lightstrip.ts +14 -9
  116. package/src/device/lock.ts +14 -7
  117. package/src/device/meter.ts +13 -8
  118. package/src/device/meterplus.ts +62 -55
  119. package/src/device/motion.ts +46 -28
  120. package/src/device/plug.ts +10 -7
  121. package/src/device/robotvacuumcleaner.ts +34 -5
  122. package/src/irdevice/airconditioner.ts +84 -96
  123. package/src/irdevice/airpurifier.ts +6 -6
  124. package/src/irdevice/camera.ts +6 -6
  125. package/src/irdevice/fan.ts +6 -6
  126. package/src/irdevice/light.ts +6 -6
  127. package/src/irdevice/other.ts +6 -6
  128. package/src/irdevice/tv.ts +6 -6
  129. package/src/irdevice/vacuumcleaner.ts +6 -6
  130. package/src/irdevice/waterheater.ts +6 -6
  131. package/src/platform.ts +76 -75
  132. 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
  /**
@@ -552,14 +563,20 @@ export class Bot {
552
563
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
553
564
  headers: this.platform.generateHeaders(),
554
565
  });
555
- const deviceStatus = await body.json();
556
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
557
- this.statusCode(statusCode);
558
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
559
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
560
- this.power = deviceStatus.body.power;
561
- this.openAPIparseStatus();
562
- this.updateHomeKitCharacteristics();
566
+ if (statusCode === 200) {
567
+ const deviceStatus: any = await body.json();
568
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
569
+ this.statusCode(statusCode);
570
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
571
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
572
+ this.power = deviceStatus.body.power;
573
+ this.Battery = deviceStatus.body.battery;
574
+ this.Version = deviceStatus.body.version;
575
+ this.openAPIparseStatus();
576
+ this.updateHomeKitCharacteristics();
577
+ } else {
578
+ this.statusCode(statusCode);
579
+ }
563
580
  } catch (e: any) {
564
581
  this.apiError(e);
565
582
  this.errorLog(
@@ -712,7 +729,7 @@ export class Bot {
712
729
  method: 'POST',
713
730
  headers: this.platform.generateHeaders(),
714
731
  });
715
- const deviceStatus = await body.json();
732
+ const deviceStatus: any = await body.json();
716
733
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
717
734
  this.statusCode(statusCode);
718
735
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -985,23 +1002,22 @@ export class Bot {
985
1002
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
986
1003
  }
987
1004
  }
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
- }
1005
+ if (this.BatteryLevel === undefined) {
1006
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
1007
+ } else {
1008
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
1009
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
1010
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
1004
1011
  }
1012
+ if (this.StatusLowBattery === undefined) {
1013
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
1014
+ } else {
1015
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
1016
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
1017
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1018
+ }
1019
+
1020
+ this.accessory.context.On = this.On;
1005
1021
  }
1006
1022
 
1007
1023
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
@@ -1289,10 +1305,8 @@ export class Bot {
1289
1305
  } else {
1290
1306
  this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
1291
1307
  }
1292
- if (this.BLE) {
1293
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1294
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1295
- }
1308
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1309
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1296
1310
  }
1297
1311
 
1298
1312
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
@@ -1302,10 +1316,12 @@ export class Bot {
1302
1316
  );
1303
1317
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1304
1318
  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) {
1319
+ if (device.firmware) {
1308
1320
  FirmwareRevision = device.firmware;
1321
+ } else if (device.version) {
1322
+ FirmwareRevision = JSON.stringify(device.version);
1323
+ } if (accessory.context.FirmwareRevision) {
1324
+ FirmwareRevision = accessory.context.FirmwareRevision;
1309
1325
  } else {
1310
1326
  FirmwareRevision = this.platform.version;
1311
1327
  }
@@ -1377,7 +1393,7 @@ export class Bot {
1377
1393
  config['maxRetry'] = device.maxRetry;
1378
1394
  }
1379
1395
  if (Object.entries(config).length !== 0) {
1380
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1396
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1381
1397
  }
1382
1398
  }
1383
1399
 
@@ -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();
@@ -402,7 +406,7 @@ export class CeilingLight {
402
406
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
403
407
  headers: this.platform.generateHeaders(),
404
408
  });
405
- const deviceStatus = await body.json();
409
+ const deviceStatus: any = await body.json();
406
410
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
407
411
  this.statusCode(statusCode);
408
412
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -524,7 +528,7 @@ export class CeilingLight {
524
528
  method: 'POST',
525
529
  headers: this.platform.generateHeaders(),
526
530
  });
527
- const deviceStatus = await body.json();
531
+ const deviceStatus: any = await body.json();
528
532
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
529
533
  this.statusCode(statusCode);
530
534
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -575,7 +579,7 @@ export class CeilingLight {
575
579
  method: 'POST',
576
580
  headers: this.platform.generateHeaders(),
577
581
  });
578
- const deviceStatus = await body.json();
582
+ const deviceStatus: any = await body.json();
579
583
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
580
584
  this.statusCode(statusCode);
581
585
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -611,7 +615,7 @@ export class CeilingLight {
611
615
  method: 'POST',
612
616
  headers: this.platform.generateHeaders(),
613
617
  });
614
- const deviceStatus = await body.json();
618
+ const deviceStatus: any = await body.json();
615
619
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
616
620
  this.statusCode(statusCode);
617
621
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -645,7 +649,7 @@ export class CeilingLight {
645
649
  method: 'POST',
646
650
  headers: this.platform.generateHeaders(),
647
651
  });
648
- const deviceStatus = await body.json();
652
+ const deviceStatus: any = await body.json();
649
653
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
650
654
  this.statusCode(statusCode);
651
655
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -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;
@@ -438,7 +441,7 @@ export class ColorBulb {
438
441
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
439
442
  headers: this.platform.generateHeaders(),
440
443
  });
441
- const deviceStatus = await body.json();
444
+ const deviceStatus: any = await body.json();
442
445
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
443
446
  this.statusCode(statusCode);
444
447
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -696,7 +699,7 @@ export class ColorBulb {
696
699
  method: 'POST',
697
700
  headers: this.platform.generateHeaders(),
698
701
  });
699
- const deviceStatus = await body.json();
702
+ const deviceStatus: any = await body.json();
700
703
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
701
704
  this.statusCode(statusCode);
702
705
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -747,7 +750,7 @@ export class ColorBulb {
747
750
  method: 'POST',
748
751
  headers: this.platform.generateHeaders(),
749
752
  });
750
- const deviceStatus = await body.json();
753
+ const deviceStatus: any = await body.json();
751
754
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
752
755
  this.statusCode(statusCode);
753
756
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -783,7 +786,7 @@ export class ColorBulb {
783
786
  method: 'POST',
784
787
  headers: this.platform.generateHeaders(),
785
788
  });
786
- const deviceStatus = await body.json();
789
+ const deviceStatus: any = await body.json();
787
790
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
788
791
  this.statusCode(statusCode);
789
792
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -817,7 +820,7 @@ export class ColorBulb {
817
820
  method: 'POST',
818
821
  headers: this.platform.generateHeaders(),
819
822
  });
820
- const deviceStatus = await body.json();
823
+ const deviceStatus: any = await body.json();
821
824
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
822
825
  this.statusCode(statusCode);
823
826
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -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
  /**
@@ -386,7 +400,7 @@ export class Contact {
386
400
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
387
401
  headers: this.platform.generateHeaders(),
388
402
  });
389
- const deviceStatus = await body.json();
403
+ const deviceStatus: any = await body.json();
390
404
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
391
405
  this.statusCode(statusCode);
392
406
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -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