@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge SwitchBot",
3
3
  "name": "@switchbot/homebridge-switchbot",
4
- "version": "2.9.1-beta.3",
4
+ "version": "2.9.1",
5
5
  "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
6
6
  "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
7
7
  "license": "ISC",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "engines": {
16
16
  "homebridge": "^1.6.1",
17
- "node": "^16.20.2 || ^18.17.1 || ^20.5.1"
17
+ "node": "^18.18.2 || ^20.8.1"
18
18
  },
19
19
  "main": "dist/index.js",
20
20
  "scripts": {
@@ -57,11 +57,10 @@
57
57
  "dependencies": {
58
58
  "@homebridge/plugin-ui-utils": "^0.1.0",
59
59
  "async-mqtt": "^2.6.3",
60
- "crypto-js": "^4.1.1",
61
60
  "fakegato-history": "^0.6.4",
62
61
  "homebridge-lib": "^6.6.1",
63
62
  "rxjs": "^7.8.1",
64
- "undici": "^5.25.4"
63
+ "undici": "^5.26.3"
65
64
  },
66
65
  "optionalDependencies": {
67
66
  "@abandonware/bluetooth-hci-socket": "^0.5.3-10",
@@ -69,19 +68,15 @@
69
68
  "node-switchbot": "^1.9.0"
70
69
  },
71
70
  "devDependencies": {
72
- "@types/crypto-js": "^4.1.2",
73
- "@types/node": "^20.8.2",
74
- "@typescript-eslint/eslint-plugin": "^6.7.4",
75
- "@typescript-eslint/parser": "^6.7.4",
76
- "eslint": "^8.50.0",
77
- "eslint-config-prettier": "9.0.0",
78
- "eslint-plugin-prettier": "5.0.0",
71
+ "@types/node": "^20.8.6",
72
+ "@typescript-eslint/eslint-plugin": "^6.7.5",
73
+ "@typescript-eslint/parser": "^6.7.5",
74
+ "eslint": "^8.51.0",
79
75
  "homebridge": "^1.6.1",
80
76
  "nodemon": "^3.0.1",
81
- "npm-check-updates": "^16.14.4",
82
- "prettier": "3.0.3",
77
+ "npm-check-updates": "^16.14.6",
83
78
  "rimraf": "^5.0.5",
84
79
  "ts-node": "^10.9.1",
85
80
  "typescript": "^5.2.2"
86
81
  }
87
- }
82
+ }
@@ -1,4 +1,3 @@
1
- import { Context } from 'vm';
2
1
  import { request } from 'undici';
3
2
  import { sleep } from '../utils';
4
3
  import { MqttClient } from 'mqtt';
@@ -114,26 +113,15 @@ export class BlindTilt {
114
113
  .getService(this.platform.Service.AccessoryInformation)!
115
114
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
116
115
  .setCharacteristic(this.platform.Characteristic.Model, 'W2701600')
117
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
118
-
119
- if (accessory.context.FirmwareRevision) {
120
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
121
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
122
- accessory
123
- .getService(this.platform.Service.AccessoryInformation)!
124
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
125
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
126
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
127
- .updateValue(accessory.context.FirmwareRevision);
128
- } else {
129
- this.setFirmwareRevision(accessory, device);
130
- }
116
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
117
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
131
118
 
132
119
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
133
120
  // you can create multiple services for each accessory
121
+ const windowCoveringService = `${device.deviceName} ${device.deviceType}`;
134
122
  (this.windowCoveringService =
135
- accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
136
- `${device.deviceName} ${device.deviceType}`;
123
+ accessory.getService(this.platform.Service.WindowCovering)
124
+ || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService;
137
125
 
138
126
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
139
127
  if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -191,8 +179,9 @@ export class BlindTilt {
191
179
  .onSet(this.TargetHorizontalTiltAngleSet.bind(this));
192
180
 
193
181
  // Battery Service
194
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
195
- `${accessory.displayName} Battery`;
182
+ const batteryService = `${accessory.displayName} Battery`;
183
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
184
+ || accessory.addService(this.platform.Service.Battery)), batteryService;
196
185
 
197
186
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
198
187
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -451,10 +440,11 @@ export class BlindTilt {
451
440
  this.BatteryLevel = 100;
452
441
  }
453
442
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
454
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
443
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
455
444
 
456
445
  // FirmwareRevision
457
446
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
447
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
458
448
  }
459
449
 
460
450
  async refreshStatus(): Promise<void> {
@@ -897,22 +887,6 @@ export class BlindTilt {
897
887
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
898
888
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
899
889
  }
900
- // FirmwareRevision
901
- if (this.FirmwareRevision === undefined) {
902
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
903
- } else {
904
- if (this.device.mqttURL) {
905
- this.mqttPublish('FirmwareRevision', this.FirmwareRevision);
906
- }
907
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
908
- this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
909
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
910
- if (!this.device.blindTilt?.hide_lightsensor) {
911
- this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
912
- }
913
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
914
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
915
- }
916
890
  }
917
891
 
918
892
  /*
@@ -1145,32 +1119,6 @@ export class BlindTilt {
1145
1119
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1146
1120
  }
1147
1121
 
1148
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
1149
- await this.refreshStatus();
1150
- if (device.firmware) {
1151
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1152
- accessory.context.FirmwareRevision = device.firmware;
1153
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1154
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
1155
- } else if (device.version) {
1156
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
1157
- accessory.context.FirmwareRevision = device.version;
1158
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1159
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
1160
- } else {
1161
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1162
- accessory.context.FirmwareRevision = this.platform.version;
1163
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1164
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
1165
- }
1166
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
1167
- accessory
1168
- .getService(this.platform.Service.AccessoryInformation)!
1169
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
1170
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
1171
- .updateValue(this.FirmwareRevision);
1172
- }
1173
-
1174
1122
  async context() {
1175
1123
  if (this.CurrentPosition === undefined) {
1176
1124
  this.CurrentPosition = 0;
@@ -1189,6 +1137,10 @@ export class BlindTilt {
1189
1137
  } else {
1190
1138
  this.PositionState = this.accessory.context.PositionState;
1191
1139
  }
1140
+ if (this.FirmwareRevision === undefined) {
1141
+ this.FirmwareRevision = this.platform.version;
1142
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1143
+ }
1192
1144
  }
1193
1145
 
1194
1146
  /**
package/src/device/bot.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Context } from 'vm';
2
1
  import { request } from 'undici';
3
2
  import { sleep } from '../utils';
4
3
  import { interval, Subject } from 'rxjs';
@@ -94,20 +93,8 @@ export class Bot {
94
93
  .getService(this.platform.Service.AccessoryInformation)!
95
94
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
96
95
  .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
97
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
98
-
99
- if (accessory.context.FirmwareRevision) {
100
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
101
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
102
- accessory
103
- .getService(this.platform.Service.AccessoryInformation)!
104
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
105
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
106
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
107
- .updateValue(accessory.context.FirmwareRevision);
108
- } else {
109
- this.setFirmwareRevision(accessory, device);
110
- }
96
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
97
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
111
98
 
112
99
  // deviceType
113
100
  if (this.botDeviceType === 'switch') {
@@ -122,8 +109,9 @@ export class Bot {
122
109
  this.removeStatefulProgrammableSwitchService(accessory);
123
110
 
124
111
  // Add switchService
125
- (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
126
- `${accessory.displayName} Switch`;
112
+ const switchService = `${accessory.displayName} Switch`;
113
+ (this.switchService = accessory.getService(this.platform.Service.Switch)
114
+ || accessory.addService(this.platform.Service.Switch)), switchService;
127
115
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
128
116
 
129
117
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -142,10 +130,10 @@ export class Bot {
142
130
  this.removeWindowCoveringService(accessory);
143
131
  this.removeStatefulProgrammableSwitchService(accessory);
144
132
 
145
- // Add switchService
146
- (this.garageDoorService =
147
- accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
148
- `${accessory.displayName} Garage Door Opener`;
133
+ // Add garageDoorService
134
+ const garageDoorService = `${accessory.displayName} Garage Door Opener`;
135
+ (this.garageDoorService = accessory.getService(this.platform.Service.GarageDoorOpener)
136
+ || accessory.addService(this.platform.Service.GarageDoorOpener)), garageDoorService;
149
137
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
150
138
 
151
139
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -165,9 +153,10 @@ export class Bot {
165
153
  this.removeWindowCoveringService(accessory);
166
154
  this.removeStatefulProgrammableSwitchService(accessory);
167
155
 
168
- // Add switchService
169
- (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
170
- `${accessory.displayName} Door`;
156
+ // Add doorService
157
+ const doorService = `${accessory.displayName} Door`;
158
+ (this.doorService = accessory.getService(this.platform.Service.Door)
159
+ || accessory.addService(this.platform.Service.Door)), doorService;
171
160
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
172
161
 
173
162
  this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -195,9 +184,10 @@ export class Bot {
195
184
  this.removeWindowCoveringService(accessory);
196
185
  this.removeStatefulProgrammableSwitchService(accessory);
197
186
 
198
- // Add switchService
199
- (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
200
- `${accessory.displayName} Window`;
187
+ // Add windowService
188
+ const windowService = `${accessory.displayName} Window`;
189
+ (this.windowService = accessory.getService(this.platform.Service.Window)
190
+ || accessory.addService(this.platform.Service.Window)), windowService;
201
191
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
202
192
 
203
193
  this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -225,10 +215,10 @@ export class Bot {
225
215
  this.removeGarageDoorService(accessory);
226
216
  this.removeStatefulProgrammableSwitchService(accessory);
227
217
 
228
- // Add switchService
229
- (this.windowCoveringService =
230
- accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
231
- `${accessory.displayName} Window Covering`;
218
+ // Add windowCoveringService
219
+ const windowCoveringService = `${accessory.displayName} Window Covering`;
220
+ (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering)
221
+ || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService;
232
222
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
233
223
 
234
224
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -256,9 +246,10 @@ export class Bot {
256
246
  this.removeWindowCoveringService(accessory);
257
247
  this.removeStatefulProgrammableSwitchService(accessory);
258
248
 
259
- // Add switchService
260
- (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
261
- `${accessory.displayName} Lock`;
249
+ // Add lockService
250
+ const lockService = `${accessory.displayName} Lock`;
251
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism)
252
+ || accessory.addService(this.platform.Service.LockMechanism)), lockService;
262
253
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
263
254
 
264
255
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -277,9 +268,10 @@ export class Bot {
277
268
  this.removeWindowCoveringService(accessory);
278
269
  this.removeStatefulProgrammableSwitchService(accessory);
279
270
 
280
- // Add switchService
281
- (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
282
- `${accessory.displayName} Faucet`;
271
+ // Add faucetService
272
+ const faucetService = `${accessory.displayName} Faucet`;
273
+ (this.faucetService = accessory.getService(this.platform.Service.Faucet)
274
+ || accessory.addService(this.platform.Service.Faucet)), faucetService;
283
275
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
284
276
 
285
277
  this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -298,9 +290,10 @@ export class Bot {
298
290
  this.removeWindowCoveringService(accessory);
299
291
  this.removeStatefulProgrammableSwitchService(accessory);
300
292
 
301
- // Add switchService
302
- (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
303
- `${accessory.displayName} Fan`;
293
+ // Add fanService
294
+ const fanService = `${accessory.displayName} Fan`;
295
+ (this.fanService = accessory.getService(this.platform.Service.Fan)
296
+ || accessory.addService(this.platform.Service.Fan)), fanService;
304
297
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
305
298
 
306
299
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -319,11 +312,10 @@ export class Bot {
319
312
  this.removeGarageDoorService(accessory);
320
313
  this.removeWindowCoveringService(accessory);
321
314
 
322
- // Add switchService
323
- (this.statefulProgrammableSwitchService =
324
- accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
325
- accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
326
- `${accessory.displayName} Stateful Programmable Switch`;
315
+ // Add statefulProgrammableSwitchService
316
+ const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
317
+ (this.statefulProgrammableSwitchService = accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
318
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
327
319
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
328
320
 
329
321
  this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -345,8 +337,9 @@ export class Bot {
345
337
  this.removeStatefulProgrammableSwitchService(accessory);
346
338
 
347
339
  // Add outletService
348
- (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
349
- `${accessory.displayName} Outlet`;
340
+ const outletService = `${accessory.displayName} Outlet`;
341
+ (this.outletService = accessory.getService(this.platform.Service.Outlet)
342
+ || accessory.addService(this.platform.Service.Outlet)), outletService;
350
343
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
351
344
 
352
345
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -356,9 +349,10 @@ export class Bot {
356
349
  this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
357
350
  }
358
351
 
359
- // Battery Service
360
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
361
- `${accessory.displayName} Battery`;
352
+ // batteryService
353
+ const batteryService = `${accessory.displayName} Battery`;
354
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
355
+ || accessory.addService(this.platform.Service.Battery)), batteryService;
362
356
 
363
357
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
364
358
  if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
@@ -450,7 +444,7 @@ export class Bot {
450
444
  this.BatteryLevel = 100;
451
445
  }
452
446
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
453
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
447
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
454
448
  }
455
449
 
456
450
  async openAPIparseStatus(): Promise<void> {
@@ -477,10 +471,11 @@ export class Bot {
477
471
  this.BatteryLevel = 100;
478
472
  }
479
473
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
480
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
474
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
481
475
 
482
476
  // FirmwareRevision
483
477
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
478
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
484
479
  }
485
480
 
486
481
  /**
@@ -1042,36 +1037,6 @@ export class Bot {
1042
1037
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
1043
1038
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1044
1039
  }
1045
- // FirmwareRevision
1046
- if (this.FirmwareRevision === undefined) {
1047
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
1048
- } else {
1049
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1050
- this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1051
- if (this.botDeviceType === 'garagedoor') {
1052
- this.garageDoorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1053
- } else if (this.botDeviceType === 'door') {
1054
- this.doorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1055
- } else if (this.botDeviceType === 'window') {
1056
- this.windowService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1057
- } else if (this.botDeviceType === 'windowcovering') {
1058
- this.windowCoveringService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1059
- } else if (this.botDeviceType === 'lock') {
1060
- this.lockService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1061
- } else if (this.botDeviceType === 'faucet') {
1062
- this.faucetService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1063
- } else if (this.botDeviceType === 'fan') {
1064
- this.fanService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1065
- } else if (this.botDeviceType === 'stateful') {
1066
- this.statefulProgrammableSwitchService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1067
- } else if (this.botDeviceType === 'switch') {
1068
- this.switchService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1069
- } else {
1070
- this.outletService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
1071
- }
1072
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
1073
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
1074
- }
1075
1040
  }
1076
1041
 
1077
1042
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
@@ -1363,32 +1328,6 @@ export class Bot {
1363
1328
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1364
1329
  }
1365
1330
 
1366
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
1367
- await this.refreshStatus();
1368
- if (device.firmware) {
1369
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1370
- accessory.context.FirmwareRevision = device.firmware;
1371
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1372
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
1373
- } else if (device.version) {
1374
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
1375
- accessory.context.FirmwareRevision = device.version;
1376
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1377
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
1378
- } else {
1379
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1380
- accessory.context.FirmwareRevision = this.platform.version;
1381
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1382
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
1383
- }
1384
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
1385
- accessory
1386
- .getService(this.platform.Service.AccessoryInformation)!
1387
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
1388
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
1389
- .updateValue(this.FirmwareRevision);
1390
- }
1391
-
1392
1331
  async deviceType(device: device & devicesConfig): Promise<void> {
1393
1332
  if (!device.bot?.deviceType && this.accessory.context.deviceType) {
1394
1333
  this.botDeviceType = this.accessory.context.deviceType;
@@ -1423,6 +1362,10 @@ export class Bot {
1423
1362
  } else {
1424
1363
  this.StatusLowBattery = this.accessory.context.StatusLowBattery;
1425
1364
  }
1365
+ if (this.FirmwareRevision === undefined) {
1366
+ this.FirmwareRevision = this.platform.version;
1367
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1368
+ }
1426
1369
  }
1427
1370
 
1428
1371
  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';
@@ -88,25 +86,14 @@ export class CeilingLight {
88
86
  .getService(this.platform.Service.AccessoryInformation)!
89
87
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
90
88
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
91
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
92
-
93
- if (accessory.context.FirmwareRevision) {
94
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
95
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
96
- accessory
97
- .getService(this.platform.Service.AccessoryInformation)!
98
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
99
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
100
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
101
- .updateValue(accessory.context.FirmwareRevision);
102
- } else {
103
- this.setFirmwareRevision(accessory, device);
104
- }
89
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
90
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
105
91
 
106
92
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
107
93
  // you can create multiple services for each accessory
108
- (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
109
- `${accessory.displayName} ${device.deviceType}`;
94
+ const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
95
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb)
96
+ || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService;
110
97
 
111
98
  if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
112
99
  this.accessory.removeService(this.lightBulbService);
@@ -242,7 +229,7 @@ export class CeilingLight {
242
229
  }
243
230
  /*if (this.BLE) {
244
231
  await this.BLEparseStatus();
245
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
232
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
246
233
  await this.openAPIparseStatus();
247
234
  } else {
248
235
  await this.offlineOff();
@@ -315,6 +302,7 @@ export class CeilingLight {
315
302
 
316
303
  // FirmwareRevision
317
304
  this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
305
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
318
306
  }
319
307
 
320
308
  /**
@@ -323,9 +311,9 @@ export class CeilingLight {
323
311
  async refreshStatus(): Promise<void> {
324
312
  if (!this.device.enableCloudService && this.OpenAPI) {
325
313
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
326
- } /*if (this.BLE) {
327
- await this.BLERefreshStatus();
328
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
314
+ /*} else if (this.BLE) {
315
+ await this.BLERefreshStatus();*/
316
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
329
317
  await this.openAPIRefreshStatus();
330
318
  } else {
331
319
  await this.offlineOff();
@@ -454,9 +442,9 @@ export class CeilingLight {
454
442
  async pushChanges(): Promise<void> {
455
443
  if (!this.device.enableCloudService && this.OpenAPI) {
456
444
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
457
- } /*if (this.BLE) {
458
- await this.BLEpushChanges();
459
- } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
445
+ /*} else if (this.BLE) {
446
+ await this.BLEpushChanges();*/
447
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
460
448
  await this.openAPIpushChanges();
461
449
  } else {
462
450
  await this.offlineOff();
@@ -856,16 +844,6 @@ export class CeilingLight {
856
844
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
857
845
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
858
846
  }
859
-
860
- // FirmwareRevision
861
- if (this.FirmwareRevision === undefined) {
862
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
863
- } else {
864
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
865
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
866
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
867
- + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
868
- }
869
847
  }
870
848
 
871
849
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -1022,32 +1000,6 @@ export class CeilingLight {
1022
1000
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
1023
1001
  }
1024
1002
 
1025
- async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
1026
- await this.refreshStatus();
1027
- if (device.firmware) {
1028
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1029
- accessory.context.FirmwareRevision = device.firmware;
1030
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1031
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
1032
- } else if (device.version) {
1033
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
1034
- accessory.context.FirmwareRevision = device.version;
1035
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1036
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
1037
- } else {
1038
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1039
- accessory.context.FirmwareRevision = this.platform.version;
1040
- this.FirmwareRevision = accessory.context.FirmwareRevision;
1041
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
1042
- }
1043
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
1044
- accessory
1045
- .getService(this.platform.Service.AccessoryInformation)!
1046
- .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
1047
- .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
1048
- .updateValue(this.FirmwareRevision);
1049
- }
1050
-
1051
1003
  async context() {
1052
1004
  if (this.On === undefined) {
1053
1005
  this.On = false;
@@ -1076,6 +1028,10 @@ export class CeilingLight {
1076
1028
  }
1077
1029
  this.minKelvin = 2000;
1078
1030
  this.maxKelvin = 9000;
1031
+ if (this.FirmwareRevision === undefined) {
1032
+ this.FirmwareRevision = this.platform.version;
1033
+ this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1034
+ }
1079
1035
  }
1080
1036
 
1081
1037
  async refreshRate(device: device & devicesConfig): Promise<void> {