@switchbot/homebridge-switchbot 2.8.0-beta.9 → 2.8.0

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 (109) 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 +7 -4
  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 +64 -50
  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 +7 -4
  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 +6 -3
  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 +43 -32
  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 +31 -34
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/hub.d.ts +2 -1
  28. package/dist/device/hub.d.ts.map +1 -1
  29. package/dist/device/hub.js +8 -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 +7 -4
  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 +8 -4
  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 +7 -4
  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 +9 -4
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts +1 -0
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +8 -4
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts +1 -0
  51. package/dist/device/meterplus.d.ts.map +1 -1
  52. package/dist/device/meterplus.js +8 -4
  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 +44 -29
  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 +7 -4
  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 +25 -0
  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 +67 -86
  69. package/dist/irdevice/airconditioner.js.map +1 -1
  70. package/dist/irdevice/airpurifier.js.map +1 -1
  71. package/dist/irdevice/camera.js.map +1 -1
  72. package/dist/irdevice/fan.js.map +1 -1
  73. package/dist/irdevice/light.js.map +1 -1
  74. package/dist/irdevice/other.js.map +1 -1
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  77. package/dist/irdevice/waterheater.js.map +1 -1
  78. package/dist/platform.d.ts.map +1 -1
  79. package/dist/platform.js +64 -63
  80. package/dist/platform.js.map +1 -1
  81. package/package.json +11 -11
  82. package/src/device/blindtilt.ts +8 -6
  83. package/src/device/bot.ts +64 -48
  84. package/src/device/ceilinglight.ts +11 -8
  85. package/src/device/colorbulb.ts +11 -8
  86. package/src/device/contact.ts +43 -29
  87. package/src/device/curtain.ts +32 -33
  88. package/src/device/hub.ts +9 -6
  89. package/src/device/humidifier.ts +9 -7
  90. package/src/device/iosensor.ts +9 -5
  91. package/src/device/lightstrip.ts +10 -7
  92. package/src/device/lock.ts +11 -5
  93. package/src/device/meter.ts +9 -5
  94. package/src/device/meterplus.ts +9 -5
  95. package/src/device/motion.ts +44 -26
  96. package/src/device/plug.ts +8 -5
  97. package/src/device/robotvacuumcleaner.ts +32 -3
  98. package/src/irdevice/airconditioner.ts +80 -94
  99. package/src/irdevice/airpurifier.ts +1 -1
  100. package/src/irdevice/camera.ts +1 -1
  101. package/src/irdevice/fan.ts +1 -1
  102. package/src/irdevice/light.ts +1 -1
  103. package/src/irdevice/other.ts +1 -1
  104. package/src/irdevice/tv.ts +1 -1
  105. package/src/irdevice/vacuumcleaner.ts +1 -1
  106. package/src/irdevice/waterheater.ts +1 -1
  107. package/src/platform.ts +73 -73
  108. package/src/settings.ts +1 -1
  109. package/.github/npm-version-script.js +0 -81
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
 
@@ -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}`);
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}`);
1004
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
  }
@@ -25,6 +25,7 @@ export class CeilingLight {
25
25
  ColorTemperature?: CharacteristicValue;
26
26
 
27
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
28
29
  power: deviceStatus['power'];
29
30
  color: deviceStatus['color'];
30
31
  brightness: deviceStatus['brightness'];
@@ -405,7 +406,7 @@ export class CeilingLight {
405
406
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
406
407
  headers: this.platform.generateHeaders(),
407
408
  });
408
- const deviceStatus = await body.json();
409
+ const deviceStatus: any = await body.json();
409
410
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
410
411
  this.statusCode(statusCode);
411
412
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -527,7 +528,7 @@ export class CeilingLight {
527
528
  method: 'POST',
528
529
  headers: this.platform.generateHeaders(),
529
530
  });
530
- const deviceStatus = await body.json();
531
+ const deviceStatus: any = await body.json();
531
532
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
532
533
  this.statusCode(statusCode);
533
534
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -578,7 +579,7 @@ export class CeilingLight {
578
579
  method: 'POST',
579
580
  headers: this.platform.generateHeaders(),
580
581
  });
581
- const deviceStatus = await body.json();
582
+ const deviceStatus: any = await body.json();
582
583
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
583
584
  this.statusCode(statusCode);
584
585
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -614,7 +615,7 @@ export class CeilingLight {
614
615
  method: 'POST',
615
616
  headers: this.platform.generateHeaders(),
616
617
  });
617
- const deviceStatus = await body.json();
618
+ const deviceStatus: any = await body.json();
618
619
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
619
620
  this.statusCode(statusCode);
620
621
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -648,7 +649,7 @@ export class CeilingLight {
648
649
  method: 'POST',
649
650
  headers: this.platform.generateHeaders(),
650
651
  });
651
- const deviceStatus = await body.json();
652
+ const deviceStatus: any = await body.json();
652
653
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
653
654
  this.statusCode(statusCode);
654
655
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -964,10 +965,12 @@ export class CeilingLight {
964
965
  );
965
966
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
966
967
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
967
- if (accessory.context.FirmwareRevision) {
968
- FirmwareRevision = accessory.context.FirmwareRevision;
969
- } else if (device.firmware) {
968
+ if (device.firmware) {
970
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;
971
974
  } else {
972
975
  FirmwareRevision = this.platform.version;
973
976
  }
@@ -25,6 +25,7 @@ export class ColorBulb {
25
25
  ColorTemperature?: CharacteristicValue;
26
26
 
27
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
28
29
  power: deviceStatus['power'];
29
30
  color: deviceStatus['color'];
30
31
  brightness: deviceStatus['brightness'];
@@ -440,7 +441,7 @@ export class ColorBulb {
440
441
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
441
442
  headers: this.platform.generateHeaders(),
442
443
  });
443
- const deviceStatus = await body.json();
444
+ const deviceStatus: any = await body.json();
444
445
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
445
446
  this.statusCode(statusCode);
446
447
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -698,7 +699,7 @@ export class ColorBulb {
698
699
  method: 'POST',
699
700
  headers: this.platform.generateHeaders(),
700
701
  });
701
- const deviceStatus = await body.json();
702
+ const deviceStatus: any = await body.json();
702
703
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
703
704
  this.statusCode(statusCode);
704
705
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -749,7 +750,7 @@ export class ColorBulb {
749
750
  method: 'POST',
750
751
  headers: this.platform.generateHeaders(),
751
752
  });
752
- const deviceStatus = await body.json();
753
+ const deviceStatus: any = await body.json();
753
754
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
754
755
  this.statusCode(statusCode);
755
756
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -785,7 +786,7 @@ export class ColorBulb {
785
786
  method: 'POST',
786
787
  headers: this.platform.generateHeaders(),
787
788
  });
788
- const deviceStatus = await body.json();
789
+ const deviceStatus: any = await body.json();
789
790
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
790
791
  this.statusCode(statusCode);
791
792
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -819,7 +820,7 @@ export class ColorBulb {
819
820
  method: 'POST',
820
821
  headers: this.platform.generateHeaders(),
821
822
  });
822
- const deviceStatus = await body.json();
823
+ const deviceStatus: any = await body.json();
823
824
  this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
824
825
  this.statusCode(statusCode);
825
826
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
@@ -1135,10 +1136,12 @@ export class ColorBulb {
1135
1136
  );
1136
1137
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1137
1138
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1138
- if (accessory.context.FirmwareRevision) {
1139
- FirmwareRevision = accessory.context.FirmwareRevision;
1140
- } else if (device.firmware) {
1139
+ if (device.firmware) {
1141
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;
1142
1145
  } else {
1143
1146
  FirmwareRevision = this.platform.version;
1144
1147
  }
@@ -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'];
@@ -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
  }
@@ -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'];
@@ -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
  }
@@ -560,7 +559,7 @@ export class Curtain {
560
559
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
561
560
  headers: this.platform.generateHeaders(),
562
561
  });
563
- const deviceStatus = await body.json();
562
+ const deviceStatus: any = await body.json();
564
563
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
565
564
  this.statusCode(statusCode);
566
565
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -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) {
@@ -704,7 +705,7 @@ export class Curtain {
704
705
  method: 'POST',
705
706
  headers: this.platform.generateHeaders(),
706
707
  });
707
- const deviceStatus = await body.json();
708
+ const deviceStatus: any = await body.json();
708
709
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
709
710
  this.statusCode(statusCode);
710
711
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -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
  }