@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.2-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 (158) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/config.schema.json +19 -3
  3. package/dist/device/blindtilt.d.ts +6 -4
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +61 -47
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +6 -3
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +60 -26
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +6 -3
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +48 -30
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +6 -3
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +54 -37
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +6 -3
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +46 -32
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +6 -4
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +42 -28
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +7 -4
  28. package/dist/device/device.d.ts.map +1 -1
  29. package/dist/device/device.js +61 -152
  30. package/dist/device/device.js.map +1 -1
  31. package/dist/device/fan.d.ts +6 -3
  32. package/dist/device/fan.d.ts.map +1 -1
  33. package/dist/device/fan.js +54 -33
  34. package/dist/device/fan.js.map +1 -1
  35. package/dist/device/hub.d.ts +6 -3
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +50 -31
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +6 -3
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +48 -29
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +6 -3
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +45 -28
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +6 -3
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +47 -29
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +6 -3
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +39 -26
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +6 -3
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +44 -28
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +6 -3
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +43 -28
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +6 -3
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +38 -25
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +6 -3
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +31 -18
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +6 -3
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +38 -23
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +6 -3
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +44 -27
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/homebridge-ui/public/index.html +2 -2
  80. package/dist/irdevice/airconditioner.d.ts +1 -3
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +67 -177
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +0 -1
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +24 -53
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts.map +1 -1
  89. package/dist/irdevice/camera.js +12 -17
  90. package/dist/irdevice/camera.js.map +1 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +22 -38
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +22 -10
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +94 -100
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts.map +1 -1
  99. package/dist/irdevice/light.js +20 -38
  100. package/dist/irdevice/light.js.map +1 -1
  101. package/dist/irdevice/other.d.ts.map +1 -1
  102. package/dist/irdevice/other.js +79 -77
  103. package/dist/irdevice/other.js.map +1 -1
  104. package/dist/irdevice/tv.d.ts.map +1 -1
  105. package/dist/irdevice/tv.js +38 -53
  106. package/dist/irdevice/tv.js.map +1 -1
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +11 -16
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts.map +1 -1
  111. package/dist/irdevice/waterheater.js +11 -16
  112. package/dist/irdevice/waterheater.js.map +1 -1
  113. package/dist/platform.d.ts +4 -6
  114. package/dist/platform.d.ts.map +1 -1
  115. package/dist/platform.js +564 -665
  116. package/dist/platform.js.map +1 -1
  117. package/dist/settings.d.ts +10 -8
  118. package/dist/settings.d.ts.map +1 -1
  119. package/dist/settings.js.map +1 -1
  120. package/dist/types/bledevicestatus.d.ts +2 -1
  121. package/dist/types/bledevicestatus.d.ts.map +1 -1
  122. package/dist/types/devicestatus.d.ts +1 -1
  123. package/dist/types/devicestatus.d.ts.map +1 -1
  124. package/package.json +14 -14
  125. package/src/device/blindtilt.ts +65 -49
  126. package/src/device/bot.ts +80 -27
  127. package/src/device/ceilinglight.ts +58 -32
  128. package/src/device/colorbulb.ts +58 -44
  129. package/src/device/contact.ts +50 -32
  130. package/src/device/curtain.ts +52 -29
  131. package/src/device/device.ts +63 -135
  132. package/src/device/fan.ts +68 -34
  133. package/src/device/hub.ts +63 -34
  134. package/src/device/humidifier.ts +61 -34
  135. package/src/device/iosensor.ts +52 -31
  136. package/src/device/lightstrip.ts +53 -30
  137. package/src/device/lock.ts +56 -27
  138. package/src/device/meter.ts +61 -30
  139. package/src/device/meterplus.ts +57 -30
  140. package/src/device/motion.ts +51 -27
  141. package/src/device/plug.ts +39 -19
  142. package/src/device/robotvacuumcleaner.ts +54 -25
  143. package/src/device/waterdetector.ts +63 -29
  144. package/src/homebridge-ui/public/index.html +2 -2
  145. package/src/irdevice/airconditioner.ts +76 -165
  146. package/src/irdevice/airpurifier.ts +29 -49
  147. package/src/irdevice/camera.ts +13 -16
  148. package/src/irdevice/fan.ts +25 -35
  149. package/src/irdevice/irdevice.ts +97 -96
  150. package/src/irdevice/light.ts +21 -35
  151. package/src/irdevice/other.ts +79 -77
  152. package/src/irdevice/tv.ts +40 -51
  153. package/src/irdevice/vacuumcleaner.ts +12 -15
  154. package/src/irdevice/waterheater.ts +12 -15
  155. package/src/platform.ts +566 -696
  156. package/src/settings.ts +11 -8
  157. package/src/types/bledevicestatus.ts +4 -2
  158. package/src/types/devicestatus.ts +1 -1
@@ -39,6 +39,15 @@ export class Humidifier extends deviceBase {
39
39
  CurrentTemperature: CharacteristicValue;
40
40
  };
41
41
 
42
+ // OpenAPI
43
+ deviceStatus!: humidifierStatus;
44
+
45
+ //Webhook
46
+ webhookContext!: humidifierWebhookContext;
47
+
48
+ // BLE
49
+ serviceData!: humidifierServiceData;
50
+
42
51
  // Updates
43
52
  humidifierUpdateInProgress!: boolean;
44
53
  doHumidifierUpdate!: Subject<void>;
@@ -49,6 +58,9 @@ export class Humidifier extends deviceBase {
49
58
  device: device & devicesConfig,
50
59
  ) {
51
60
  super(platform, accessory, device);
61
+ // Set category
62
+ accessory.category = this.hap.Categories.AIR_HUMIDIFIER;
63
+
52
64
  // this is subject we use to track when we need to POST changes to the SwitchBot API
53
65
  this.doHumidifierUpdate = new Subject();
54
66
  this.humidifierUpdateInProgress = false;
@@ -110,7 +122,7 @@ export class Humidifier extends deviceBase {
110
122
  // Initialize the Temperature Sensor Service
111
123
  if (device.humidifier?.hide_temperature) {
112
124
  if (this.TemperatureSensor) {
113
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
125
+ this.debugLog('Removing Temperature Sensor Service');
114
126
  this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
115
127
  accessory.removeService(this.TemperatureSensor!.Service);
116
128
  }
@@ -139,12 +151,11 @@ export class Humidifier extends deviceBase {
139
151
  }
140
152
 
141
153
  // Retrieve initial values and updateHomekit
154
+ this.debugLog('Retrieve initial values and update Homekit');
142
155
  this.refreshStatus();
143
156
 
144
- // Retrieve initial values and updateHomekit
145
- this.updateHomeKitCharacteristics();
146
-
147
157
  //regisiter webhook event handler
158
+ this.debugLog('Registering Webhook Event Handler');
148
159
  this.registerWebhook();
149
160
 
150
161
  // Start an update interval
@@ -174,18 +185,23 @@ export class Humidifier extends deviceBase {
174
185
  });
175
186
  }
176
187
 
177
- async BLEparseStatus(serviceData: humidifierServiceData): Promise<void> {
188
+ async BLEparseStatus(): Promise<void> {
178
189
  await this.debugLog('BLEparseStatus');
190
+ await this.debugLog(`(onState, percentage, autoMode) = BLE:(${this.serviceData.onState}, ${this.serviceData.percentage},`
191
+ + ` ${this.serviceData.autoMode}), current:(${this.HumidifierDehumidifier.Active}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity},`
192
+ + ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`,
193
+ );
194
+
179
195
  // Active
180
- this.HumidifierDehumidifier.Active = serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
196
+ this.HumidifierDehumidifier.Active = this.serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
181
197
  await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
182
198
 
183
199
  // Current Relative Humidity
184
- this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
200
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = this.serviceData.percentage;
185
201
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
186
202
 
187
203
  // Target Humidifier Dehumidifier State
188
- switch (serviceData.autoMode) {
204
+ switch (this.serviceData.autoMode) {
189
205
  case true:
190
206
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
191
207
  this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
@@ -194,7 +210,7 @@ export class Humidifier extends deviceBase {
194
210
  break;
195
211
  default:
196
212
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
197
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = serviceData.percentage > 100 ? 100 : serviceData.percentage;
213
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.serviceData.percentage > 100 ? 100 : this.serviceData.percentage;
198
214
  if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
199
215
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
200
216
  } else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
@@ -208,24 +224,30 @@ export class Humidifier extends deviceBase {
208
224
  + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
209
225
  }
210
226
 
211
- async openAPIparseStatus(deviceStatus: humidifierStatus): Promise<void> {
227
+ async openAPIparseStatus(): Promise<void> {
212
228
  await this.debugLog('openAPIparseStatus');
229
+ await this.debugLog(`(power, auto, temperature, lackWater, nebulizationEfficiency, version) = OpenAPI:(${this.deviceStatus.power},`
230
+ + ` ${this.deviceStatus.auto}, ${this.deviceStatus.temperature}, ${this.deviceStatus.lackWater},`
231
+ + ` ${this.deviceStatus.nebulizationEfficiency}, ${this.deviceStatus.version}), current:(${this.HumidifierDehumidifier.Active},`
232
+ + ` ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
233
+ + ` ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`);
234
+
213
235
  // Active
214
- this.HumidifierDehumidifier.Active = deviceStatus.power === 'on'
236
+ this.HumidifierDehumidifier.Active = this.deviceStatus.power === 'on'
215
237
  ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
216
238
  await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
217
239
 
218
240
  // Current Relative Humidity
219
- this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.temperature!;
241
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = this.deviceStatus.temperature!;
220
242
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
221
243
 
222
244
  // Current Temperature
223
245
  if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
224
- this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
246
+ this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature;
225
247
  await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
226
248
  }
227
249
  // Target Humidifier Dehumidifier State
228
- switch (deviceStatus.auto) {
250
+ switch (this.deviceStatus.auto) {
229
251
  case true:
230
252
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
231
253
  this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
@@ -234,8 +256,8 @@ export class Humidifier extends deviceBase {
234
256
  break;
235
257
  default:
236
258
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
237
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.nebulizationEfficiency > 100
238
- ? 100 : deviceStatus.nebulizationEfficiency;
259
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.deviceStatus.nebulizationEfficiency > 100
260
+ ? 100 : this.deviceStatus.nebulizationEfficiency;
239
261
  if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
240
262
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
241
263
  } else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
@@ -249,7 +271,7 @@ export class Humidifier extends deviceBase {
249
271
  + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
250
272
 
251
273
  // Water Level
252
- if (deviceStatus.lackWater) {
274
+ if (this.deviceStatus.lackWater) {
253
275
  this.HumidifierDehumidifier.WaterLevel = 0;
254
276
  } else {
255
277
  this.HumidifierDehumidifier.WaterLevel = 100;
@@ -257,8 +279,8 @@ export class Humidifier extends deviceBase {
257
279
  await this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
258
280
 
259
281
  // Firmware Version
260
- if (deviceStatus.version) {
261
- const version = deviceStatus.version.toString();
282
+ if (this.deviceStatus.version) {
283
+ const version = this.deviceStatus.version.toString();
262
284
  await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
263
285
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
264
286
  this.accessory
@@ -267,23 +289,25 @@ export class Humidifier extends deviceBase {
267
289
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
268
290
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
269
291
  .updateValue(deviceVersion);
270
- this.accessory.context.deviceVersion = deviceVersion;
271
- await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
292
+ this.accessory.context.version = deviceVersion;
293
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
272
294
  }
273
295
  }
274
296
 
275
- async parseStatusWebhook(context: humidifierWebhookContext): Promise<void> {
297
+ async parseStatusWebhook(): Promise<void> {
276
298
  await this.debugLog('parseStatusWebhook');
277
- await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo)},`
278
- + ` ${context.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
299
+ await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
300
+ this.device.iosensor?.convertUnitTo)}, ${this.webhookContext.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature},`
301
+ + ` ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
279
302
 
280
303
  // CurrentRelativeHumidity
281
- this.HumidifierDehumidifier.CurrentRelativeHumidity = context.humidity;
304
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = this.webhookContext.humidity;
282
305
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
283
306
 
284
307
  // CurrentTemperature
285
308
  if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
286
- this.TemperatureSensor.CurrentTemperature = convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo);
309
+ this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
310
+ this.device.iosensor?.convertUnitTo);
287
311
  await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
288
312
  }
289
313
  }
@@ -314,10 +338,11 @@ export class Humidifier extends deviceBase {
314
338
  // Start to monitor advertisement packets
315
339
  (async () => {
316
340
  // Start to monitor advertisement packets
317
- const serviceData= await this.monitorAdvertisementPackets(switchbot) as unknown as humidifierServiceData;
341
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData;
318
342
  // Update HomeKit
319
343
  if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
320
- await this.BLEparseStatus(serviceData);
344
+ this.serviceData = serviceData;
345
+ await this.BLEparseStatus();
321
346
  await this.updateHomeKitCharacteristics();
322
347
  } else {
323
348
  await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
@@ -335,7 +360,8 @@ export class Humidifier extends deviceBase {
335
360
  await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
336
361
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
337
362
  await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
338
- await this.openAPIparseStatus(deviceStatus.body);
363
+ this.deviceStatus = deviceStatus.body;
364
+ await this.openAPIparseStatus();
339
365
  await this.updateHomeKitCharacteristics();
340
366
  } else {
341
367
  await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
@@ -353,7 +379,8 @@ export class Humidifier extends deviceBase {
353
379
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: humidifierWebhookContext) => {
354
380
  try {
355
381
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
356
- await this.parseStatusWebhook(context);
382
+ this.webhookContext = context;
383
+ await this.parseStatusWebhook();
357
384
  await this.updateHomeKitCharacteristics();
358
385
  } catch (e: any) {
359
386
  await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
@@ -414,8 +441,8 @@ export class Humidifier extends deviceBase {
414
441
  }
415
442
  } else {
416
443
  await this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active},`
417
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
418
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
444
+ + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
445
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
419
446
  }
420
447
  }
421
448
 
@@ -423,7 +450,7 @@ export class Humidifier extends deviceBase {
423
450
  await this.debugLog('openAPIpushChanges');
424
451
  if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
425
452
  && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
426
- && (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
453
+ && (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
427
454
  await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
428
455
  const bodyChange = JSON.stringify({
429
456
  command: 'setMode',
@@ -608,7 +635,7 @@ export class Humidifier extends deviceBase {
608
635
  }
609
636
 
610
637
  async BLERefreshConnection(switchbot: any): Promise<void> {
611
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
638
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
612
639
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
613
640
  await this.warnLog('Using OpenAPI Connection to Refresh Status');
614
641
  await this.openAPIRefreshStatus();
@@ -42,6 +42,15 @@ export class IOSensor extends deviceBase {
42
42
  CurrentTemperature: CharacteristicValue;
43
43
  };
44
44
 
45
+ // OpenAPI
46
+ deviceStatus!: outdoorMeterStatus;
47
+
48
+ //Webhook
49
+ webhookContext!: outdoorMeterWebhookContext;
50
+
51
+ // BLE
52
+ serviceData!: outdoorMeterServiceData;
53
+
45
54
  // Updates
46
55
  ioSensorUpdateInProgress!: boolean;
47
56
  doIOSensorUpdate: Subject<void>;
@@ -52,6 +61,9 @@ export class IOSensor extends deviceBase {
52
61
  device: device & devicesConfig,
53
62
  ) {
54
63
  super(platform, accessory, device);
64
+ // Set category
65
+ accessory.category = this.hap.Categories.SENSOR;
66
+
55
67
  // this is subject we use to track when we need to POST changes to the SwitchBot API
56
68
  this.doIOSensorUpdate = new Subject();
57
69
  this.ioSensorUpdateInProgress = false;
@@ -85,7 +97,7 @@ export class IOSensor extends deviceBase {
85
97
  // InitializeTemperature Sensor Service
86
98
  if (device.iosensor?.hide_temperature) {
87
99
  if (this.TemperatureSensor) {
88
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
100
+ this.debugLog('Removing Temperature Sensor Service');
89
101
  this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
90
102
  accessory.removeService(this.TemperatureSensor.Service);
91
103
  }
@@ -117,7 +129,7 @@ export class IOSensor extends deviceBase {
117
129
  // Initialize Humidity Sensor Service
118
130
  if (device.iosensor?.hide_humidity) {
119
131
  if (this.HumiditySensor) {
120
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
132
+ this.debugLog('Removing Humidity Sensor Service');
121
133
  this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
122
134
  accessory.removeService(this.HumiditySensor.Service);
123
135
  }
@@ -143,12 +155,11 @@ export class IOSensor extends deviceBase {
143
155
  }
144
156
 
145
157
  // Retrieve initial values and updateHomekit
158
+ this.debugLog('Retrieve initial values and update Homekit');
146
159
  this.refreshStatus();
147
160
 
148
- // Retrieve initial values and updateHomekit
149
- this.updateHomeKitCharacteristics();
150
-
151
161
  //regisiter webhook event handler
162
+ this.debugLog('Registering Webhook Event Handler');
152
163
  this.registerWebhook();
153
164
 
154
165
  // Start an update interval
@@ -159,11 +170,14 @@ export class IOSensor extends deviceBase {
159
170
  });
160
171
  }
161
172
 
162
- async BLEparseStatus(serviceData: outdoorMeterServiceData): Promise<void> {
173
+ async BLEparseStatus(): Promise<void> {
163
174
  await this.debugLog('BLEparseStatus');
175
+ await this.debugLog(`(battery, temperature, humidity) = BLE:(${this.serviceData.battery}, ${this.serviceData.temperature.c},`
176
+ + ` ${this.serviceData.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature},`
177
+ + ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
164
178
 
165
179
  // BatteryLevel
166
- this.Battery.BatteryLevel = Number(serviceData.battery);
180
+ this.Battery.BatteryLevel = this.serviceData.battery;
167
181
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
168
182
 
169
183
  // StatusLowBattery
@@ -173,23 +187,26 @@ export class IOSensor extends deviceBase {
173
187
 
174
188
  // CurrentRelativeHumidity
175
189
  if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
176
- this.HumiditySensor.CurrentRelativeHumidity = serviceData.humidity;
190
+ this.HumiditySensor.CurrentRelativeHumidity = this.serviceData.humidity;
177
191
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
178
192
  }
179
193
 
180
194
  // Current Temperature
181
195
  if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
182
- const CELSIUS = serviceData.temperature.c < 0 ? 0 : serviceData.temperature.c > 100 ? 100 : serviceData.temperature.c;
196
+ const CELSIUS = this.serviceData.temperature.c < 0 ? 0 : this.serviceData.temperature.c > 100 ? 100 : this.serviceData.temperature.c;
183
197
  this.TemperatureSensor.CurrentTemperature = CELSIUS;
184
198
  await this.debugLog(`Temperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
185
199
  }
186
200
  }
187
201
 
188
- async openAPIparseStatus(deviceStatus: outdoorMeterStatus): Promise<void> {
202
+ async openAPIparseStatus(): Promise<void> {
189
203
  await this.debugLog('openAPIparseStatus');
204
+ await this.debugLog(`(battery, temperature, humidity) = OpenAPI:(${this.deviceStatus.battery}, ${this.deviceStatus.temperature},`
205
+ + ` ${this.deviceStatus.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature},`
206
+ + ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
190
207
 
191
208
  // BatteryLevel
192
- this.Battery.BatteryLevel = Number(deviceStatus.battery);
209
+ this.Battery.BatteryLevel = this.deviceStatus.battery;
193
210
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
194
211
 
195
212
  // StatusLowBattery
@@ -199,20 +216,20 @@ export class IOSensor extends deviceBase {
199
216
 
200
217
  // CurrentRelativeHumidity
201
218
  if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
202
- this.HumiditySensor.CurrentRelativeHumidity = deviceStatus.humidity;
219
+ this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity;
203
220
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
204
221
  }
205
222
 
206
223
  // Current Temperature
207
224
  if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
208
- this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
225
+ this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature;
209
226
  await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
210
227
  }
211
228
 
212
229
  // Firmware Version
213
- const version = deviceStatus.version.toString();
214
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
215
- if (deviceStatus.version) {
230
+ if (this.deviceStatus.version) {
231
+ const version = this.deviceStatus.version.toString();
232
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
216
233
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
217
234
  this.accessory
218
235
  .getService(this.hap.Service.AccessoryInformation)!
@@ -220,29 +237,30 @@ export class IOSensor extends deviceBase {
220
237
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
221
238
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
222
239
  .updateValue(deviceVersion);
223
- this.accessory.context.deviceVersion = deviceVersion;
224
- await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
240
+ this.accessory.context.version = deviceVersion;
241
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
225
242
  }
226
243
  }
227
244
 
228
- async parseStatusWebhook(context: outdoorMeterWebhookContext): Promise<void> {
245
+ async parseStatusWebhook(): Promise<void> {
229
246
  await this.debugLog('parseStatusWebhook');
230
- await this.debugLog(`(scale, temperature, humidity) = Webhook:(${context.scale}, ${convertUnits(context.temperature, context.scale,
231
- this.device.iosensor?.convertUnitTo)}, ${context.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature},`
232
- + ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
247
+ await this.debugLog(`(scale, temperature, humidity) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature,
248
+ this.webhookContext.scale, this.device.iosensor?.convertUnitTo)}, ${this.webhookContext.humidity}),`
249
+ + ` current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`);
233
250
 
234
- if (context.scale !== 'CELSIUS' && this.device.iosensor?.convertUnitTo === undefined) {
235
- await this.warnLog(`received a non-CELSIUS Webhook scale: ${context.scale}, Use the *convertUnitsTo* config under Hub settings,`
251
+ if (this.webhookContext.scale !== 'CELSIUS' && this.device.iosensor?.convertUnitTo === undefined) {
252
+ await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings,`
236
253
  + ' if displaying incorrectly in HomeKit.');
237
254
  }
238
255
  // CurrentRelativeHumidity
239
256
  if (this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
240
- this.HumiditySensor.CurrentRelativeHumidity = context.humidity;
257
+ this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity;
241
258
  await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
242
259
  }
243
260
  // CurrentTemperature
244
261
  if (this.device.iosensor?.hide_temperature && this.TemperatureSensor?.Service) {
245
- this.TemperatureSensor.CurrentTemperature = convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo);
262
+ this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
263
+ this.device.iosensor?.convertUnitTo);
246
264
  await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
247
265
  }
248
266
  }
@@ -273,10 +291,11 @@ export class IOSensor extends deviceBase {
273
291
  // Start to monitor advertisement packets
274
292
  (async () => {
275
293
  // Start to monitor advertisement packets
276
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as outdoorMeterServiceData;
294
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
277
295
  // Update HomeKit
278
296
  if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
279
- await this.BLEparseStatus(serviceData);
297
+ this.serviceData = serviceData;
298
+ await this.BLEparseStatus();
280
299
  await this.updateHomeKitCharacteristics();
281
300
  } else {
282
301
  await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
@@ -294,7 +313,8 @@ export class IOSensor extends deviceBase {
294
313
  await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
295
314
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
296
315
  await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
297
- await this.openAPIparseStatus(deviceStatus.body);
316
+ this.deviceStatus = deviceStatus.body;
317
+ await this.openAPIparseStatus();
298
318
  await this.updateHomeKitCharacteristics();
299
319
  } else {
300
320
  await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
@@ -312,7 +332,8 @@ export class IOSensor extends deviceBase {
312
332
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: outdoorMeterWebhookContext) => {
313
333
  try {
314
334
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
315
- await this.parseStatusWebhook(context);
335
+ this.webhookContext = context;
336
+ await this.parseStatusWebhook();
316
337
  await this.updateHomeKitCharacteristics();
317
338
  } catch (e: any) {
318
339
  await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
@@ -346,7 +367,7 @@ export class IOSensor extends deviceBase {
346
367
  }
347
368
 
348
369
  async BLERefreshConnection(switchbot: any): Promise<void> {
349
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
370
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
350
371
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
351
372
  await this.warnLog('Using OpenAPI Connection to Refresh Status');
352
373
  await this.openAPIRefreshStatus();
@@ -32,6 +32,15 @@ export class StripLight extends deviceBase {
32
32
  ColorTemperature?: CharacteristicValue;
33
33
  };
34
34
 
35
+ // OpenAPI
36
+ deviceStatus!: stripLightStatus;
37
+
38
+ //Webhook
39
+ webhookContext!: stripLightWebhookContext;
40
+
41
+ // BLE
42
+ serviceData!: stripLightServiceData;
43
+
35
44
  // Adaptive Lighting
36
45
  AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
37
46
  adaptiveLightingShift?: number;
@@ -46,6 +55,9 @@ export class StripLight extends deviceBase {
46
55
  device: device & devicesConfig,
47
56
  ) {
48
57
  super(platform, accessory, device);
58
+ // Set category
59
+ accessory.category = this.hap.Categories.LIGHTBULB;
60
+
49
61
  // Adaptive Lighting
50
62
  this.adaptiveLighting(device);
51
63
  // this is subject we use to track when we need to POST changes to the SwitchBot API
@@ -146,12 +158,11 @@ export class StripLight extends deviceBase {
146
158
  .onSet(this.SaturationSet.bind(this));
147
159
 
148
160
  // Retrieve initial values and updateHomekit
161
+ this.debugLog('Retrieve initial values and update Homekit');
149
162
  this.refreshStatus();
150
163
 
151
- // Update Homekit
152
- this.updateHomeKitCharacteristics();
153
-
154
164
  //regisiter webhook event handler
165
+ this.debugLog('Registering Webhook Event Handler');
155
166
  this.registerWebhook();
156
167
 
157
168
  // Start an update interval
@@ -181,20 +192,24 @@ export class StripLight extends deviceBase {
181
192
  });
182
193
  }
183
194
 
184
- async BLEparseStatus(serviceData: stripLightServiceData): Promise<void> {
195
+ async BLEparseStatus(): Promise<void> {
185
196
  await this.debugLog('BLEparseStatus');
197
+ await this.debugLog(`(power, brightness, color) = BLE:(${this.serviceData.power}, ${this.serviceData.brightness},`
198
+ + ` ${this.serviceData.red}:${this.serviceData.green}:${this.serviceData.blue}), current:(${this.LightBulb.On},`
199
+ + ` ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
200
+
186
201
  // On
187
- this.LightBulb.On = serviceData.power;
202
+ this.LightBulb.On = this.serviceData.power;
188
203
  await this.debugLog(`On: ${this.LightBulb.On}`);
189
204
 
190
205
  // Brightness
191
- this.LightBulb.Brightness = serviceData.brightness;
206
+ this.LightBulb.Brightness = this.serviceData.brightness;
192
207
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
193
208
 
194
209
  // Color, Hue & Brightness
195
- await this.debugLog(`red: ${serviceData.red}, green: ${serviceData.green}, blue: ${serviceData.blue}`);
196
- const [hue, saturation] = rgb2hs(serviceData.red, serviceData.green, serviceData.blue);
197
- await this.debugLog(`hs: ${JSON.stringify(rgb2hs(serviceData.red, serviceData.green, serviceData.blue))}`);
210
+ await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`);
211
+ const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue);
212
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`);
198
213
 
199
214
  // Hue
200
215
  this.LightBulb.Hue = hue;
@@ -205,19 +220,23 @@ export class StripLight extends deviceBase {
205
220
  this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
206
221
  }
207
222
 
208
- async openAPIparseStatus(deviceStatus: stripLightStatus): Promise<void> {
223
+ async openAPIparseStatus(): Promise<void> {
209
224
  await this.debugLog('openAPIparseStatus');
225
+ await this.debugLog(`(power, brightness, color) = API:(${this.deviceStatus.power}, ${this.deviceStatus.brightness},`
226
+ + ` ${this.deviceStatus.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
227
+ + ` ${this.LightBulb.Saturation})`);
228
+
210
229
  // On
211
- this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
230
+ this.LightBulb.On = this.deviceStatus.power === 'on' ? true : false;
212
231
  await this.debugLog(`On: ${this.LightBulb.On}`);
213
232
 
214
233
  // Brightness
215
- this.LightBulb.Brightness = deviceStatus.brightness;
234
+ this.LightBulb.Brightness = this.deviceStatus.brightness;
216
235
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
217
236
 
218
237
  // Color, Hue & Brightness
219
- await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
220
- const [red, green, blue] = deviceStatus.color.split(':');
238
+ await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`);
239
+ const [red, green, blue] = this.deviceStatus.color.split(':');
221
240
  await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
222
241
  const [hue, saturation] = rgb2hs(red, green, blue);
223
242
  await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
@@ -231,9 +250,9 @@ export class StripLight extends deviceBase {
231
250
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
232
251
 
233
252
  // Firmware Version
234
- const version = deviceStatus.version.toString();
235
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
236
- if (deviceStatus.version) {
253
+ if (this.deviceStatus.version) {
254
+ const version = this.deviceStatus.version.toString();
255
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
237
256
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
238
257
  this.accessory
239
258
  .getService(this.hap.Service.AccessoryInformation)!
@@ -241,27 +260,28 @@ export class StripLight extends deviceBase {
241
260
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
242
261
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
243
262
  .updateValue(deviceVersion);
244
- this.accessory.context.deviceVersion = deviceVersion;
245
- await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
263
+ this.accessory.context.version = deviceVersion;
264
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
246
265
  }
247
266
  }
248
267
 
249
- async parseStatusWebhook(context: stripLightWebhookContext): Promise<void> {
268
+ async parseStatusWebhook(): Promise<void> {
250
269
  await this.debugLog('parseStatusWebhook');
251
- await this.debugLog(`(powerState, brightness, color) = Webhook:(${context.powerState}, ${context.brightness}, ${context.color}),`
252
- + ` current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
270
+ await this.debugLog(`(powerState, brightness, color) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness},`
271
+ + ` ${this.webhookContext.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
272
+ + ` ${this.LightBulb.Saturation})`);
253
273
 
254
274
  // On
255
- this.LightBulb.On = context.powerState === 'ON' ? true : false;
275
+ this.LightBulb.On = this.webhookContext.powerState === 'ON' ? true : false;
256
276
  await this.debugLog(`On: ${this.LightBulb.On}`);
257
277
 
258
278
  // Brightness
259
- this.LightBulb.Brightness = context.brightness;
279
+ this.LightBulb.Brightness = this.webhookContext.brightness;
260
280
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
261
281
 
262
282
  // Color, Hue & Brightness
263
- await this.debugLog(`color: ${JSON.stringify(context.color)}`);
264
- const [red, green, blue] = context.color.split(':');
283
+ await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`);
284
+ const [red, green, blue] = this.webhookContext.color.split(':');
265
285
  await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
266
286
  const [hue, saturation] = rgb2hs(red, green, blue);
267
287
  await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
@@ -304,7 +324,8 @@ export class StripLight extends deviceBase {
304
324
  const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
305
325
  // Update HomeKit
306
326
  if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
307
- await this.BLEparseStatus(serviceData);
327
+ this.serviceData = serviceData;
328
+ await this.BLEparseStatus();
308
329
  await this.updateHomeKitCharacteristics();
309
330
  } else {
310
331
  await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
@@ -322,7 +343,8 @@ export class StripLight extends deviceBase {
322
343
  await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
323
344
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
324
345
  await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
325
- await this.openAPIparseStatus(deviceStatus.body);
346
+ this.deviceStatus = deviceStatus.body;
347
+ await this.openAPIparseStatus();
326
348
  await this.updateHomeKitCharacteristics();
327
349
  } else {
328
350
  await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
@@ -340,7 +362,8 @@ export class StripLight extends deviceBase {
340
362
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: stripLightWebhookContext) => {
341
363
  try {
342
364
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
343
- await this.parseStatusWebhook(context);
365
+ this.webhookContext = context;
366
+ await this.parseStatusWebhook();
344
367
  await this.updateHomeKitCharacteristics();
345
368
  } catch (e: any) {
346
369
  await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
@@ -752,7 +775,7 @@ export class StripLight extends deviceBase {
752
775
  }
753
776
 
754
777
  async BLERefreshConnection(switchbot: any): Promise<void> {
755
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
778
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
756
779
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
757
780
  await this.warnLog('Using OpenAPI Connection to Refresh Status');
758
781
  await this.openAPIRefreshStatus();