@switchbot/homebridge-switchbot 2.9.1-beta.3 → 2.9.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 (135) hide show
  1. package/.eslintrc +47 -14
  2. package/.vscode/settings.json +7 -1
  3. package/CHANGELOG.md +79 -70
  4. package/SECURITY.md +2 -2
  5. package/config.schema.json +348 -114
  6. package/dist/device/blindtilt.d.ts +0 -3
  7. package/dist/device/blindtilt.d.ts.map +1 -1
  8. package/dist/device/blindtilt.js +13 -62
  9. package/dist/device/blindtilt.js.map +1 -1
  10. package/dist/device/bot.d.ts +0 -3
  11. package/dist/device/bot.d.ts.map +1 -1
  12. package/dist/device/bot.js +49 -116
  13. package/dist/device/bot.js.map +1 -1
  14. package/dist/device/ceilinglight.d.ts +0 -3
  15. package/dist/device/ceilinglight.d.ts.map +1 -1
  16. package/dist/device/ceilinglight.js +17 -60
  17. package/dist/device/ceilinglight.js.map +1 -1
  18. package/dist/device/colorbulb.d.ts +0 -3
  19. package/dist/device/colorbulb.d.ts.map +1 -1
  20. package/dist/device/colorbulb.js +13 -56
  21. package/dist/device/colorbulb.js.map +1 -1
  22. package/dist/device/contact.d.ts +0 -3
  23. package/dist/device/contact.d.ts.map +1 -1
  24. package/dist/device/contact.js +19 -69
  25. package/dist/device/contact.js.map +1 -1
  26. package/dist/device/curtain.d.ts +0 -3
  27. package/dist/device/curtain.d.ts.map +1 -1
  28. package/dist/device/curtain.js +16 -66
  29. package/dist/device/curtain.js.map +1 -1
  30. package/dist/device/hub.d.ts +1 -4
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +16 -69
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +0 -3
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +16 -63
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +0 -3
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +16 -65
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +0 -3
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +13 -56
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +0 -3
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +22 -68
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +0 -3
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +16 -68
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +1 -4
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +16 -69
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +0 -3
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +12 -62
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +0 -3
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +6 -53
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +0 -3
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +18 -65
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/irdevice/airconditioner.d.ts +0 -1
  71. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  72. package/dist/irdevice/airconditioner.js +9 -47
  73. package/dist/irdevice/airconditioner.js.map +1 -1
  74. package/dist/irdevice/airpurifier.d.ts +0 -1
  75. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  76. package/dist/irdevice/airpurifier.js +9 -47
  77. package/dist/irdevice/airpurifier.js.map +1 -1
  78. package/dist/irdevice/camera.d.ts +0 -1
  79. package/dist/irdevice/camera.d.ts.map +1 -1
  80. package/dist/irdevice/camera.js +9 -47
  81. package/dist/irdevice/camera.js.map +1 -1
  82. package/dist/irdevice/fan.d.ts +0 -1
  83. package/dist/irdevice/fan.d.ts.map +1 -1
  84. package/dist/irdevice/fan.js +9 -47
  85. package/dist/irdevice/fan.js.map +1 -1
  86. package/dist/irdevice/light.d.ts +0 -1
  87. package/dist/irdevice/light.d.ts.map +1 -1
  88. package/dist/irdevice/light.js +9 -47
  89. package/dist/irdevice/light.js.map +1 -1
  90. package/dist/irdevice/other.d.ts +0 -1
  91. package/dist/irdevice/other.d.ts.map +1 -1
  92. package/dist/irdevice/other.js +44 -77
  93. package/dist/irdevice/other.js.map +1 -1
  94. package/dist/irdevice/tv.d.ts +0 -1
  95. package/dist/irdevice/tv.d.ts.map +1 -1
  96. package/dist/irdevice/tv.js +18 -56
  97. package/dist/irdevice/tv.js.map +1 -1
  98. package/dist/irdevice/vacuumcleaner.d.ts +0 -1
  99. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  100. package/dist/irdevice/vacuumcleaner.js +9 -47
  101. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  102. package/dist/irdevice/waterheater.d.ts +0 -1
  103. package/dist/irdevice/waterheater.d.ts.map +1 -1
  104. package/dist/irdevice/waterheater.js +9 -47
  105. package/dist/irdevice/waterheater.js.map +1 -1
  106. package/nodemon.json +4 -2
  107. package/package.json +9 -14
  108. package/src/device/blindtilt.ts +14 -62
  109. package/src/device/bot.ts +51 -108
  110. package/src/device/ceilinglight.ts +17 -61
  111. package/src/device/colorbulb.ts +13 -56
  112. package/src/device/contact.ts +20 -69
  113. package/src/device/curtain.ts +17 -66
  114. package/src/device/hub.ts +16 -70
  115. package/src/device/humidifier.ts +16 -64
  116. package/src/device/iosensor.ts +17 -66
  117. package/src/device/lightstrip.ts +13 -56
  118. package/src/device/lock.ts +22 -69
  119. package/src/device/meter.ts +18 -69
  120. package/src/device/meterplus.ts +17 -70
  121. package/src/device/motion.ts +13 -62
  122. package/src/device/plug.ts +6 -52
  123. package/src/device/robotvacuumcleaner.ts +18 -65
  124. package/src/irdevice/airconditioner.ts +9 -46
  125. package/src/irdevice/airpurifier.ts +9 -48
  126. package/src/irdevice/camera.ts +9 -48
  127. package/src/irdevice/fan.ts +9 -48
  128. package/src/irdevice/light.ts +9 -48
  129. package/src/irdevice/other.ts +44 -78
  130. package/src/irdevice/tv.ts +18 -57
  131. package/src/irdevice/vacuumcleaner.ts +9 -48
  132. package/src/irdevice/waterheater.ts +9 -48
  133. package/tsconfig.json +16 -4
  134. package/.github/npm-version-script.js +0 -81
  135. package/.prettierrc +0 -9
@@ -1,5 +1,3 @@
1
- /* eslint-disable brace-style */
2
- import { Context } from 'vm';
3
1
  import { request } from 'undici';
4
2
  import { sleep } from '../utils';
5
3
  import { interval, Subject } from 'rxjs';
@@ -81,26 +79,14 @@ export class Humidifier {
81
79
  .getService(this.platform.Service.AccessoryInformation)!
82
80
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
83
81
  .setCharacteristic(this.platform.Characteristic.Model, 'W0801800')
84
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
85
-
86
- if (accessory.context.FirmwareRevision) {
87
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
88
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
89
- accessory
90
- .getService(this.platform.Service.AccessoryInformation)!
91
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
92
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
93
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
94
- .updateValue(accessory.context.FirmwareRevision);
95
- } else {
96
- this.setFirmwareRevision(accessory, device);
97
- }
82
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
83
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
98
84
 
99
85
  // get the service if it exists, otherwise create a new service
100
86
  // you can create multiple services for each accessory
101
- (this.humidifierService =
102
- accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
103
- `${accessory.displayName} Humidifier`;
87
+ const humidifierService = `${accessory.displayName} Humidifier`;
88
+ (this.humidifierService = accessory.getService(this.platform.Service.HumidifierDehumidifier)
89
+ || accessory.addService(this.platform.Service.HumidifierDehumidifier)), humidifierService;
104
90
 
105
91
  this.humidifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
106
92
  if (!this.humidifierService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -145,9 +131,9 @@ export class Humidifier {
145
131
  accessory.removeService(this.temperatureservice!);
146
132
  } else if (!this.temperatureservice && !this.BLE) {
147
133
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
148
- (this.temperatureservice =
149
- this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
150
- `${accessory.displayName} Temperature Sensor`;
134
+ const temperatureservice = `${accessory.displayName} Temperature Sensor`;
135
+ (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor)
136
+ || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureservice;
151
137
 
152
138
  this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
153
139
  if (!this.temperatureservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -294,6 +280,7 @@ export class Humidifier {
294
280
 
295
281
  // FirmwareRevision
296
282
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
283
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
297
284
  }
298
285
 
299
286
  /**
@@ -421,9 +408,9 @@ export class Humidifier {
421
408
  async pushChanges(): Promise<void> {
422
409
  if (!this.device.enableCloudService && this.OpenAPI) {
423
410
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
424
- } /*if (this.BLE) {
425
- await this.BLEpushChanges();
426
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
411
+ /*} else if (this.BLE) {
412
+ await this.BLEpushChanges();*/
413
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
427
414
  await this.openAPIpushChanges();
428
415
  } else {
429
416
  await this.offlineOff();
@@ -747,19 +734,6 @@ export class Humidifier {
747
734
  this.accessory.context.CurrentTemperature = this.CurrentTemperature;
748
735
  }
749
736
  }
750
-
751
- // FirmwareRevision
752
- if (this.FirmwareRevision === undefined) {
753
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
754
- } else {
755
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
756
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
757
- if (!this.device.humidifier?.hide_temperature) {
758
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
759
- }
760
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
761
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
762
- }
763
737
  }
764
738
 
765
739
  async stopScanning(switchbot: any) {
@@ -895,32 +869,6 @@ export class Humidifier {
895
869
  }
896
870
  }
897
871
 
898
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
899
- await this.refreshStatus();
900
- if (device.firmware) {
901
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
902
- accessory.context.FirmwareRevision = device.firmware;
903
- this.FirmwareRevision = accessory.context.FirmwareRevision;
904
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
905
- } else if (device.version) {
906
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
907
- accessory.context.FirmwareRevision = device.version;
908
- this.FirmwareRevision = accessory.context.FirmwareRevision;
909
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
910
- } else {
911
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
912
- accessory.context.FirmwareRevision = this.platform.version;
913
- this.FirmwareRevision = accessory.context.FirmwareRevision;
914
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
915
- }
916
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
917
- accessory
918
- .getService(this.platform.Service.AccessoryInformation)!
919
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
920
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
921
- .updateValue(this.FirmwareRevision);
922
- }
923
-
924
872
  async context() {
925
873
  if (this.Active === undefined) {
926
874
  this.Active = this.platform.Characteristic.Active.ACTIVE;
@@ -961,6 +909,10 @@ export class Humidifier {
961
909
  } else {
962
910
  this.WaterLevel = this.accessory.context.WaterLevel;
963
911
  }
912
+ if (this.FirmwareRevision === undefined) {
913
+ this.FirmwareRevision = this.platform.version;
914
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
915
+ }
964
916
  }
965
917
 
966
918
  async refreshRate(device: device & devicesConfig): Promise<void> {
@@ -1,4 +1,3 @@
1
- import { Context } from 'vm';
2
1
  import { hostname } from 'os';
3
2
  import { request } from 'undici';
4
3
  import { sleep } from '../utils';
@@ -89,20 +88,8 @@ export class IOSensor {
89
88
  .getService(this.platform.Service.AccessoryInformation)!
90
89
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
91
90
  .setCharacteristic(this.platform.Characteristic.Model, 'WoIOSensor')
92
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
93
-
94
- if (accessory.context.FirmwareRevision) {
95
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
96
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
97
- accessory
98
- .getService(this.platform.Service.AccessoryInformation)!
99
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
100
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
101
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
102
- .updateValue(accessory.context.FirmwareRevision);
103
- } else {
104
- this.setFirmwareRevision(accessory, device);
105
- }
91
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
92
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
106
93
 
107
94
  // Temperature Sensor Service
108
95
  if (device.meter?.hide_temperature) {
@@ -111,9 +98,9 @@ export class IOSensor {
111
98
  accessory.removeService(this.temperatureservice!);
112
99
  } else if (!this.temperatureservice) {
113
100
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
114
- (this.temperatureservice =
115
- this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
116
- `${accessory.displayName} Temperature Sensor`;
101
+ const temperatureservice = `${accessory.displayName} Temperature Sensor`;
102
+ (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor)
103
+ || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureservice;
117
104
 
118
105
  this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
119
106
  if (!this.temperatureservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -142,9 +129,9 @@ export class IOSensor {
142
129
  accessory.removeService(this.humidityservice!);
143
130
  } else if (!this.humidityservice) {
144
131
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
145
- (this.humidityservice =
146
- this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
147
- `${accessory.displayName} Humidity Sensor`;
132
+ const humidityservice = `${accessory.displayName} Humidity Sensor`;
133
+ (this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor)
134
+ || this.accessory.addService(this.platform.Service.HumiditySensor)), humidityservice;
148
135
 
149
136
  this.humidityservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
150
137
  if (!this.humidityservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -163,8 +150,9 @@ export class IOSensor {
163
150
  }
164
151
 
165
152
  // Battery Service
166
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
167
- `${accessory.displayName} Battery`;
153
+ const batteryService = `${accessory.displayName} Battery`;
154
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
155
+ || accessory.addService(this.platform.Service.Battery)), batteryService;
168
156
 
169
157
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
170
158
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -261,10 +249,11 @@ export class IOSensor {
261
249
  this.BatteryLevel = 100;
262
250
  }
263
251
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
264
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
252
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
265
253
 
266
254
  // FirmwareRevision
267
255
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
256
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
268
257
  }
269
258
 
270
259
  /**
@@ -457,22 +446,6 @@ export class IOSensor {
457
446
  this.historyService?.addEntry(entry);
458
447
  }
459
448
  }
460
-
461
- // FirmwareRevision
462
- if (this.FirmwareRevision === undefined) {
463
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
464
- } else {
465
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
466
- this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
467
- if (this.device.meter?.hide_humidity) {
468
- this.humidityservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
469
- }
470
- if (this.device.meter?.hide_temperature) {
471
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
472
- }
473
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
474
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
475
- }
476
449
  }
477
450
 
478
451
  /*
@@ -634,32 +607,6 @@ export class IOSensor {
634
607
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
635
608
  }
636
609
 
637
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
638
- await this.refreshStatus();
639
- if (device.firmware) {
640
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
641
- accessory.context.FirmwareRevision = device.firmware;
642
- this.FirmwareRevision = accessory.context.FirmwareRevision;
643
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
644
- } else if (device.version) {
645
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
646
- accessory.context.FirmwareRevision = device.version;
647
- this.FirmwareRevision = accessory.context.FirmwareRevision;
648
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
649
- } else {
650
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
651
- accessory.context.FirmwareRevision = this.platform.version;
652
- this.FirmwareRevision = accessory.context.FirmwareRevision;
653
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
654
- }
655
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
656
- accessory
657
- .getService(this.platform.Service.AccessoryInformation)!
658
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
659
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
660
- .updateValue(this.FirmwareRevision);
661
- }
662
-
663
610
  async context() {
664
611
  if (this.CurrentRelativeHumidity === undefined) {
665
612
  this.CurrentRelativeHumidity = 0;
@@ -682,6 +629,10 @@ export class IOSensor {
682
629
  } else {
683
630
  this.StatusLowBattery = this.accessory.context.StatusLowBattery;
684
631
  }
632
+ if (this.FirmwareRevision === undefined) {
633
+ this.FirmwareRevision = this.platform.version;
634
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
635
+ }
685
636
  }
686
637
 
687
638
  async refreshRate(device: device & devicesConfig): Promise<void> {
@@ -1,5 +1,3 @@
1
- /* eslint-disable brace-style */
2
- import { Context } from 'vm';
3
1
  import { request } from 'undici';
4
2
  import { sleep } from '../utils';
5
3
  import { interval, Subject } from 'rxjs';
@@ -86,25 +84,14 @@ export class StripLight {
86
84
  .getService(this.platform.Service.AccessoryInformation)!
87
85
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
88
86
  .setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
89
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
90
-
91
- if (accessory.context.FirmwareRevision) {
92
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
93
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
94
- accessory
95
- .getService(this.platform.Service.AccessoryInformation)!
96
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
97
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
98
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
99
- .updateValue(accessory.context.FirmwareRevision);
100
- } else {
101
- this.setFirmwareRevision(accessory, device);
102
- }
87
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
88
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
103
89
 
104
90
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
105
91
  // you can create multiple services for each accessory
106
- (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
107
- `${accessory.displayName} ${device.deviceType}`;
92
+ const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
93
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb)
94
+ || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService;
108
95
 
109
96
  if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
110
97
  this.accessory.removeService(this.lightBulbService);
@@ -289,6 +276,7 @@ export class StripLight {
289
276
 
290
277
  // FirmwareRevision
291
278
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
279
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
292
280
  }
293
281
 
294
282
  /**
@@ -419,9 +407,9 @@ export class StripLight {
419
407
  async pushChanges(): Promise<void> {
420
408
  if (!this.device.enableCloudService && this.OpenAPI) {
421
409
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
422
- } /*if (this.BLE) {
423
- await this.BLEpushChanges();
424
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
410
+ /* }else if (this.BLE) {
411
+ await this.BLEpushChanges();*/
412
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
425
413
  await this.openAPIpushChanges();
426
414
  } else {
427
415
  await this.offlineOff();
@@ -870,15 +858,6 @@ export class StripLight {
870
858
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
871
859
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
872
860
  }
873
- // FirmwareRevision
874
- if (this.FirmwareRevision === undefined) {
875
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
876
- } else {
877
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
878
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
879
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
880
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
881
- }
882
861
  }
883
862
 
884
863
  async stopScanning(switchbot: any) {
@@ -1034,32 +1013,6 @@ export class StripLight {
1034
1013
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
1035
1014
  }
1036
1015
 
1037
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
1038
- await this.refreshStatus();
1039
- if (device.firmware) {
1040
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1041
- accessory.context.FirmwareRevision = device.firmware;
1042
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1043
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
1044
- } else if (device.version) {
1045
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
1046
- accessory.context.FirmwareRevision = device.version;
1047
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1048
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
1049
- } else {
1050
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1051
- accessory.context.FirmwareRevision = this.platform.version;
1052
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1053
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
1054
- }
1055
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
1056
- accessory
1057
- .getService(this.platform.Service.AccessoryInformation)!
1058
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
1059
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
1060
- .updateValue(this.FirmwareRevision);
1061
- }
1062
-
1063
1016
  async context() {
1064
1017
  if (this.On === undefined) {
1065
1018
  this.On = false;
@@ -1088,6 +1041,10 @@ export class StripLight {
1088
1041
  }
1089
1042
  this.minKelvin = 2000;
1090
1043
  this.maxKelvin = 9000;
1044
+ if (this.FirmwareRevision === undefined) {
1045
+ this.FirmwareRevision = this.platform.version;
1046
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1047
+ }
1091
1048
  }
1092
1049
 
1093
1050
  async refreshRate(device: device & devicesConfig): Promise<void> {
@@ -1,5 +1,3 @@
1
- /* eslint-disable brace-style */
2
- import { Context } from 'vm';
3
1
  import { request } from 'undici';
4
2
  import { sleep } from '../utils';
5
3
  import { interval, Subject } from 'rxjs';
@@ -74,25 +72,14 @@ export class Lock {
74
72
  .getService(this.platform.Service.AccessoryInformation)!
75
73
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
76
74
  .setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
77
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
78
-
79
- if (accessory.context.FirmwareRevision) {
80
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
81
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
82
- accessory
83
- .getService(this.platform.Service.AccessoryInformation)!
84
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
85
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
86
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
87
- .updateValue(accessory.context.FirmwareRevision);
88
- } else {
89
- this.setFirmwareRevision(accessory, device);
90
- }
75
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
76
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
91
77
 
92
78
  // get the LockMechanism service if it exists, otherwise create a new LockMechanism service
93
79
  // you can create multiple services for each accessory
94
- (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
95
- `${device.deviceName} ${device.deviceType}`;
80
+ const lockService = `${accessory.displayName} ${device.deviceType}`;
81
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism)
82
+ || accessory.addService(this.platform.Service.LockMechanism)), lockService;
96
83
 
97
84
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
98
85
  if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -112,9 +99,9 @@ export class Lock {
112
99
  accessory.removeService(this.contactSensorService!);
113
100
  } else if (!this.contactSensorService) {
114
101
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
115
- (this.contactSensorService =
116
- this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)),
117
- `${accessory.displayName} Contact Sensor`;
102
+ const contactSensorService = `${accessory.displayName} Contact Sensor`;
103
+ (this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor)
104
+ || this.accessory.addService(this.platform.Service.ContactSensor)), contactSensorService;
118
105
 
119
106
  this.contactSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
120
107
  if (!this.contactSensorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -125,8 +112,9 @@ export class Lock {
125
112
  }
126
113
 
127
114
  // Battery Service
128
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
129
- `${accessory.displayName} Battery`;
115
+ const batteryService = `${accessory.displayName} Battery`;
116
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
117
+ || accessory.addService(this.platform.Service.Battery)), batteryService;
130
118
 
131
119
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
132
120
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -173,9 +161,9 @@ export class Lock {
173
161
  async parseStatus(): Promise<void> {
174
162
  if (!this.device.enableCloudService && this.OpenAPI) {
175
163
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
176
- } /*if (this.BLE) {
177
- await this.BLEparseStatus();
178
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
164
+ /* } else if (this.BLE) {
165
+ await this.BLEparseStatus();*/
166
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
179
167
  await this.openAPIparseStatus();
180
168
  } else {
181
169
  await this.offlineOff();
@@ -251,6 +239,7 @@ export class Lock {
251
239
 
252
240
  // FirmwareRevision
253
241
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
242
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
254
243
  }
255
244
 
256
245
  /**
@@ -380,9 +369,9 @@ export class Lock {
380
369
  async pushChanges(): Promise<void> {
381
370
  if (!this.device.enableCloudService && this.OpenAPI) {
382
371
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
383
- } /*if (this.BLE) {
384
- await this.BLEpushChanges();
385
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
372
+ /*} else if (this.BLE) {
373
+ await this.BLEpushChanges();*/
374
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
386
375
  await this.openAPIpushChanges();
387
376
  } else {
388
377
  await this.offlineOff();
@@ -542,20 +531,6 @@ export class Lock {
542
531
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
543
532
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
544
533
  }
545
-
546
- // FirmwareRevision
547
- if (this.FirmwareRevision === undefined) {
548
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
549
- } else {
550
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
551
- this.lockService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
552
- this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
553
- if (this.device.lock?.hide_contactsensor) {
554
- this.contactSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
555
- }
556
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
557
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
558
- }
559
534
  }
560
535
 
561
536
  async stopScanning(switchbot: any) {
@@ -672,38 +647,16 @@ export class Lock {
672
647
  this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
673
648
  }
674
649
 
675
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
676
- await this.refreshStatus();
677
- if (device.firmware) {
678
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
679
- accessory.context.FirmwareRevision = device.firmware;
680
- this.FirmwareRevision = accessory.context.FirmwareRevision;
681
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
682
- } else if (device.version) {
683
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
684
- accessory.context.FirmwareRevision = device.version;
685
- this.FirmwareRevision = accessory.context.FirmwareRevision;
686
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
687
- } else {
688
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
689
- accessory.context.FirmwareRevision = this.platform.version;
690
- this.FirmwareRevision = accessory.context.FirmwareRevision;
691
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
692
- }
693
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
694
- accessory
695
- .getService(this.platform.Service.AccessoryInformation)!
696
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
697
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
698
- .updateValue(this.FirmwareRevision);
699
- }
700
-
701
650
  async context() {
702
651
  if (this.LockTargetState === undefined) {
703
652
  this.LockTargetState = false;
704
653
  } else {
705
654
  this.LockTargetState = this.accessory.context.On;
706
655
  }
656
+ if (this.FirmwareRevision === undefined) {
657
+ this.FirmwareRevision = this.platform.version;
658
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
659
+ }
707
660
  }
708
661
 
709
662
  async refreshRate(device: device & devicesConfig): Promise<void> {