@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/hub.ts CHANGED
@@ -3,7 +3,7 @@ import { interval } from 'rxjs';
3
3
  import { request } from 'undici';
4
4
  import { Context } from 'vm';
5
5
  import { SwitchBotPlatform } from '../platform';
6
- import { Devices, device, devicesConfig } from '../settings';
6
+ import { Devices, device, deviceStatus, devicesConfig } from '../settings';
7
7
  import { sleep } from '../utils';
8
8
 
9
9
  export class Hub {
@@ -18,6 +18,7 @@ export class Hub {
18
18
  CurrentAmbientLightLevel!: number;
19
19
 
20
20
  // OpenAPI Others
21
+ Version: deviceStatus['version'];
21
22
  deviceStatus!: any; //deviceStatusResponse;
22
23
  lightLevel!: number;
23
24
  spaceBetweenLevels!: number;
@@ -293,7 +294,7 @@ export class Hub {
293
294
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
294
295
  headers: this.platform.generateHeaders(),
295
296
  });
296
- const deviceStatus = await body.json();
297
+ const deviceStatus: any = await body.json();
297
298
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
298
299
  this.statusCode(statusCode);
299
300
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -357,7 +358,7 @@ export class Hub {
357
358
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
358
359
  } else {
359
360
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
360
- this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
361
+ this.hubLightSensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
361
362
  this.debugLog(
362
363
  `${this.device.deviceType}: ${this.accessory.displayName} ` +
363
364
  `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
@@ -444,10 +445,12 @@ export class Hub {
444
445
  );
445
446
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
446
447
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
447
- if (accessory.context.FirmwareRevision) {
448
- FirmwareRevision = accessory.context.FirmwareRevision;
449
- } else if (device.firmware) {
448
+ if (device.firmware) {
450
449
  FirmwareRevision = device.firmware;
450
+ } else if (device.version) {
451
+ FirmwareRevision = JSON.stringify(device.version);
452
+ } else if (accessory.context.FirmwareRevision) {
453
+ FirmwareRevision = accessory.context.FirmwareRevision;
451
454
  } else {
452
455
  FirmwareRevision = this.platform.version;
453
456
  }
@@ -379,7 +379,7 @@ export class Humidifier {
379
379
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
380
380
  headers: this.platform.generateHeaders(),
381
381
  });
382
- const deviceStatus = await body.json();
382
+ const deviceStatus: any = await body.json();
383
383
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
384
384
  this.statusCode(statusCode);
385
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -475,7 +475,7 @@ export class Humidifier {
475
475
  method: 'POST',
476
476
  headers: this.platform.generateHeaders(),
477
477
  });
478
- const deviceStatus = await body.json();
478
+ const deviceStatus: any = await body.json();
479
479
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
480
480
  this.statusCode(statusCode);
481
481
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -518,7 +518,7 @@ export class Humidifier {
518
518
  method: 'POST',
519
519
  headers: this.platform.generateHeaders(),
520
520
  });
521
- const deviceStatus = await body.json();
521
+ const deviceStatus: any = await body.json();
522
522
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
523
523
  this.statusCode(statusCode);
524
524
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -556,7 +556,7 @@ export class Humidifier {
556
556
  method: 'POST',
557
557
  headers: this.platform.generateHeaders(),
558
558
  });
559
- const deviceStatus = await body.json();
559
+ const deviceStatus: any = await body.json();
560
560
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
561
561
  this.statusCode(statusCode);
562
562
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -845,10 +845,12 @@ export class Humidifier {
845
845
  );
846
846
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
847
847
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
848
- if (accessory.context.FirmwareRevision) {
849
- FirmwareRevision = accessory.context.FirmwareRevision;
850
- } else if (device.firmware) {
848
+ if (device.firmware) {
851
849
  FirmwareRevision = device.firmware;
850
+ } else if (device.version) {
851
+ FirmwareRevision = JSON.stringify(device.version);
852
+ } else if (accessory.context.FirmwareRevision) {
853
+ FirmwareRevision = accessory.context.FirmwareRevision;
852
854
  } else {
853
855
  FirmwareRevision = this.platform.version;
854
856
  }
@@ -29,6 +29,7 @@ export class IOSensor {
29
29
  StatusLowBattery?: CharacteristicValue;
30
30
 
31
31
  // OpenAPI Others
32
+ Version: deviceStatus['version'];
32
33
  Battery: deviceStatus['battery'];
33
34
  Temperature: deviceStatus['temperature'];
34
35
  Humidity: deviceStatus['humidity'];
@@ -337,14 +338,15 @@ export class IOSensor {
337
338
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
338
339
  headers: this.platform.generateHeaders(),
339
340
  });
340
- const deviceStatus = await body.json();
341
+ const deviceStatus: any = await body.json();
341
342
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
342
343
  this.statusCode(statusCode);
343
344
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
344
345
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
345
346
  this.Humidity = deviceStatus.body.humidity!;
346
347
  this.Temperature = deviceStatus.body.temperature!;
347
- this.Battery = deviceStatus.body.battery!;
348
+ this.Battery = deviceStatus.body.battery;
349
+ this.Version = deviceStatus.body.version;
348
350
  this.openAPIparseStatus();
349
351
  this.updateHomeKitCharacteristics();
350
352
  } catch (e: any) {
@@ -592,10 +594,12 @@ export class IOSensor {
592
594
  );
593
595
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
594
596
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
595
- if (accessory.context.FirmwareRevision) {
596
- FirmwareRevision = accessory.context.FirmwareRevision;
597
- } else if (device.firmware) {
597
+ if (device.firmware) {
598
598
  FirmwareRevision = device.firmware;
599
+ } else if (device.version) {
600
+ FirmwareRevision = JSON.stringify(device.version);
601
+ } else if (accessory.context.FirmwareRevision) {
602
+ FirmwareRevision = accessory.context.FirmwareRevision;
599
603
  } else {
600
604
  FirmwareRevision = this.platform.version;
601
605
  }
@@ -25,6 +25,7 @@ export class StripLight {
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'];
@@ -380,7 +381,7 @@ export class StripLight {
380
381
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
381
382
  headers: this.platform.generateHeaders(),
382
383
  });
383
- const deviceStatus = await body.json();
384
+ const deviceStatus: any = await body.json();
384
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
385
386
  this.statusCode(statusCode);
386
387
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -593,7 +594,7 @@ export class StripLight {
593
594
  method: 'POST',
594
595
  headers: this.platform.generateHeaders(),
595
596
  });
596
- const deviceStatus = await body.json();
597
+ const deviceStatus: any = await body.json();
597
598
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
598
599
  this.statusCode(statusCode);
599
600
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -641,7 +642,7 @@ export class StripLight {
641
642
  method: 'POST',
642
643
  headers: this.platform.generateHeaders(),
643
644
  });
644
- const deviceStatus = await body.json();
645
+ const deviceStatus: any = await body.json();
645
646
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
646
647
  this.statusCode(statusCode);
647
648
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -675,7 +676,7 @@ export class StripLight {
675
676
  method: 'POST',
676
677
  headers: this.platform.generateHeaders(),
677
678
  });
678
- const deviceStatus = await body.json();
679
+ const deviceStatus: any = await body.json();
679
680
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
680
681
  this.statusCode(statusCode);
681
682
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -990,10 +991,12 @@ export class StripLight {
990
991
  );
991
992
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
992
993
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
993
- if (accessory.context.FirmwareRevision) {
994
- FirmwareRevision = accessory.context.FirmwareRevision;
995
- } else if (device.firmware) {
994
+ if (device.firmware) {
996
995
  FirmwareRevision = device.firmware;
996
+ } else if (device.version) {
997
+ FirmwareRevision = JSON.stringify(device.version);
998
+ } else if (accessory.context.FirmwareRevision) {
999
+ FirmwareRevision = accessory.context.FirmwareRevision;
997
1000
  } else {
998
1001
  FirmwareRevision = this.platform.version;
999
1002
  }
@@ -19,6 +19,8 @@ export class Lock {
19
19
  LockTargetState!: CharacteristicValue;
20
20
 
21
21
  // OpenAPI Others
22
+ Version: deviceStatus['version'];
23
+ Battery: deviceStatus['battery'];
22
24
  doorState!: deviceStatus['doorState'];
23
25
  lockState!: deviceStatus['lockState'];
24
26
  deviceStatus!: any; //deviceStatusResponse;
@@ -310,13 +312,15 @@ export class Lock {
310
312
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
311
313
  headers: this.platform.generateHeaders(),
312
314
  });
313
- const deviceStatus = await body.json();
315
+ const deviceStatus: any = await body.json();
314
316
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
315
317
  this.statusCode(statusCode);
316
318
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
317
319
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
318
320
  this.lockState = deviceStatus.body.lockState;
319
321
  this.doorState = deviceStatus.body.doorState;
322
+ this.Battery = deviceStatus.body.battery;
323
+ this.Version = deviceStatus.body.version;
320
324
  this.openAPIparseStatus();
321
325
  this.updateHomeKitCharacteristics();
322
326
  } catch (e: any) {
@@ -417,7 +421,7 @@ export class Lock {
417
421
  method: 'POST',
418
422
  headers: this.platform.generateHeaders(),
419
423
  });
420
- const deviceStatus = await body.json();
424
+ const deviceStatus: any = await body.json();
421
425
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
422
426
  this.statusCode(statusCode);
423
427
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -598,10 +602,12 @@ export class Lock {
598
602
  );
599
603
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
600
604
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
601
- if (accessory.context.FirmwareRevision) {
602
- FirmwareRevision = accessory.context.FirmwareRevision;
603
- } else if (device.firmware) {
605
+ if (device.firmware) {
604
606
  FirmwareRevision = device.firmware;
607
+ } else if (device.version) {
608
+ FirmwareRevision = JSON.stringify(device.version);
609
+ } else if (accessory.context.FirmwareRevision) {
610
+ FirmwareRevision = accessory.context.FirmwareRevision;
605
611
  } else {
606
612
  FirmwareRevision = this.platform.version;
607
613
  }
@@ -29,6 +29,7 @@ export class Meter {
29
29
  StatusLowBattery?: CharacteristicValue;
30
30
 
31
31
  // OpenAPI Others
32
+ Version: deviceStatus['version'];
32
33
  Battery: deviceStatus['battery'];
33
34
  Temperature: deviceStatus['temperature'];
34
35
  Humidity: deviceStatus['humidity'];
@@ -343,14 +344,15 @@ export class Meter {
343
344
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
344
345
  headers: this.platform.generateHeaders(),
345
346
  });
346
- const deviceStatus = await body.json();
347
+ const deviceStatus: any = await body.json();
347
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
348
349
  this.statusCode(statusCode);
349
350
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
350
351
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
351
352
  this.Humidity = deviceStatus.body.humidity!;
352
353
  this.Temperature = deviceStatus.body.temperature!;
353
- this.Battery = deviceStatus.body.battery!;
354
+ this.Battery = deviceStatus.body.battery;
355
+ this.Version = deviceStatus.body.version;
354
356
  this.openAPIparseStatus();
355
357
  this.updateHomeKitCharacteristics();
356
358
  } catch (e: any) {
@@ -600,10 +602,12 @@ export class Meter {
600
602
  );
601
603
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
602
604
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
603
- if (accessory.context.FirmwareRevision) {
604
- FirmwareRevision = accessory.context.FirmwareRevision;
605
- } else if (device.firmware) {
605
+ if (device.firmware) {
606
606
  FirmwareRevision = device.firmware;
607
+ } else if (device.version) {
608
+ FirmwareRevision = JSON.stringify(device.version);
609
+ } else if (accessory.context.FirmwareRevision) {
610
+ FirmwareRevision = accessory.context.FirmwareRevision;
607
611
  } else {
608
612
  FirmwareRevision = this.platform.version;
609
613
  }
@@ -29,6 +29,7 @@ export class MeterPlus {
29
29
  StatusLowBattery?: CharacteristicValue;
30
30
 
31
31
  // OpenAPI Others
32
+ Version: deviceStatus['version'];
32
33
  Battery: deviceStatus['battery'];
33
34
  Temperature: deviceStatus['temperature'];
34
35
  Humidity: deviceStatus['humidity'];
@@ -343,14 +344,15 @@ export class MeterPlus {
343
344
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
344
345
  headers: this.platform.generateHeaders(),
345
346
  });
346
- const deviceStatus = await body.json();
347
+ const deviceStatus: any = await body.json();
347
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
348
349
  this.statusCode(statusCode);
349
350
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
350
351
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
351
352
  this.Humidity = deviceStatus.body.humidity!;
352
353
  this.Temperature = deviceStatus.body.temperature!;
353
- this.Battery = deviceStatus.body.battery!;
354
+ this.Battery = deviceStatus.body.battery;
355
+ this.Version = deviceStatus.body.version;
354
356
  this.openAPIparseStatus();
355
357
  this.updateHomeKitCharacteristics();
356
358
  } catch (e: any) {
@@ -611,10 +613,12 @@ export class MeterPlus {
611
613
  );
612
614
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
613
615
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
614
- if (accessory.context.FirmwareRevision) {
615
- FirmwareRevision = accessory.context.FirmwareRevision;
616
- } else if (device.firmware) {
616
+ if (device.firmware) {
617
617
  FirmwareRevision = device.firmware;
618
+ } else if (device.version) {
619
+ FirmwareRevision = JSON.stringify(device.version);
620
+ } else if (accessory.context.FirmwareRevision) {
621
+ FirmwareRevision = accessory.context.FirmwareRevision;
618
622
  } else {
619
623
  FirmwareRevision = this.platform.version;
620
624
  }
@@ -25,6 +25,8 @@ export class Motion {
25
25
  StatusLowBattery?: CharacteristicValue;
26
26
 
27
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
29
+ Battery: deviceStatus['battery'];
28
30
  deviceStatus!: any; //deviceStatusResponse;
29
31
  moveDetected: deviceStatus['moveDetected'];
30
32
  brightness: deviceStatus['brightness'];
@@ -124,17 +126,16 @@ export class Motion {
124
126
  }
125
127
 
126
128
  // Battery Service
127
- if (!this.BLE) {
128
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
129
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
130
- accessory.removeService(this.batteryService!);
131
- } else if (this.BLE && !this.batteryService) {
129
+ if (!this.batteryService) {
132
130
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
133
131
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
134
132
  `${accessory.displayName} Battery`;
135
133
 
136
134
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
137
- this.batteryService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
135
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
136
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
137
+ }
138
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
138
139
  } else {
139
140
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
140
141
  }
@@ -230,6 +231,19 @@ export class Motion {
230
231
  }
231
232
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
232
233
  }
234
+ // Battery
235
+ if (this.battery === undefined) {
236
+ this.battery = 100;
237
+ }
238
+ this.BatteryLevel = this.Battery!;
239
+ if (this.BatteryLevel < 10) {
240
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
241
+ } else {
242
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
243
+ }
244
+ this.debugLog(
245
+ `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
246
+ );
233
247
  }
234
248
 
235
249
  /**
@@ -343,13 +357,15 @@ export class Motion {
343
357
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
344
358
  headers: this.platform.generateHeaders(),
345
359
  });
346
- const deviceStatus = await body.json();
360
+ const deviceStatus: any = await body.json();
347
361
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
348
362
  this.statusCode(statusCode);
349
363
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
350
364
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
351
365
  this.moveDetected = deviceStatus.body.moveDetected;
352
366
  this.brightness = deviceStatus.body.brightness;
367
+ this.Battery = deviceStatus.body.battery;
368
+ this.Version = deviceStatus.body.version;
353
369
  this.openAPIparseStatus();
354
370
  this.updateHomeKitCharacteristics();
355
371
  } catch (e: any) {
@@ -372,21 +388,21 @@ export class Motion {
372
388
  this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
373
389
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
374
390
  }
391
+ if (this.BatteryLevel === undefined) {
392
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
393
+ } else {
394
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
395
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
396
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
397
+ }
398
+ if (this.StatusLowBattery === undefined) {
399
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
400
+ } else {
401
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
402
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
403
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
404
+ }
375
405
  if (this.BLE) {
376
- if (this.BatteryLevel === undefined) {
377
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
378
- } else {
379
- this.accessory.context.BatteryLevel = this.BatteryLevel;
380
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
381
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
382
- }
383
- if (this.StatusLowBattery === undefined) {
384
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
385
- } else {
386
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
387
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
388
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
389
- }
390
406
  if (this.CurrentAmbientLightLevel === undefined) {
391
407
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
392
408
  } else {
@@ -539,9 +555,9 @@ export class Motion {
539
555
 
540
556
  async apiError(e: any): Promise<void> {
541
557
  this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
558
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
559
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
542
560
  if (this.BLE) {
543
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
544
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
545
561
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
546
562
  }
547
563
  }
@@ -553,10 +569,12 @@ export class Motion {
553
569
  );
554
570
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
555
571
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
556
- if (accessory.context.FirmwareRevision) {
557
- FirmwareRevision = accessory.context.FirmwareRevision;
558
- } else if (device.firmware) {
572
+ if (device.firmware) {
559
573
  FirmwareRevision = device.firmware;
574
+ } else if (device.version) {
575
+ FirmwareRevision = JSON.stringify(device.version);
576
+ } else if (accessory.context.FirmwareRevision) {
577
+ FirmwareRevision = accessory.context.FirmwareRevision;
560
578
  } else {
561
579
  FirmwareRevision = this.platform.version;
562
580
  }
@@ -15,6 +15,7 @@ export class Plug {
15
15
  On!: CharacteristicValue;
16
16
 
17
17
  // OpenAPI Others
18
+ Version: deviceStatus['version'];
18
19
  power: deviceStatus['power'];
19
20
  deviceStatus!: any; //deviceStatusResponse;
20
21
 
@@ -264,7 +265,7 @@ export class Plug {
264
265
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
265
266
  headers: this.platform.generateHeaders(),
266
267
  });
267
- const deviceStatus = await body.json();
268
+ const deviceStatus: any = await body.json();
268
269
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
269
270
  this.statusCode(statusCode);
270
271
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -382,7 +383,7 @@ export class Plug {
382
383
  method: 'POST',
383
384
  headers: this.platform.generateHeaders(),
384
385
  });
385
- const deviceStatus = await body.json();
386
+ const deviceStatus: any = await body.json();
386
387
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
387
388
  this.statusCode(statusCode);
388
389
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -583,10 +584,12 @@ export class Plug {
583
584
  );
584
585
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
585
586
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
586
- if (accessory.context.FirmwareRevision) {
587
- FirmwareRevision = accessory.context.FirmwareRevision;
588
- } else if (device.firmware) {
587
+ if (device.firmware) {
589
588
  FirmwareRevision = device.firmware;
589
+ } else if (device.version) {
590
+ FirmwareRevision = JSON.stringify(device.version);
591
+ } else if (accessory.context.FirmwareRevision) {
592
+ FirmwareRevision = accessory.context.FirmwareRevision;
590
593
  } else {
591
594
  FirmwareRevision = this.platform.version;
592
595
  }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable brace-style */
1
2
  import { Context } from 'vm';
2
3
  import { request } from 'undici';
3
4
  import { sleep } from '../utils';
@@ -19,6 +20,8 @@ export class RobotVacuumCleaner {
19
20
  StatusLowBattery?: CharacteristicValue;
20
21
 
21
22
  // OpenAPI Others
23
+ Version: deviceStatus['version'];
24
+ Battery: deviceStatus['battery'];
22
25
  power: deviceStatus['power'];
23
26
  deviceStatus!: any; //deviceStatusResponse;
24
27
 
@@ -107,6 +110,21 @@ export class RobotVacuumCleaner {
107
110
  })
108
111
  .onSet(this.BrightnessSet.bind(this));
109
112
 
113
+ // Battery Service
114
+ if (!this.batteryService) {
115
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
116
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
117
+ `${accessory.displayName} Battery`;
118
+
119
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
120
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
121
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
122
+ }
123
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
124
+ } else {
125
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
126
+ }
127
+
110
128
  // Update Homekit
111
129
  this.updateHomeKitCharacteristics();
112
130
 
@@ -186,6 +204,15 @@ export class RobotVacuumCleaner {
186
204
  this.On = false;
187
205
  }
188
206
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
207
+
208
+ // Battery
209
+ this.BatteryLevel = Number(this.Battery);
210
+ if (this.BatteryLevel < 15) {
211
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
212
+ } else {
213
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
214
+ }
215
+ this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
189
216
  }
190
217
 
191
218
  /**
@@ -276,12 +303,14 @@ export class RobotVacuumCleaner {
276
303
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
277
304
  headers: this.platform.generateHeaders(),
278
305
  });
279
- const deviceStatus = await body.json();
306
+ const deviceStatus: any = await body.json();
280
307
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
281
308
  this.statusCode(statusCode);
282
309
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
283
310
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
284
311
  this.power = deviceStatus.body.power;
312
+ this.Battery = deviceStatus.body.battery;
313
+ this.Version = deviceStatus.body.version;
285
314
  this.openAPIparseStatus();
286
315
  this.updateHomeKitCharacteristics();
287
316
  } catch (e: any) {
@@ -393,7 +422,7 @@ export class RobotVacuumCleaner {
393
422
  method: 'POST',
394
423
  headers: this.platform.generateHeaders(),
395
424
  });
396
- const deviceStatus = await body.json();
425
+ const deviceStatus: any = await body.json();
397
426
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
398
427
  this.statusCode(statusCode);
399
428
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -422,7 +451,7 @@ export class RobotVacuumCleaner {
422
451
  method: 'POST',
423
452
  headers: this.platform.generateHeaders(),
424
453
  });
425
- const deviceStatus = await body.json();
454
+ const deviceStatus: any = await body.json();
426
455
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
427
456
  this.statusCode(statusCode);
428
457
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);