@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';
@@ -68,25 +66,14 @@ export class RobotVacuumCleaner {
68
66
  .getService(this.platform.Service.AccessoryInformation)!
69
67
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
70
68
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
71
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
72
-
73
- if (accessory.context.FirmwareRevision) {
74
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
75
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
76
- accessory
77
- .getService(this.platform.Service.AccessoryInformation)!
78
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
79
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
80
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
81
- .updateValue(accessory.context.FirmwareRevision);
82
- } else {
83
- this.setFirmwareRevision(accessory, device);
84
- }
69
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
70
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
85
71
 
86
72
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
87
73
  // you can create multiple services for each accessory
88
- (this.robotVacuumCleanerService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
89
- `${device.deviceName} ${device.deviceType}`;
74
+ const robotVacuumCleanerService = `${accessory.displayName} ${device.deviceType}`;
75
+ (this.robotVacuumCleanerService = accessory.getService(this.platform.Service.Lightbulb)
76
+ || accessory.addService(this.platform.Service.Lightbulb)), robotVacuumCleanerService;
90
77
 
91
78
  this.robotVacuumCleanerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
92
79
  if (!this.robotVacuumCleanerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -114,8 +101,9 @@ export class RobotVacuumCleaner {
114
101
  .onSet(this.BrightnessSet.bind(this));
115
102
 
116
103
  // Battery Service
117
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
118
- `${accessory.displayName} Battery`;
104
+ const batteryService = `${accessory.displayName} Battery`;
105
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
106
+ || accessory.addService(this.platform.Service.Battery)), batteryService;
119
107
 
120
108
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
121
109
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -166,9 +154,9 @@ export class RobotVacuumCleaner {
166
154
  async parseStatus(): Promise<void> {
167
155
  if (!this.device.enableCloudService && this.OpenAPI) {
168
156
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
169
- } /*if (this.BLE) {
170
- await this.BLEparseStatus();
171
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
157
+ /*} else if (this.BLE) {
158
+ await this.BLEparseStatus();*/
159
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
172
160
  await this.openAPIparseStatus();
173
161
  } else {
174
162
  await this.offlineOff();
@@ -213,6 +201,7 @@ export class RobotVacuumCleaner {
213
201
 
214
202
  // FirmwareRevision
215
203
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
204
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
216
205
  }
217
206
 
218
207
  /**
@@ -221,9 +210,9 @@ export class RobotVacuumCleaner {
221
210
  async refreshStatus(): Promise<void> {
222
211
  if (!this.device.enableCloudService && this.OpenAPI) {
223
212
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
224
- } /*if (this.BLE) {
225
- await this.BLERefreshStatus();
226
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
213
+ /*} else if (this.BLE) {
214
+ await this.BLERefreshStatus();*/
215
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
227
216
  await this.openAPIRefreshStatus();
228
217
  } else {
229
218
  await this.offlineOff();
@@ -341,9 +330,9 @@ export class RobotVacuumCleaner {
341
330
  async pushChanges(): Promise<void> {
342
331
  if (!this.device.enableCloudService && this.OpenAPI) {
343
332
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
344
- } /* if (this.BLE) {
345
- await this.BLEpushChanges();
346
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
333
+ /*} else if (this.BLE) {
334
+ await this.BLEpushChanges();*/
335
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
347
336
  await this.openAPIpushChanges();
348
337
  } else {
349
338
  await this.offlineOff();
@@ -599,16 +588,6 @@ export class RobotVacuumCleaner {
599
588
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
600
589
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
601
590
  }
602
- // FirmwareRevision
603
- if (this.FirmwareRevision === undefined) {
604
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
605
- } else {
606
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
607
- this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
608
- this.robotVacuumCleanerService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
609
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
610
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
611
- }
612
591
  }
613
592
 
614
593
  async stopScanning(switchbot: any) {
@@ -761,32 +740,6 @@ export class RobotVacuumCleaner {
761
740
  this.robotVacuumCleanerService.updateCharacteristic(this.platform.Characteristic.On, e);
762
741
  }
763
742
 
764
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
765
- await this.refreshStatus();
766
- if (device.firmware) {
767
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
768
- accessory.context.FirmwareRevision = device.firmware;
769
- this.FirmwareRevision = accessory.context.FirmwareRevision;
770
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
771
- } else if (device.version) {
772
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
773
- accessory.context.FirmwareRevision = device.version;
774
- this.FirmwareRevision = accessory.context.FirmwareRevision;
775
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
776
- } else {
777
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
778
- accessory.context.FirmwareRevision = this.platform.version;
779
- this.FirmwareRevision = accessory.context.FirmwareRevision;
780
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
781
- }
782
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
783
- accessory
784
- .getService(this.platform.Service.AccessoryInformation)!
785
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
786
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
787
- .updateValue(this.FirmwareRevision);
788
- }
789
-
790
743
  async context() {
791
744
  if (this.On === undefined) {
792
745
  this.On = false;
@@ -62,25 +62,14 @@ export class AirConditioner {
62
62
  .getService(this.platform.Service.AccessoryInformation)!
63
63
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
64
64
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
65
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
66
-
67
- if (accessory.context.FirmwareRevision) {
68
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
69
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
70
- accessory
71
- .getService(this.platform.Service.AccessoryInformation)!
72
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
73
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
74
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
75
- .updateValue(accessory.context.FirmwareRevision);
76
- } else {
77
- this.setFirmwareRevision(accessory, device);
78
- }
65
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
66
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
79
67
 
80
68
  // get the Television service if it exists, otherwise create a new Television service
81
69
  // you can create multiple services for each accessory
82
- (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
83
- `${accessory.displayName} ${device.remoteType}`;
70
+ const coolerService = `${accessory.displayName} ${device.remoteType}`;
71
+ (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler)
72
+ || accessory.addService(this.platform.Service.HeaterCooler)), coolerService;
84
73
 
85
74
  this.coolerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
86
75
  if (!this.coolerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -524,16 +513,6 @@ export class AirConditioner {
524
513
  `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
525
514
  );
526
515
  }
527
- // FirmwareRevision
528
- if (this.FirmwareRevision === undefined) {
529
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
530
- } else {
531
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
532
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
533
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
534
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
535
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
536
- }
537
516
  }
538
517
 
539
518
  async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
@@ -641,26 +620,6 @@ export class AirConditioner {
641
620
  this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
642
621
  }
643
622
 
644
- async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
645
- if (device.firmware) {
646
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
647
- accessory.context.FirmwareRevision = device.firmware;
648
- this.FirmwareRevision = accessory.context.FirmwareRevision;
649
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
650
- } else {
651
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
652
- accessory.context.FirmwareRevision = this.platform.version;
653
- this.FirmwareRevision = accessory.context.FirmwareRevision;
654
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
655
- }
656
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
657
- accessory
658
- .getService(this.platform.Service.AccessoryInformation)!
659
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
660
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
661
- .updateValue(this.FirmwareRevision);
662
- }
663
-
664
623
  async context(): Promise<void> {
665
624
  if (this.Active === undefined) {
666
625
  this.Active = this.platform.Characteristic.Active.INACTIVE;
@@ -703,6 +662,10 @@ export class AirConditioner {
703
662
  this.CurrentRelativeHumidity = this.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
704
663
  }
705
664
  }
665
+ if (this.FirmwareRevision === undefined) {
666
+ this.FirmwareRevision = this.platform.version;
667
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
668
+ }
706
669
  }
707
670
 
708
671
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -56,25 +56,14 @@ export class AirPurifier {
56
56
  .getService(this.platform.Service.AccessoryInformation)!
57
57
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
58
58
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
59
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
60
-
61
- if (accessory.context.FirmwareRevision) {
62
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
63
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
64
- accessory
65
- .getService(this.platform.Service.AccessoryInformation)!
66
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
67
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
68
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
69
- .updateValue(accessory.context.FirmwareRevision);
70
- } else {
71
- this.setFirmwareRevision(accessory, device);
72
- }
59
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
60
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
73
61
 
74
62
  // get the Television service if it exists, otherwise create a new Television service
75
63
  // you can create multiple services for each accessory
76
- (this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier) || accessory.addService(this.platform.Service.AirPurifier)),
77
- `${accessory.displayName} Air Purifier`;
64
+ const airPurifierService = `${accessory.displayName} Air Purifier`;
65
+ (this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier)
66
+ || accessory.addService(this.platform.Service.AirPurifier)), airPurifierService;
78
67
 
79
68
  this.airPurifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
80
69
  if (!this.airPurifierService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -283,16 +272,6 @@ export class AirPurifier {
283
272
  ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
284
273
  );
285
274
  }
286
- // FirmwareRevision
287
- if (this.FirmwareRevision === undefined) {
288
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
289
- } else {
290
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
291
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
292
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
293
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
294
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
295
- }
296
275
  }
297
276
 
298
277
  async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
@@ -388,28 +367,6 @@ export class AirPurifier {
388
367
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
389
368
  }
390
369
 
391
-
392
-
393
- async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
394
- if (device.firmware) {
395
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
396
- accessory.context.FirmwareRevision = device.firmware;
397
- this.FirmwareRevision = accessory.context.FirmwareRevision;
398
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
399
- } else {
400
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
401
- accessory.context.FirmwareRevision = this.platform.version;
402
- this.FirmwareRevision = accessory.context.FirmwareRevision;
403
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
404
- }
405
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
406
- accessory
407
- .getService(this.platform.Service.AccessoryInformation)!
408
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
409
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
410
- .updateValue(this.FirmwareRevision);
411
- }
412
-
413
370
  private context() {
414
371
  if (this.Active === undefined) {
415
372
  this.Active = this.platform.Characteristic.Active.INACTIVE;
@@ -421,6 +378,10 @@ export class AirPurifier {
421
378
  } else {
422
379
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
423
380
  }
381
+ if (this.FirmwareRevision === undefined) {
382
+ this.FirmwareRevision = this.platform.version;
383
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
384
+ }
424
385
  }
425
386
 
426
387
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -38,25 +38,14 @@ export class Camera {
38
38
  .getService(this.platform.Service.AccessoryInformation)!
39
39
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
40
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
42
-
43
- if (accessory.context.FirmwareRevision) {
44
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
45
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
46
- accessory
47
- .getService(this.platform.Service.AccessoryInformation)!
48
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
49
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
50
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
51
- .updateValue(accessory.context.FirmwareRevision);
52
- } else {
53
- this.setFirmwareRevision(accessory, device);
54
- }
41
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
55
43
 
56
44
  // get the Television service if it exists, otherwise create a new Television service
57
45
  // you can create multiple services for each accessory
58
- (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
59
- `${accessory.displayName} Camera`;
46
+ const switchService = `${accessory.displayName} Camera`;
47
+ (this.switchService = accessory.getService(this.platform.Service.Switch)
48
+ || accessory.addService(this.platform.Service.Switch)), switchService;
60
49
 
61
50
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
62
51
  if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -167,16 +156,6 @@ export class Camera {
167
156
  this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
168
157
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
169
158
  }
170
- // FirmwareRevision
171
- if (this.FirmwareRevision === undefined) {
172
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
173
- } else {
174
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
175
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
176
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
177
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
178
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
179
- }
180
159
  }
181
160
 
182
161
  async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
@@ -269,34 +248,16 @@ export class Camera {
269
248
  this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
270
249
  }
271
250
 
272
-
273
-
274
- async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
275
- if (device.firmware) {
276
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
277
- accessory.context.FirmwareRevision = device.firmware;
278
- this.FirmwareRevision = accessory.context.FirmwareRevision;
279
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
280
- } else {
281
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
282
- accessory.context.FirmwareRevision = this.platform.version;
283
- this.FirmwareRevision = accessory.context.FirmwareRevision;
284
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
285
- }
286
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
287
- accessory
288
- .getService(this.platform.Service.AccessoryInformation)!
289
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
290
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
291
- .updateValue(this.FirmwareRevision);
292
- }
293
-
294
251
  async context() {
295
252
  if (this.On === undefined) {
296
253
  this.On = false;
297
254
  } else {
298
255
  this.On = this.accessory.context.On;
299
256
  }
257
+ if (this.FirmwareRevision === undefined) {
258
+ this.FirmwareRevision = this.platform.version;
259
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
260
+ }
300
261
  }
301
262
 
302
263
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -45,25 +45,14 @@ export class Fan {
45
45
  .getService(this.platform.Service.AccessoryInformation)!
46
46
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
47
47
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
48
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
49
-
50
- if (accessory.context.FirmwareRevision) {
51
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
52
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
53
- accessory
54
- .getService(this.platform.Service.AccessoryInformation)!
55
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
56
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
57
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
58
- .updateValue(accessory.context.FirmwareRevision);
59
- } else {
60
- this.setFirmwareRevision(accessory, device);
61
- }
48
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
49
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
62
50
 
63
51
  // get the Television service if it exists, otherwise create a new Television service
64
52
  // you can create multiple services for each accessory
65
- (this.fanService = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
66
- `${accessory.displayName} Fan`;
53
+ const fanService = `${accessory.displayName} Fan`;
54
+ (this.fanService = accessory.getService(this.platform.Service.Fanv2)
55
+ || accessory.addService(this.platform.Service.Fanv2)), fanService;
67
56
 
68
57
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
69
58
  if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -297,16 +286,6 @@ export class Fan {
297
286
  this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
298
287
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
299
288
  }
300
- // FirmwareRevision
301
- if (this.FirmwareRevision === undefined) {
302
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
303
- } else {
304
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
305
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
306
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
307
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
308
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
309
- }
310
289
  }
311
290
 
312
291
  async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
@@ -401,34 +380,16 @@ export class Fan {
401
380
  this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
402
381
  }
403
382
 
404
-
405
-
406
- async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
407
- if (device.firmware) {
408
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
409
- accessory.context.FirmwareRevision = device.firmware;
410
- this.FirmwareRevision = accessory.context.FirmwareRevision;
411
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
412
- } else {
413
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
414
- accessory.context.FirmwareRevision = this.platform.version;
415
- this.FirmwareRevision = accessory.context.FirmwareRevision;
416
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
417
- }
418
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
419
- accessory
420
- .getService(this.platform.Service.AccessoryInformation)!
421
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
422
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
423
- .updateValue(this.FirmwareRevision);
424
- }
425
-
426
383
  async context() {
427
384
  if (this.Active === undefined) {
428
385
  this.Active = this.platform.Characteristic.Active.INACTIVE;
429
386
  } else {
430
387
  this.Active = this.accessory.context.Active;
431
388
  }
389
+ if (this.FirmwareRevision === undefined) {
390
+ this.FirmwareRevision = this.platform.version;
391
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
392
+ }
432
393
  }
433
394
 
434
395
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -38,25 +38,14 @@ export class Light {
38
38
  .getService(this.platform.Service.AccessoryInformation)!
39
39
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
40
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
42
-
43
- if (accessory.context.FirmwareRevision) {
44
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
45
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
46
- accessory
47
- .getService(this.platform.Service.AccessoryInformation)!
48
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
49
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
50
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
51
- .updateValue(accessory.context.FirmwareRevision);
52
- } else {
53
- this.setFirmwareRevision(accessory, device);
54
- }
41
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
55
43
 
56
44
  // get the Light service if it exists, otherwise create a new Light service
57
45
  // you can create multiple services for each accessory
58
- (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
59
- `${accessory.displayName} ${device.remoteType}`;
46
+ const lightBulbService = `${accessory.displayName} ${device.remoteType}`;
47
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb)
48
+ || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService;
60
49
 
61
50
  this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
62
51
  if (!this.lightBulbService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -192,16 +181,6 @@ export class Light {
192
181
  this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
193
182
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
194
183
  }
195
- // FirmwareRevision
196
- if (this.FirmwareRevision === undefined) {
197
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
198
- } else {
199
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
200
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
201
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
202
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
203
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
204
- }
205
184
  }
206
185
 
207
186
  async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
@@ -294,34 +273,16 @@ export class Light {
294
273
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
295
274
  }
296
275
 
297
-
298
-
299
- async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
300
- if (device.firmware) {
301
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
302
- accessory.context.FirmwareRevision = device.firmware;
303
- this.FirmwareRevision = accessory.context.FirmwareRevision;
304
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
305
- } else {
306
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
307
- accessory.context.FirmwareRevision = this.platform.version;
308
- this.FirmwareRevision = accessory.context.FirmwareRevision;
309
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
310
- }
311
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
312
- accessory
313
- .getService(this.platform.Service.AccessoryInformation)!
314
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
315
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
316
- .updateValue(this.FirmwareRevision);
317
- }
318
-
319
276
  async context() {
320
277
  if (this.On === undefined) {
321
278
  this.On = false;
322
279
  } else {
323
280
  this.On = this.accessory.context.On;
324
281
  }
282
+ if (this.FirmwareRevision === undefined) {
283
+ this.FirmwareRevision = this.platform.version;
284
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
285
+ }
325
286
  }
326
287
 
327
288
  async config(device: irdevice & irDevicesConfig): Promise<void> {