@switchbot/homebridge-switchbot 2.8.0 → 2.8.1-beta.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 (94) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/dist/device/blindtilt.d.ts +21 -23
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +71 -73
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +11 -15
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +38 -34
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +10 -14
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +33 -23
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +16 -24
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +49 -43
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +16 -24
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +49 -51
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +21 -26
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +49 -47
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/hub.d.ts +9 -8
  27. package/dist/device/hub.d.ts.map +1 -1
  28. package/dist/device/hub.js +42 -30
  29. package/dist/device/hub.js.map +1 -1
  30. package/dist/device/humidifier.d.ts +8 -10
  31. package/dist/device/humidifier.d.ts.map +1 -1
  32. package/dist/device/humidifier.js +27 -17
  33. package/dist/device/humidifier.js.map +1 -1
  34. package/dist/device/iosensor.d.ts +16 -21
  35. package/dist/device/iosensor.d.ts.map +1 -1
  36. package/dist/device/iosensor.js +35 -26
  37. package/dist/device/iosensor.js.map +1 -1
  38. package/dist/device/lightstrip.d.ts +1 -5
  39. package/dist/device/lightstrip.d.ts.map +1 -1
  40. package/dist/device/lightstrip.js +2 -4
  41. package/dist/device/lightstrip.js.map +1 -1
  42. package/dist/device/lock.d.ts +15 -21
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +64 -26
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts +4 -9
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +8 -16
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts +5 -10
  51. package/dist/device/meterplus.d.ts.map +1 -1
  52. package/dist/device/meterplus.js +8 -16
  53. package/dist/device/meterplus.js.map +1 -1
  54. package/dist/device/motion.d.ts +4 -8
  55. package/dist/device/motion.d.ts.map +1 -1
  56. package/dist/device/motion.js +10 -23
  57. package/dist/device/motion.js.map +1 -1
  58. package/dist/device/plug.d.ts +1 -5
  59. package/dist/device/plug.d.ts.map +1 -1
  60. package/dist/device/plug.js +2 -4
  61. package/dist/device/plug.js.map +1 -1
  62. package/dist/device/robotvacuumcleaner.d.ts +4 -8
  63. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  64. package/dist/device/robotvacuumcleaner.js +7 -16
  65. package/dist/device/robotvacuumcleaner.js.map +1 -1
  66. package/dist/irdevice/fan.d.ts +0 -1
  67. package/dist/irdevice/fan.d.ts.map +1 -1
  68. package/dist/irdevice/fan.js.map +1 -1
  69. package/dist/irdevice/tv.d.ts +0 -1
  70. package/dist/irdevice/tv.d.ts.map +1 -1
  71. package/dist/irdevice/tv.js.map +1 -1
  72. package/dist/settings.d.ts +3 -1
  73. package/dist/settings.d.ts.map +1 -1
  74. package/dist/settings.js.map +1 -1
  75. package/package.json +2 -2
  76. package/src/device/blindtilt.ts +96 -95
  77. package/src/device/bot.ts +54 -54
  78. package/src/device/ceilinglight.ts +46 -39
  79. package/src/device/colorbulb.ts +68 -69
  80. package/src/device/contact.ts +69 -77
  81. package/src/device/curtain.ts +75 -74
  82. package/src/device/hub.ts +53 -38
  83. package/src/device/humidifier.ts +33 -26
  84. package/src/device/iosensor.ts +53 -48
  85. package/src/device/lightstrip.ts +4 -10
  86. package/src/device/lock.ts +84 -49
  87. package/src/device/meter.ts +13 -25
  88. package/src/device/meterplus.ts +14 -27
  89. package/src/device/motion.ts +16 -32
  90. package/src/device/plug.ts +4 -10
  91. package/src/device/robotvacuumcleaner.ts +13 -25
  92. package/src/irdevice/fan.ts +0 -3
  93. package/src/irdevice/tv.ts +0 -3
  94. package/src/settings.ts +5 -1
package/src/device/bot.ts CHANGED
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
5
5
  import { SwitchBotPlatform } from '../platform';
6
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
7
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
8
- import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot, Devices } from '../settings';
8
+ import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
9
9
 
10
10
  /**
11
11
  * Platform Accessory
@@ -21,7 +21,7 @@ export class Bot {
21
21
  windowService?: Service;
22
22
  switchService?: Service;
23
23
  outletService?: Service;
24
- batteryService?: Service;
24
+ batteryService: Service;
25
25
  garageDoorService?: Service;
26
26
  windowCoveringService?: Service;
27
27
  statefulProgrammableSwitchService?: Service;
@@ -31,31 +31,28 @@ export class Bot {
31
31
  BatteryLevel!: CharacteristicValue;
32
32
  StatusLowBattery!: CharacteristicValue;
33
33
 
34
- // OpenAPI Others
35
- Version: deviceStatus['version'];
36
- Battery: deviceStatus['battery'];
37
- power: deviceStatus['power'];
38
- deviceStatus!: any; //deviceStatusResponse;
39
-
40
- // BLE Others
41
- connected?: boolean;
42
- switchbot!: switchbot;
43
- serviceData!: serviceData;
44
- address!: ad['address'];
45
- mode!: serviceData['mode'];
46
- state!: serviceData['state'];
47
- battery!: serviceData['battery'];
34
+ // OpenAPI Status
35
+ OpenAPI_On: deviceStatus['power'];
36
+ OpenAPI_BatteryLevel: deviceStatus['battery'];
37
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
38
+
39
+ // BLE Status
40
+ BLE_On!: serviceData['state'];
41
+ BLE_Mode!: serviceData['mode'];
42
+ BLE_BatteryLevel!: serviceData['battery'];
43
+
44
+ //BLE Others
45
+ BLE_IsConnected?: boolean;
48
46
 
49
47
  // Config
50
48
  botMode!: string;
51
49
  allowPush?: boolean;
52
50
  doublePress!: number;
53
- pushRatePress!: number;
54
51
  scanDuration!: number;
52
+ pushRatePress!: number;
55
53
  deviceLogging!: string;
56
- deviceRefreshRate!: number;
57
- // Multi-Press
58
54
  multiPressCount!: number;
55
+ deviceRefreshRate!: number;
59
56
 
60
57
  // Updates
61
58
  botUpdateInProgress!: boolean;
@@ -348,19 +345,14 @@ export class Bot {
348
345
  }
349
346
 
350
347
  // Battery Service
351
- if (!this.batteryService) {
352
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
353
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
354
- `${accessory.displayName} Battery`;
355
-
356
- this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
357
- if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
358
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
359
- }
360
- this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
361
- } else {
362
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
348
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
349
+ `${accessory.displayName} Battery`;
350
+
351
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
352
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
353
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
363
354
  }
355
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
364
356
 
365
357
  // Retrieve initial values and updateHomekit
366
358
  this.updateHomeKitCharacteristics();
@@ -424,19 +416,19 @@ export class Bot {
424
416
  async BLEparseStatus(): Promise<void> {
425
417
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
426
418
  // BLEmode (true if Switch Mode) | (false if Press Mode)
427
- if (this.mode) {
419
+ if (this.BLE_Mode) {
428
420
  this.accessory.context.On = this.On;
429
421
  if (this.On === undefined) {
430
- this.On = Boolean(this.state);
422
+ this.On = Boolean(this.BLE_On);
431
423
  }
432
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`);
424
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, mode: ${this.BLE_Mode}, On: ${this.On}`);
433
425
  } else {
434
426
  this.On = false;
435
427
  this.accessory.context.On = this.On;
436
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`);
428
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode, mode: ${this.BLE_Mode}, On: ${this.On}`);
437
429
  }
438
430
 
439
- this.BatteryLevel = Number(this.battery);
431
+ this.BatteryLevel = Number(this.BLE_BatteryLevel);
440
432
  if (this.BatteryLevel < 10) {
441
433
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
442
434
  } else {
@@ -462,7 +454,7 @@ export class Bot {
462
454
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
463
455
 
464
456
  // Battery
465
- this.BatteryLevel = Number(this.Battery);
457
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
466
458
  if (this.BatteryLevel < 10) {
467
459
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
468
460
  } else {
@@ -513,28 +505,26 @@ export class Bot {
513
505
  .then(async () => {
514
506
  // Set an event hander
515
507
  switchbot.onadvertisement = async (ad: ad) => {
516
- this.address = ad.address;
517
508
  this.debugLog(
518
509
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
519
- ` BLE Address Found: ${this.address}`,
510
+ ` BLE Address Found: ${ad.address}`,
520
511
  );
521
- this.serviceData = ad.serviceData;
522
- this.mode = ad.serviceData.mode;
523
- this.state = ad.serviceData.state;
524
- this.battery = ad.serviceData.battery;
512
+ this.BLE_Mode = ad.serviceData.mode;
513
+ this.BLE_On = ad.serviceData.state;
514
+ this.BLE_BatteryLevel = ad.serviceData.battery;
525
515
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
526
516
  this.debugLog(
527
517
  `${this.device.deviceType}: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ` +
528
518
  `${ad.serviceData.modelName}, mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
529
519
  );
530
520
 
531
- if (this.serviceData) {
532
- this.connected = true;
533
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
521
+ if (ad.serviceData) {
522
+ this.BLE_IsConnected = true;
523
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
534
524
  await this.stopScanning(switchbot);
535
525
  } else {
536
- this.connected = false;
537
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
526
+ this.BLE_IsConnected = false;
527
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
538
528
  }
539
529
  };
540
530
  // Wait
@@ -569,9 +559,9 @@ export class Bot {
569
559
  this.statusCode(statusCode);
570
560
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
571
561
  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;
562
+ this.OpenAPI_On = deviceStatus.body.power;
563
+ this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
564
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
575
565
  this.openAPIparseStatus();
576
566
  this.updateHomeKitCharacteristics();
577
567
  } else {
@@ -1002,6 +992,8 @@ export class Bot {
1002
992
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
1003
993
  }
1004
994
  }
995
+ this.accessory.context.On = this.On;
996
+ // Battery
1005
997
  if (this.BatteryLevel === undefined) {
1006
998
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
1007
999
  } else {
@@ -1016,8 +1008,16 @@ export class Bot {
1016
1008
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
1017
1009
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1018
1010
  }
1019
-
1020
- this.accessory.context.On = this.On;
1011
+ // FirmwareRevision
1012
+ if (this.OpenAPI_FirmwareRevision === undefined) {
1013
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
1014
+ } else {
1015
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
1016
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
1017
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
1018
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
1019
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
1020
+ }
1021
1021
  }
1022
1022
 
1023
1023
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
@@ -1121,7 +1121,7 @@ export class Bot {
1121
1121
 
1122
1122
  async stopScanning(switchbot: any) {
1123
1123
  await switchbot.stopScan();
1124
- if (this.connected) {
1124
+ if (this.BLE_IsConnected) {
1125
1125
  await this.BLEparseStatus();
1126
1126
  await this.updateHomeKitCharacteristics();
1127
1127
  } else {
@@ -5,7 +5,7 @@ import { sleep } from '../utils';
5
5
  import { interval, Subject } from 'rxjs';
6
6
  import { SwitchBotPlatform } from '../platform';
7
7
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
- import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
8
+ import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
9
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
10
 
11
11
  /**
@@ -24,22 +24,20 @@ export class CeilingLight {
24
24
  Brightness!: CharacteristicValue;
25
25
  ColorTemperature?: CharacteristicValue;
26
26
 
27
- // OpenAPI Others
28
- Version: deviceStatus['version'];
29
- power: deviceStatus['power'];
30
- color: deviceStatus['color'];
31
- brightness: deviceStatus['brightness'];
32
- colorTemperature?: deviceStatus['colorTemperature'];
33
- deviceStatus!: any;
27
+ // OpenAPI Status
28
+ OpenAPI_On: deviceStatus['power'];
29
+ OpenAPI_RGB: deviceStatus['color'];
30
+ OpenAPI_Brightness: deviceStatus['brightness'];
31
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
32
+ OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
33
+
34
+ // BLE Status
35
+ BLE_Delay: serviceData['delay'];
36
+ BLE_On: serviceData['state'];
37
+ BLE_WifiRssi: serviceData['wifiRssi'];
34
38
 
35
39
  // BLE Others
36
- connected?: boolean;
37
- switchbot!: switchbot;
38
- address!: ad['address'];
39
- serviceData!: serviceData;
40
- state: serviceData['state'];
41
- delay: serviceData['delay'];
42
- wifiRssi: serviceData['wifiRssi'];
40
+ BLE_IsConnected?: boolean;
43
41
 
44
42
  // Config
45
43
  set_minStep?: number;
@@ -252,7 +250,7 @@ export class CeilingLight {
252
250
  async BLEparseStatus(): Promise<void> {
253
251
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
254
252
  // State
255
- switch (this.state) {
253
+ switch (this.BLE_On) {
256
254
  case 'on':
257
255
  this.On = true;
258
256
  break;
@@ -264,7 +262,7 @@ export class CeilingLight {
264
262
 
265
263
  async openAPIparseStatus() {
266
264
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
267
- switch (this.power) {
265
+ switch (this.OpenAPI_On) {
268
266
  case 'on':
269
267
  this.On = true;
270
268
  break;
@@ -274,13 +272,13 @@ export class CeilingLight {
274
272
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
275
273
 
276
274
  // Brightness
277
- this.Brightness = Number(this.brightness);
275
+ this.Brightness = Number(this.OpenAPI_Brightness);
278
276
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
279
277
 
280
278
  // Color, Hue & Brightness
281
- if (this.color) {
282
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
283
- const [red, green, blue] = this.color!.split(':');
279
+ if (this.OpenAPI_RGB) {
280
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
281
+ const [red, green, blue] = this.OpenAPI_RGB!.split(':');
284
282
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
285
283
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
286
284
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
@@ -300,9 +298,9 @@ export class CeilingLight {
300
298
  }
301
299
 
302
300
  // ColorTemperature
303
- if (!Number.isNaN(this.colorTemperature)) {
304
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
305
- const mired = Math.round(1000000 / this.colorTemperature!);
301
+ if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
302
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
303
+ const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
306
304
 
307
305
  this.ColorTemperature = Number(mired);
308
306
 
@@ -349,15 +347,13 @@ export class CeilingLight {
349
347
  })
350
348
  .then(async () => {
351
349
  // Set an event hander
352
- switchbot.onadvertisement = async (ad: any) => {
353
- this.address = ad.address;
350
+ switchbot.onadvertisement = async (ad: ad) => {
354
351
  this.debugLog(
355
352
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
356
- ` BLE Address Found: ${this.address}`,
353
+ ` BLE Address Found: ${ad.address}`,
357
354
  );
358
355
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
359
- this.serviceData = ad.serviceData;
360
- //this.state = ad.serviceData.state;
356
+ this.BLE_On = ad.serviceData.state;
361
357
  //this.delay = ad.serviceData.delay;
362
358
  //this.timer = ad.serviceData.timer;
363
359
  //this.syncUtcTime = ad.serviceData.syncUtcTime;
@@ -371,13 +367,13 @@ export class CeilingLight {
371
367
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
372
368
  );*/
373
369
 
374
- if (this.serviceData) {
375
- this.connected = true;
376
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
370
+ if (ad.serviceData) {
371
+ this.BLE_IsConnected = true;
372
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
377
373
  await this.stopScanning(switchbot);
378
374
  } else {
379
- this.connected = false;
380
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
375
+ this.BLE_IsConnected = false;
376
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
381
377
  }
382
378
  };
383
379
  // Wait
@@ -411,10 +407,11 @@ export class CeilingLight {
411
407
  this.statusCode(statusCode);
412
408
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
413
409
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
414
- this.power = deviceStatus.body.power;
415
- this.color = deviceStatus.body.color;
416
- this.brightness = deviceStatus.body.brightness;
417
- this.colorTemperature = deviceStatus.body.colorTemperature;
410
+ this.OpenAPI_On = deviceStatus.body.power;
411
+ this.OpenAPI_RGB = deviceStatus.body.color;
412
+ this.OpenAPI_Brightness = deviceStatus.body.brightness;
413
+ this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
414
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
418
415
  this.openAPIparseStatus();
419
416
  this.updateHomeKitCharacteristics();
420
417
  } catch (e: any) {
@@ -802,6 +799,16 @@ export class CeilingLight {
802
799
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
803
800
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
804
801
  }
802
+ // FirmwareRevision
803
+ if (this.OpenAPI_FirmwareRevision === undefined) {
804
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
805
+ } else {
806
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
807
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
808
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
809
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
810
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
811
+ }
805
812
  }
806
813
 
807
814
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -816,7 +823,7 @@ export class CeilingLight {
816
823
 
817
824
  async stopScanning(switchbot: any) {
818
825
  await switchbot.stopScan();
819
- if (this.connected) {
826
+ if (this.BLE_IsConnected) {
820
827
  await this.BLEparseStatus();
821
828
  await this.updateHomeKitCharacteristics();
822
829
  } else {
@@ -5,7 +5,7 @@ import { sleep } from '../utils';
5
5
  import { interval, Subject } from 'rxjs';
6
6
  import { SwitchBotPlatform } from '../platform';
7
7
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
- import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
8
+ import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
9
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
10
 
11
11
  /**
@@ -24,32 +24,26 @@ export class ColorBulb {
24
24
  Brightness!: CharacteristicValue;
25
25
  ColorTemperature?: CharacteristicValue;
26
26
 
27
- // OpenAPI Others
28
- Version: deviceStatus['version'];
29
- power: deviceStatus['power'];
30
- color: deviceStatus['color'];
31
- brightness: deviceStatus['brightness'];
32
- colorTemperature?: deviceStatus['colorTemperature'];
33
- deviceStatus!: any;
27
+ // OpenAPI Status
28
+ OpenAPI_On: deviceStatus['power'];
29
+ OpenAPI_RGB: deviceStatus['color'];
30
+ OpenAPI_Brightness: deviceStatus['brightness'];
31
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
32
+ OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
33
+
34
+ // BLE Status
35
+ BLE_Red: serviceData['red'];
36
+ BLE_On: serviceData['state'];
37
+ BLE_Blue: serviceData['blue'];
38
+ BLE_Power: serviceData['power'];
39
+ BLE_Green: serviceData['green'];
40
+ BLE_Delay: serviceData['delay'];
41
+ BLE_WifiRssi: serviceData['wifiRssi'];
42
+ BLE_Brightness: serviceData['brightness'];
43
+ BLE_ColorTemperature: serviceData['color_temperature'];
34
44
 
35
45
  // BLE Others
36
- connected?: boolean;
37
- switchbot!: switchbot;
38
- address!: ad['address'];
39
- serviceData!: serviceData;
40
- powerState: serviceData['power'];
41
- state: serviceData['state'];
42
- red: serviceData['red'];
43
- green: serviceData['green'];
44
- blue: serviceData['blue'];
45
- delay: serviceData['delay'];
46
- wifiRssi: serviceData['wifiRssi'];
47
- brightnessBLE: serviceData['brightness'];
48
- color_temperature: serviceData['color_temperature'];
49
- preset: any; //serviceData['preset'];
50
- color_mode: any; //serviceData['color_mode'];
51
- speed: any; //serviceData['speed'];
52
- loop_index: any; //serviceData['loop_index'];
46
+ BLE_IsConnected?: boolean;
53
47
 
54
48
  // Config
55
49
  set_minStep?: number;
@@ -250,7 +244,7 @@ export class ColorBulb {
250
244
  async BLEparseStatus(): Promise<void> {
251
245
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
252
246
  // State
253
- switch (this.state) {
247
+ switch (this.BLE_On) {
254
248
  case true:
255
249
  this.On = true;
256
250
  break;
@@ -260,18 +254,18 @@ export class ColorBulb {
260
254
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
261
255
 
262
256
  // Brightness
263
- this.Brightness = Number(this.brightnessBLE);
257
+ this.Brightness = Number(this.BLE_Brightness);
264
258
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
265
259
 
266
260
  // Color, Hue & Brightness
267
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.red}`);
268
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.green}`);
269
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.blue}`);
261
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.BLE_Red}`);
262
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.BLE_Green}`);
263
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.BLE_Blue}`);
270
264
 
271
- const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
265
+ const [hue, saturation] = rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue));
272
266
  this.debugLog(
273
267
  `${this.device.deviceType}: ${this.accessory.displayName}` +
274
- ` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`,
268
+ ` hs: ${JSON.stringify(rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue)))}`,
275
269
  );
276
270
 
277
271
  // Hue
@@ -283,9 +277,9 @@ export class ColorBulb {
283
277
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
284
278
 
285
279
  // ColorTemperature
286
- if (this.color_temperature) {
287
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.color_temperature}`);
288
- this.ColorTemperature = this.color_temperature!;
280
+ if (this.BLE_ColorTemperature) {
281
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.BLE_ColorTemperature}`);
282
+ this.ColorTemperature = this.BLE_ColorTemperature!;
289
283
 
290
284
  this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
291
285
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
@@ -294,7 +288,7 @@ export class ColorBulb {
294
288
 
295
289
  async openAPIparseStatus() {
296
290
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
297
- switch (this.power) {
291
+ switch (this.OpenAPI_On) {
298
292
  case 'on':
299
293
  this.On = true;
300
294
  break;
@@ -304,13 +298,13 @@ export class ColorBulb {
304
298
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
305
299
 
306
300
  // Brightness
307
- this.Brightness = Number(this.brightness);
301
+ this.Brightness = Number(this.OpenAPI_Brightness);
308
302
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
309
303
 
310
304
  // Color, Hue & Brightness
311
- if (this.color) {
312
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
313
- const [red, green, blue] = this.color!.split(':');
305
+ if (this.OpenAPI_RGB) {
306
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
307
+ const [red, green, blue] = this.OpenAPI_RGB!.split(':');
314
308
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
315
309
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
316
310
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
@@ -330,9 +324,9 @@ export class ColorBulb {
330
324
  }
331
325
 
332
326
  // ColorTemperature
333
- if (!Number.isNaN(this.colorTemperature)) {
334
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
335
- const mired = Math.round(1000000 / this.colorTemperature!);
327
+ if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
328
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
329
+ const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
336
330
 
337
331
  this.ColorTemperature = Number(mired);
338
332
 
@@ -379,26 +373,20 @@ export class ColorBulb {
379
373
  })
380
374
  .then(async () => {
381
375
  // Set an event hander
382
- switchbot.onadvertisement = async (ad: any) => {
383
- this.address = ad.address;
376
+ switchbot.onadvertisement = async (ad: ad) => {
384
377
  this.debugLog(
385
378
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
386
- ` BLE Address Found: ${this.address}`,
379
+ ` BLE Address Found: ${ad.address}`,
387
380
  );
388
381
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
389
- this.serviceData = ad.serviceData;
390
- this.powerState = ad.serviceData.power;
391
- this.state = ad.serviceData.state;
392
- this.red = ad.serviceData.red;
393
- this.green = ad.serviceData.green;
394
- this.blue = ad.serviceData.blue;
395
- this.color_temperature = ad.serviceData.color_temperature;
396
- this.brightnessBLE = ad.serviceData.brightness;
397
- this.delay = ad.serviceData.delay;
398
- this.preset = ad.serviceData.preset;
399
- this.color_mode = ad.serviceData.color_mode;
400
- this.speed = ad.serviceData.speed;
401
- this.loop_index = ad.serviceData.loop_index;
382
+ this.BLE_Power = ad.serviceData.power;
383
+ this.BLE_On = ad.serviceData.state;
384
+ this.BLE_Red = ad.serviceData.red;
385
+ this.BLE_Green = ad.serviceData.green;
386
+ this.BLE_Blue = ad.serviceData.blue;
387
+ this.BLE_ColorTemperature = ad.serviceData.color_temperature;
388
+ this.BLE_Brightness = ad.serviceData.brightness;
389
+ this.BLE_Delay = ad.serviceData.delay;
402
390
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
403
391
  /*this.debugLog(
404
392
  `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
@@ -406,13 +394,13 @@ export class ColorBulb {
406
394
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
407
395
  );*/
408
396
 
409
- if (this.serviceData) {
410
- this.connected = true;
411
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
397
+ if (ad.serviceData) {
398
+ this.BLE_IsConnected = true;
399
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
412
400
  await this.stopScanning(switchbot);
413
401
  } else {
414
- this.connected = false;
415
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
402
+ this.BLE_IsConnected = false;
403
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
416
404
  }
417
405
  };
418
406
  // Wait
@@ -446,10 +434,11 @@ export class ColorBulb {
446
434
  this.statusCode(statusCode);
447
435
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
448
436
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
449
- this.power = deviceStatus.body.power;
450
- this.color = deviceStatus.body.color;
451
- this.brightness = deviceStatus.body.brightness;
452
- this.colorTemperature = deviceStatus.body.colorTemperature;
437
+ this.OpenAPI_On = deviceStatus.body.power;
438
+ this.OpenAPI_RGB = deviceStatus.body.color;
439
+ this.OpenAPI_Brightness = deviceStatus.body.brightness;
440
+ this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
441
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
453
442
  this.openAPIparseStatus();
454
443
  this.updateHomeKitCharacteristics();
455
444
  } catch (e: any) {
@@ -973,6 +962,16 @@ export class ColorBulb {
973
962
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
974
963
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
975
964
  }
965
+ // FirmwareRevision
966
+ if (this.OpenAPI_FirmwareRevision === undefined) {
967
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
968
+ } else {
969
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
970
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
971
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
972
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
973
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
974
+ }
976
975
  }
977
976
 
978
977
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -987,7 +986,7 @@ export class ColorBulb {
987
986
 
988
987
  async stopScanning(switchbot: any) {
989
988
  await switchbot.stopScan();
990
- if (this.connected) {
989
+ if (this.BLE_IsConnected) {
991
990
  await this.BLEparseStatus();
992
991
  await this.updateHomeKitCharacteristics();
993
992
  } else {