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

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 (112) 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 +8 -13
  39. package/dist/device/lightstrip.d.ts.map +1 -1
  40. package/dist/device/lightstrip.js +28 -25
  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 +75 -26
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts +16 -21
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +40 -37
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts +16 -21
  51. package/dist/device/meterplus.d.ts.map +1 -1
  52. package/dist/device/meterplus.js +40 -37
  53. package/dist/device/meterplus.js.map +1 -1
  54. package/dist/device/motion.d.ts +12 -21
  55. package/dist/device/motion.d.ts.map +1 -1
  56. package/dist/device/motion.js +44 -46
  57. package/dist/device/motion.js.map +1 -1
  58. package/dist/device/plug.d.ts +5 -15
  59. package/dist/device/plug.d.ts.map +1 -1
  60. package/dist/device/plug.js +22 -19
  61. package/dist/device/plug.js.map +1 -1
  62. package/dist/device/robotvacuumcleaner.d.ts +9 -13
  63. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  64. package/dist/device/robotvacuumcleaner.js +30 -28
  65. package/dist/device/robotvacuumcleaner.js.map +1 -1
  66. package/dist/irdevice/airconditioner.d.ts +4 -4
  67. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  68. package/dist/irdevice/camera.d.ts +1 -1
  69. package/dist/irdevice/camera.d.ts.map +1 -1
  70. package/dist/irdevice/fan.d.ts +3 -4
  71. package/dist/irdevice/fan.d.ts.map +1 -1
  72. package/dist/irdevice/fan.js.map +1 -1
  73. package/dist/irdevice/light.d.ts +1 -1
  74. package/dist/irdevice/light.d.ts.map +1 -1
  75. package/dist/irdevice/other.d.ts +2 -2
  76. package/dist/irdevice/other.d.ts.map +1 -1
  77. package/dist/irdevice/tv.d.ts +1 -2
  78. package/dist/irdevice/tv.d.ts.map +1 -1
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/waterheater.d.ts +1 -1
  83. package/dist/irdevice/waterheater.d.ts.map +1 -1
  84. package/dist/settings.d.ts +3 -1
  85. package/dist/settings.d.ts.map +1 -1
  86. package/dist/settings.js.map +1 -1
  87. package/package.json +5 -5
  88. package/src/device/blindtilt.ts +96 -95
  89. package/src/device/bot.ts +54 -54
  90. package/src/device/ceilinglight.ts +46 -39
  91. package/src/device/colorbulb.ts +68 -69
  92. package/src/device/contact.ts +69 -77
  93. package/src/device/curtain.ts +75 -74
  94. package/src/device/hub.ts +53 -38
  95. package/src/device/humidifier.ts +33 -26
  96. package/src/device/iosensor.ts +53 -48
  97. package/src/device/lightstrip.ts +39 -40
  98. package/src/device/lock.ts +94 -49
  99. package/src/device/meter.ts +59 -59
  100. package/src/device/meterplus.ts +59 -60
  101. package/src/device/motion.ts +61 -65
  102. package/src/device/plug.ts +27 -35
  103. package/src/device/robotvacuumcleaner.ts +43 -43
  104. package/src/irdevice/airconditioner.ts +4 -4
  105. package/src/irdevice/camera.ts +1 -1
  106. package/src/irdevice/fan.ts +3 -6
  107. package/src/irdevice/light.ts +1 -1
  108. package/src/irdevice/other.ts +2 -2
  109. package/src/irdevice/tv.ts +1 -4
  110. package/src/irdevice/vacuumcleaner.ts +1 -1
  111. package/src/irdevice/waterheater.ts +1 -1
  112. package/src/settings.ts +5 -1
@@ -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 {