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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/dist/device/blindtilt.d.ts +21 -23
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +71 -73
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +11 -15
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +38 -34
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +10 -14
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +33 -23
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +16 -24
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +49 -43
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +16 -24
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +49 -51
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +21 -26
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +49 -47
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/hub.d.ts +9 -8
  27. package/dist/device/hub.d.ts.map +1 -1
  28. package/dist/device/hub.js +42 -30
  29. package/dist/device/hub.js.map +1 -1
  30. package/dist/device/humidifier.d.ts +8 -10
  31. package/dist/device/humidifier.d.ts.map +1 -1
  32. package/dist/device/humidifier.js +27 -17
  33. package/dist/device/humidifier.js.map +1 -1
  34. package/dist/device/iosensor.d.ts +16 -21
  35. package/dist/device/iosensor.d.ts.map +1 -1
  36. package/dist/device/iosensor.js +35 -26
  37. package/dist/device/iosensor.js.map +1 -1
  38. package/dist/device/lightstrip.d.ts +1 -5
  39. package/dist/device/lightstrip.d.ts.map +1 -1
  40. package/dist/device/lightstrip.js +2 -4
  41. package/dist/device/lightstrip.js.map +1 -1
  42. package/dist/device/lock.d.ts +15 -21
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +64 -26
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts +4 -9
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +8 -16
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts +5 -10
  51. package/dist/device/meterplus.d.ts.map +1 -1
  52. package/dist/device/meterplus.js +8 -16
  53. package/dist/device/meterplus.js.map +1 -1
  54. package/dist/device/motion.d.ts +4 -8
  55. package/dist/device/motion.d.ts.map +1 -1
  56. package/dist/device/motion.js +10 -23
  57. package/dist/device/motion.js.map +1 -1
  58. package/dist/device/plug.d.ts +1 -5
  59. package/dist/device/plug.d.ts.map +1 -1
  60. package/dist/device/plug.js +2 -4
  61. package/dist/device/plug.js.map +1 -1
  62. package/dist/device/robotvacuumcleaner.d.ts +4 -8
  63. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  64. package/dist/device/robotvacuumcleaner.js +7 -16
  65. package/dist/device/robotvacuumcleaner.js.map +1 -1
  66. package/dist/irdevice/fan.d.ts +0 -1
  67. package/dist/irdevice/fan.d.ts.map +1 -1
  68. package/dist/irdevice/fan.js.map +1 -1
  69. package/dist/irdevice/tv.d.ts +0 -1
  70. package/dist/irdevice/tv.d.ts.map +1 -1
  71. package/dist/irdevice/tv.js.map +1 -1
  72. package/dist/settings.d.ts +3 -1
  73. package/dist/settings.d.ts.map +1 -1
  74. package/dist/settings.js.map +1 -1
  75. package/package.json +2 -2
  76. package/src/device/blindtilt.ts +96 -95
  77. package/src/device/bot.ts +54 -54
  78. package/src/device/ceilinglight.ts +46 -39
  79. package/src/device/colorbulb.ts +68 -69
  80. package/src/device/contact.ts +69 -77
  81. package/src/device/curtain.ts +75 -74
  82. package/src/device/hub.ts +53 -38
  83. package/src/device/humidifier.ts +33 -26
  84. package/src/device/iosensor.ts +53 -48
  85. package/src/device/lightstrip.ts +4 -10
  86. package/src/device/lock.ts +84 -49
  87. package/src/device/meter.ts +13 -25
  88. package/src/device/meterplus.ts +14 -27
  89. package/src/device/motion.ts +16 -32
  90. package/src/device/plug.ts +4 -10
  91. package/src/device/robotvacuumcleaner.ts +13 -25
  92. package/src/irdevice/fan.ts +0 -3
  93. package/src/irdevice/tv.ts +0 -3
  94. package/src/settings.ts +5 -1
package/src/device/hub.ts CHANGED
@@ -8,19 +8,22 @@ import { sleep } from '../utils';
8
8
 
9
9
  export class Hub {
10
10
  // Services
11
- hubTemperatureSensor: Service;
12
- hubHumiditySensor: Service;
13
11
  hubLightSensor: Service;
12
+ hubHumiditySensor: Service;
13
+ hubTemperatureSensor: Service;
14
14
 
15
15
  // Characteristic Values
16
- CurrentRelativeHumidity!: number;
17
- CurrentTemperature!: number;
18
- CurrentAmbientLightLevel!: number;
16
+ CurrentTemperature!: CharacteristicValue;
17
+ CurrentRelativeHumidity!: CharacteristicValue;
18
+ CurrentAmbientLightLevel!: CharacteristicValue;
19
+
20
+ // OpenAPI Status
21
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
22
+ OpenAPI_CurrentTemperature: deviceStatus['temperature'];
23
+ OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
24
+ OpenAPI_CurrentAmbientLightLevel!: deviceStatus['brightness'];
19
25
 
20
26
  // OpenAPI Others
21
- Version: deviceStatus['version'];
22
- deviceStatus!: any; //deviceStatusResponse;
23
- lightLevel!: number;
24
27
  spaceBetweenLevels!: number;
25
28
 
26
29
  // Config
@@ -174,10 +177,11 @@ export class Hub {
174
177
 
175
178
  async openAPIparseStatus(): Promise<void> {
176
179
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
177
- this.infoLog(`update temperature and humidity for ${this.accessory.displayName}`);
178
- // this.infoLog(`temp: ${this.CurrentTemperature}, humidity: ${this.CurrentRelativeHumidity}`);
179
- this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
180
- this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
180
+ // Temperature
181
+ this.CurrentTemperature = Number(this.OpenAPI_CurrentTemperature);
182
+
183
+ // Humidity
184
+ this.CurrentRelativeHumidity = Number(this.OpenAPI_CurrentRelativeHumidity);
181
185
 
182
186
  if (!this.device.curtain?.hide_lightsensor) {
183
187
  this.set_minLux = this.minLux();
@@ -185,85 +189,85 @@ export class Hub {
185
189
  this.spaceBetweenLevels = 19;
186
190
 
187
191
  // Brightness
188
- switch (this.lightLevel) {
192
+ switch (this.OpenAPI_CurrentAmbientLightLevel) {
189
193
  case 1:
190
194
  this.CurrentAmbientLightLevel = this.set_minLux;
191
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
195
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
192
196
  break;
193
197
  case 2:
194
198
  this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
195
199
  this.debugLog(
196
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
200
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
197
201
  ` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
198
202
  );
199
203
  break;
200
204
  case 3:
201
205
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
202
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
206
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
203
207
  break;
204
208
  case 4:
205
209
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
206
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
210
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
207
211
  break;
208
212
  case 5:
209
213
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
210
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
214
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
211
215
  break;
212
216
  case 6:
213
217
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
214
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
218
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
215
219
  break;
216
220
  case 7:
217
221
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
218
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
222
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
219
223
  break;
220
224
  case 8:
221
225
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
222
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
226
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
223
227
  break;
224
228
  case 9:
225
229
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
226
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
230
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
227
231
  break;
228
232
  case 10:
229
233
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
230
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
234
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
231
235
  break;
232
236
  case 11:
233
237
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
234
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
238
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
235
239
  break;
236
240
  case 12:
237
241
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
238
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
242
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
239
243
  break;
240
244
  case 13:
241
245
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
242
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
246
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
243
247
  break;
244
248
  case 14:
245
249
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
246
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
250
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
247
251
  break;
248
252
  case 15:
249
253
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
250
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
254
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
251
255
  break;
252
256
  case 16:
253
257
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
254
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
258
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
255
259
  break;
256
260
  case 17:
257
261
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
258
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
262
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
259
263
  break;
260
264
  case 18:
261
265
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
262
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
266
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
263
267
  break;
264
268
  case 19:
265
269
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
266
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
270
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
267
271
  break;
268
272
  case 20:
269
273
  default:
@@ -271,7 +275,7 @@ export class Hub {
271
275
  this.debugLog();
272
276
  }
273
277
  this.debugLog(
274
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
278
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
275
279
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
276
280
  );
277
281
  }
@@ -299,9 +303,10 @@ export class Hub {
299
303
  this.statusCode(statusCode);
300
304
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
301
305
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
302
- this.CurrentTemperature = deviceStatus.body.temperature;
303
- this.CurrentRelativeHumidity = deviceStatus.body.humidity;
304
- this.lightLevel = deviceStatus.body.lightLevel;
306
+ this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
307
+ this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
308
+ this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.lightLevel;
309
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
305
310
  this.openAPIparseStatus();
306
311
  this.updateHomeKitCharacteristics();
307
312
  } catch (e: any) {
@@ -360,10 +365,20 @@ export class Hub {
360
365
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
361
366
  this.hubLightSensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
362
367
  this.debugLog(
363
- `${this.device.deviceType}: ${this.accessory.displayName} ` +
364
- `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
368
+ `${this.device.deviceType}: ${this.accessory.displayName} `
369
+ + `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
365
370
  );
366
371
  }
372
+ // FirmwareRevision
373
+ if (this.OpenAPI_FirmwareRevision === undefined) {
374
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
375
+ } else {
376
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
377
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
378
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
379
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
380
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
381
+ }
367
382
  }
368
383
 
369
384
  async statusCode(statusCode: number): Promise<void> {
@@ -28,18 +28,16 @@ export class Humidifier {
28
28
  WaterLevel!: CharacteristicValue;
29
29
 
30
30
  // OpenAPI
31
- auto: deviceStatus['auto'];
32
- power: deviceStatus['power'];
33
- humidity: deviceStatus['humidity'];
34
- lackWater: deviceStatus['lackWater'];
35
- temperature: deviceStatus['temperature'];
36
- nebulizationEfficiency: deviceStatus['nebulizationEfficiency'];
37
- deviceStatus!: any; //deviceStatusResponse;
31
+ OpenAPI_Active: deviceStatus['power'];
32
+ OpenAPI_WaterLevel: deviceStatus['lackWater'];
33
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
34
+ OpenAPI_CurrentTemperature: deviceStatus['temperature'];
35
+ OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
36
+ OpenAPI_CurrentHumidifierDehumidifierState: deviceStatus['auto'];
37
+ OpenAPI_RelativeHumidityHumidifierThreshold: deviceStatus['nebulizationEfficiency'];
38
38
 
39
39
  // BLE Others
40
40
  connected?: boolean;
41
- serviceData!: serviceData;
42
- address!: ad['address'];
43
41
  onState!: serviceData['onState'];
44
42
  autoMode!: serviceData['autoMode'];
45
43
  percentage!: serviceData['percentage'];
@@ -233,15 +231,15 @@ export class Humidifier {
233
231
  async openAPIparseStatus(): Promise<void> {
234
232
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
235
233
  // Current Relative Humidity
236
- this.CurrentRelativeHumidity = this.humidity!;
234
+ this.CurrentRelativeHumidity = this.OpenAPI_CurrentTemperature!;
237
235
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
238
236
  // Current Temperature
239
237
  if (!this.device.humidifier?.hide_temperature) {
240
- this.CurrentTemperature = this.temperature!;
238
+ this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
241
239
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
242
240
  }
243
241
  // Target Humidifier Dehumidifier State
244
- switch (this.auto) {
242
+ switch (this.OpenAPI_CurrentHumidifierDehumidifierState) {
245
243
  case true:
246
244
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
247
245
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
@@ -249,10 +247,10 @@ export class Humidifier {
249
247
  break;
250
248
  default:
251
249
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
252
- if (this.nebulizationEfficiency! > 100) {
250
+ if (this.OpenAPI_RelativeHumidityHumidifierThreshold! > 100) {
253
251
  this.RelativeHumidityHumidifierThreshold = 100;
254
252
  } else {
255
- this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
253
+ this.RelativeHumidityHumidifierThreshold = this.OpenAPI_RelativeHumidityHumidifierThreshold!;
256
254
  }
257
255
  if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
258
256
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
@@ -273,7 +271,7 @@ export class Humidifier {
273
271
  `${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
274
272
  );
275
273
  // Active
276
- switch (this.power) {
274
+ switch (this.OpenAPI_Active) {
277
275
  case 'on':
278
276
  this.Active = this.platform.Characteristic.Active.ACTIVE;
279
277
  break;
@@ -282,7 +280,7 @@ export class Humidifier {
282
280
  }
283
281
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
284
282
  // Water Level
285
- if (this.lackWater) {
283
+ if (this.OpenAPI_WaterLevel) {
286
284
  this.WaterLevel = 0;
287
285
  } else {
288
286
  this.WaterLevel = 100;
@@ -329,12 +327,10 @@ export class Humidifier {
329
327
  .then(async () => {
330
328
  // Set an event hander
331
329
  switchbot.onadvertisement = async (ad: ad) => {
332
- this.address = ad.address;
333
330
  this.debugLog(
334
331
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
335
- ` BLE Address Found: ${this.address}`,
332
+ ` BLE Address Found: ${ad.address}`,
336
333
  );
337
- this.serviceData = ad.serviceData;
338
334
  this.autoMode = ad.serviceData.autoMode;
339
335
  this.onState = ad.serviceData.onState;
340
336
  this.percentage = ad.serviceData.percentage;
@@ -344,7 +340,7 @@ export class Humidifier {
344
340
  `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
345
341
  );
346
342
 
347
- if (this.serviceData) {
343
+ if (ad.serviceData) {
348
344
  this.connected = true;
349
345
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
350
346
  await this.stopScanning(switchbot);
@@ -384,12 +380,13 @@ export class Humidifier {
384
380
  this.statusCode(statusCode);
385
381
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
386
382
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
387
- this.auto = deviceStatus.body.auto;
388
- this.power = deviceStatus.body.power;
389
- this.lackWater = deviceStatus.body.lackWater;
390
- this.humidity = deviceStatus.body.humidity;
391
- this.temperature = deviceStatus.body.temperature;
392
- this.nebulizationEfficiency = deviceStatus.body.nebulizationEfficiency;
383
+ this.OpenAPI_CurrentHumidifierDehumidifierState = deviceStatus.body.auto;
384
+ this.OpenAPI_Active = deviceStatus.body.power;
385
+ this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
386
+ this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
387
+ this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
388
+ this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
389
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
393
390
  this.openAPIparseStatus();
394
391
  this.updateHomeKitCharacteristics();
395
392
  } catch (e: any) {
@@ -703,6 +700,16 @@ export class Humidifier {
703
700
  this.accessory.context.CurrentTemperature = this.CurrentTemperature;
704
701
  }
705
702
  }
703
+ // FirmwareRevision
704
+ if (this.OpenAPI_FirmwareRevision === undefined) {
705
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
706
+ } else {
707
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
708
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
709
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
710
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
711
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
712
+ }
706
713
  }
707
714
 
708
715
  async stopScanning(switchbot: any) {
@@ -8,7 +8,7 @@ import { interval, Subject } from 'rxjs';
8
8
  import { skipWhile } from 'rxjs/operators';
9
9
  import { SwitchBotPlatform } from '../platform';
10
10
  import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
11
- import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, Devices } from '../settings';
11
+ import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devices } from '../settings';
12
12
 
13
13
  /**
14
14
  * Platform Accessory
@@ -17,34 +17,31 @@ import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceS
17
17
  */
18
18
  export class IOSensor {
19
19
  // Services
20
- batteryService?: Service;
21
- temperatureservice?: Service;
20
+ batteryService: Service;
22
21
  humidityservice?: Service;
22
+ temperatureservice?: Service;
23
23
 
24
24
  // Characteristic Values
25
- CurrentRelativeHumidity!: CharacteristicValue;
25
+ BatteryLevel!: CharacteristicValue;
26
+ StatusLowBattery!: CharacteristicValue;
26
27
  CurrentTemperature?: CharacteristicValue;
27
- BatteryLevel?: CharacteristicValue;
28
- ChargingState?: CharacteristicValue;
29
- StatusLowBattery?: CharacteristicValue;
28
+ CurrentRelativeHumidity!: CharacteristicValue;
30
29
 
31
- // OpenAPI Others
32
- Version: deviceStatus['version'];
33
- Battery: deviceStatus['battery'];
34
- Temperature: deviceStatus['temperature'];
35
- Humidity: deviceStatus['humidity'];
36
- deviceStatus!: any; //deviceStatusResponse;
30
+ // OpenAPI Status
31
+ OpenAPI_BatteryLevel: deviceStatus['battery'];
32
+ OpenAPI_FirmwareRevision: deviceStatus['version'];
33
+ OpenAPI_CurrentTemperature: deviceStatus['temperature'];
34
+ OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
35
+
36
+ // BLE Status
37
+ BLE_Celsius!: temperature['c'];
38
+ BLE_Fahrenheit!: temperature['f'];
39
+ BLE_BatteryLevel!: serviceData['battery'];
40
+ BLE_CurrentTemperature!: serviceData['temperature'];
41
+ BLE_CurrentRelativeHumidity!: serviceData['humidity'];
37
42
 
38
43
  // BLE Others
39
- connected?: boolean;
40
- switchbot!: switchbot;
41
- serviceData!: serviceData;
42
- address!: ad['address'];
43
- temperature!: serviceData['temperature'];
44
- celsius!: temperature['c'];
45
- fahrenheit!: temperature['f'];
46
- battery!: serviceData['battery'];
47
- humidity!: serviceData['humidity'];
44
+ BLE_IsConnected?: boolean;
48
45
 
49
46
  //MQTT stuff
50
47
  mqttClient: MqttClient | null = null;
@@ -155,7 +152,7 @@ export class IOSensor {
155
152
  }
156
153
 
157
154
  // Battery Service
158
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
155
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
159
156
  `${accessory.displayName} Battery`;
160
157
 
161
158
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
@@ -197,7 +194,7 @@ export class IOSensor {
197
194
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
198
195
 
199
196
  // Battery
200
- this.BatteryLevel = Number(this.battery);
197
+ this.BatteryLevel = Number(this.BLE_BatteryLevel);
201
198
  if (this.BatteryLevel < 15) {
202
199
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
203
200
  } else {
@@ -207,14 +204,14 @@ export class IOSensor {
207
204
 
208
205
  // Humidity
209
206
  if (!this.device.meter?.hide_humidity) {
210
- this.CurrentRelativeHumidity = this.humidity!;
207
+ this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
211
208
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
212
209
  }
213
210
 
214
211
  // Current Temperature
215
212
  if (!this.device.meter?.hide_temperature) {
216
- this.celsius < 0 ? 0 : this.celsius > 100 ? 100 : this.celsius;
217
- this.CurrentTemperature = this.celsius;
213
+ this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
214
+ this.CurrentTemperature = this.BLE_Celsius;
218
215
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
219
216
  }
220
217
  }
@@ -222,7 +219,7 @@ export class IOSensor {
222
219
  async openAPIparseStatus(): Promise<void> {
223
220
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
224
221
  // Battery
225
- this.BatteryLevel = Number(this.Battery);
222
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
226
223
  if (this.BatteryLevel < 15) {
227
224
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
228
225
  } else {
@@ -232,13 +229,13 @@ export class IOSensor {
232
229
 
233
230
  // Current Relative Humidity
234
231
  if (!this.device.meter?.hide_humidity) {
235
- this.CurrentRelativeHumidity = this.Humidity!;
232
+ this.CurrentRelativeHumidity = this.OpenAPI_CurrentRelativeHumidity!;
236
233
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
237
234
  }
238
235
 
239
236
  // Current Temperature
240
237
  if (!this.device.meter?.hide_temperature) {
241
- this.CurrentTemperature = this.Temperature!;
238
+ this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
242
239
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
243
240
  }
244
241
  }
@@ -282,20 +279,18 @@ export class IOSensor {
282
279
  .then(async () => {
283
280
  // Set an event hander
284
281
  switchbot.onadvertisement = async (ad: ad) => {
285
- this.address = ad.address;
286
282
  this.debugLog(
287
283
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
288
- ` BLE Address Found: ${this.address}`,
284
+ ` BLE Address Found: ${ad.address}`,
289
285
  );
290
286
  if (ad.serviceData.humidity! > 0) {
291
287
  // reject unreliable data
292
- this.humidity = ad.serviceData.humidity;
288
+ this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
293
289
  }
294
- this.serviceData = ad.serviceData;
295
- this.temperature = ad.serviceData.temperature;
296
- this.celsius = ad.serviceData.temperature!.c;
297
- this.fahrenheit = ad.serviceData.temperature!.f;
298
- this.battery = ad.serviceData.battery;
290
+ this.BLE_CurrentTemperature = ad.serviceData.temperature;
291
+ this.BLE_Celsius = ad.serviceData.temperature!.c;
292
+ this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
293
+ this.BLE_BatteryLevel = ad.serviceData.battery;
299
294
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
300
295
  this.debugLog(
301
296
  `${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
@@ -303,13 +298,13 @@ export class IOSensor {
303
298
  `battery: ${ad.serviceData.battery}`,
304
299
  );
305
300
 
306
- if (this.serviceData) {
307
- this.connected = true;
308
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
301
+ if (ad.serviceData) {
302
+ this.BLE_IsConnected = true;
303
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
309
304
  await this.stopScanning(switchbot);
310
305
  } else {
311
- this.connected = false;
312
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
306
+ this.BLE_IsConnected = false;
307
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
313
308
  }
314
309
  };
315
310
  // Wait
@@ -343,10 +338,10 @@ export class IOSensor {
343
338
  this.statusCode(statusCode);
344
339
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
345
340
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
346
- this.Humidity = deviceStatus.body.humidity!;
347
- this.Temperature = deviceStatus.body.temperature!;
348
- this.Battery = deviceStatus.body.battery;
349
- this.Version = deviceStatus.body.version;
341
+ this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity!;
342
+ this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
343
+ this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
344
+ this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
350
345
  this.openAPIparseStatus();
351
346
  this.updateHomeKitCharacteristics();
352
347
  } catch (e: any) {
@@ -426,6 +421,16 @@ export class IOSensor {
426
421
  this.historyService?.addEntry(entry);
427
422
  }
428
423
  }
424
+ // FirmwareRevision
425
+ if (this.OpenAPI_FirmwareRevision === undefined) {
426
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
427
+ } else {
428
+ this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
429
+ this.accessory.getService(this.platform.Service.AccessoryInformation)!
430
+ .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
431
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
432
+ + `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
433
+ }
429
434
  }
430
435
 
431
436
  /*
@@ -479,7 +484,7 @@ export class IOSensor {
479
484
 
480
485
  async stopScanning(switchbot: any) {
481
486
  await switchbot.stopScan();
482
- if (this.connected) {
487
+ if (this.BLE_IsConnected) {
483
488
  await this.BLEparseStatus();
484
489
  await this.updateHomeKitCharacteristics();
485
490
  } else {
@@ -6,7 +6,7 @@ import { interval, Subject } from 'rxjs';
6
6
  import { SwitchBotPlatform } from '../platform';
7
7
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
8
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
9
- import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m2hs, Devices } from '../settings';
9
+ import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m2hs, Devices } from '../settings';
10
10
 
11
11
  /**
12
12
  * Platform Accessory
@@ -29,13 +29,9 @@ export class StripLight {
29
29
  power: deviceStatus['power'];
30
30
  color: deviceStatus['color'];
31
31
  brightness: deviceStatus['brightness'];
32
- deviceStatus!: any; //deviceStatusResponse;
33
32
 
34
33
  // BLE Others
35
34
  connected?: boolean;
36
- switchbot!: switchbot;
37
- address!: ad['address'];
38
- serviceData!: serviceData;
39
35
  state: serviceData['state'];
40
36
  delay: serviceData['delay'];
41
37
  wifiRssi: serviceData['wifiRssi'];
@@ -324,14 +320,12 @@ export class StripLight {
324
320
  })
325
321
  .then(async () => {
326
322
  // Set an event hander
327
- switchbot.onadvertisement = async (ad: any) => {
328
- this.address = ad.address;
323
+ switchbot.onadvertisement = async (ad: ad) => {
329
324
  this.debugLog(
330
325
  `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
331
- ` BLE Address Found: ${this.address}`,
326
+ ` BLE Address Found: ${ad.address}`,
332
327
  );
333
328
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
334
- this.serviceData = ad.serviceData;
335
329
  //this.state = ad.serviceData.state;
336
330
  //this.delay = ad.serviceData.delay;
337
331
  //this.timer = ad.serviceData.timer;
@@ -346,7 +340,7 @@ export class StripLight {
346
340
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
347
341
  );*/
348
342
 
349
- if (this.serviceData) {
343
+ if (ad.serviceData) {
350
344
  this.connected = true;
351
345
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
352
346
  await this.stopScanning(switchbot);