@switchbot/homebridge-switchbot 3.8.3-beta.30 → 3.8.3-beta.32

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 (80) hide show
  1. package/.github/workflows/release.yml +1 -1
  2. package/CHANGELOG.md +2 -1
  3. package/config.schema.json +24 -0
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +26 -23
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +30 -22
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +18 -17
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +35 -32
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.js +11 -11
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts.map +1 -1
  19. package/dist/device/curtain.js +21 -20
  20. package/dist/device/curtain.js.map +1 -1
  21. package/dist/device/device.js +8 -8
  22. package/dist/device/device.js.map +1 -1
  23. package/dist/device/fan.d.ts.map +1 -1
  24. package/dist/device/fan.js +18 -17
  25. package/dist/device/fan.js.map +1 -1
  26. package/dist/device/hub.js +11 -11
  27. package/dist/device/hub.js.map +1 -1
  28. package/dist/device/humidifier.d.ts.map +1 -1
  29. package/dist/device/humidifier.js +17 -16
  30. package/dist/device/humidifier.js.map +1 -1
  31. package/dist/device/iosensor.js +11 -11
  32. package/dist/device/iosensor.js.map +1 -1
  33. package/dist/device/lightstrip.d.ts.map +1 -1
  34. package/dist/device/lightstrip.js +26 -25
  35. package/dist/device/lightstrip.js.map +1 -1
  36. package/dist/device/lock.d.ts.map +1 -1
  37. package/dist/device/lock.js +16 -16
  38. package/dist/device/lock.js.map +1 -1
  39. package/dist/device/meter.js +11 -11
  40. package/dist/device/meter.js.map +1 -1
  41. package/dist/device/meterplus.js +11 -11
  42. package/dist/device/meterplus.js.map +1 -1
  43. package/dist/device/motion.js +11 -11
  44. package/dist/device/motion.js.map +1 -1
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +18 -17
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  49. package/dist/device/robotvacuumcleaner.js +18 -17
  50. package/dist/device/robotvacuumcleaner.js.map +1 -1
  51. package/dist/device/waterdetector.js +11 -11
  52. package/dist/device/waterdetector.js.map +1 -1
  53. package/dist/platform.d.ts.map +1 -1
  54. package/dist/platform.js +80 -76
  55. package/dist/platform.js.map +1 -1
  56. package/dist/settings.d.ts +3 -0
  57. package/dist/settings.d.ts.map +1 -1
  58. package/dist/settings.js.map +1 -1
  59. package/package.json +3 -3
  60. package/src/device/blindtilt.ts +29 -26
  61. package/src/device/bot.ts +34 -26
  62. package/src/device/ceilinglight.ts +20 -19
  63. package/src/device/colorbulb.ts +40 -37
  64. package/src/device/contact.ts +11 -11
  65. package/src/device/curtain.ts +25 -23
  66. package/src/device/device.ts +8 -8
  67. package/src/device/fan.ts +20 -19
  68. package/src/device/hub.ts +11 -11
  69. package/src/device/humidifier.ts +19 -18
  70. package/src/device/iosensor.ts +11 -11
  71. package/src/device/lightstrip.ts +30 -29
  72. package/src/device/lock.ts +18 -18
  73. package/src/device/meter.ts +11 -11
  74. package/src/device/meterplus.ts +11 -11
  75. package/src/device/motion.ts +11 -11
  76. package/src/device/plug.ts +20 -19
  77. package/src/device/robotvacuumcleaner.ts +20 -19
  78. package/src/device/waterdetector.ts +11 -11
  79. package/src/platform.ts +82 -78
  80. package/src/settings.ts +3 -0
package/src/device/hub.ts CHANGED
@@ -146,7 +146,7 @@ export class Hub extends deviceBase {
146
146
  this.debugLog('Retrieve initial values and update Homekit')
147
147
  this.refreshStatus()
148
148
  } catch (e: any) {
149
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
149
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
150
150
  }
151
151
 
152
152
  // regisiter webhook event handler if enabled
@@ -154,7 +154,7 @@ export class Hub extends deviceBase {
154
154
  this.debugLog('Registering Webhook Event Handler')
155
155
  this.registerWebhook()
156
156
  } catch (e: any) {
157
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
157
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
158
158
  }
159
159
 
160
160
  // regisiter platform BLE event handler if enabled
@@ -162,7 +162,7 @@ export class Hub extends deviceBase {
162
162
  this.debugLog('Registering Platform BLE Event Handler')
163
163
  this.registerPlatformBLE()
164
164
  } catch (e: any) {
165
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
165
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
166
166
  }
167
167
 
168
168
  // Start an update interval
@@ -287,22 +287,22 @@ export class Hub extends deviceBase {
287
287
 
288
288
  async BLERefreshStatus(): Promise<void> {
289
289
  await this.debugLog('BLERefreshStatus')
290
- const switchbot = await this.switchbotBLE()
291
- if (switchbot === undefined) {
292
- await this.BLERefreshConnection(switchbot)
290
+ const switchBotBLE = await this.switchbotBLE()
291
+ if (switchBotBLE === undefined) {
292
+ await this.BLERefreshConnection(switchBotBLE)
293
293
  } else {
294
294
  // Start to monitor advertisement packets
295
295
  (async () => {
296
296
  // Start to monitor advertisement packets
297
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as hub2ServiceData
297
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as hub2ServiceData
298
298
  // Update HomeKit
299
299
  if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
300
300
  this.serviceData = serviceData
301
301
  await this.BLEparseStatus()
302
302
  await this.updateHomeKitCharacteristics()
303
303
  } else {
304
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
305
- await this.BLERefreshConnection(switchbot)
304
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
305
+ await this.BLERefreshConnection(switchBotBLE)
306
306
  }
307
307
  })()
308
308
  }
@@ -323,7 +323,7 @@ export class Hub extends deviceBase {
323
323
  await this.BLEparseStatus()
324
324
  await this.updateHomeKitCharacteristics()
325
325
  } catch (e: any) {
326
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
326
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
327
327
  }
328
328
  }
329
329
  } catch (error) {
@@ -365,7 +365,7 @@ export class Hub extends deviceBase {
365
365
  await this.parseStatusWebhook()
366
366
  await this.updateHomeKitCharacteristics()
367
367
  } catch (e: any) {
368
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
368
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
369
369
  }
370
370
  }
371
371
  } else {
@@ -3,7 +3,7 @@
3
3
  * humidifier.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
- import type { bodyChange, device, humidifierServiceData, humidifierStatus, humidifierWebhookContext } from 'node-switchbot'
6
+ import type { bodyChange, device, humidifierServiceData, humidifierStatus, humidifierWebhookContext, SwitchbotDevice, WoHumi } from 'node-switchbot'
7
7
 
8
8
  import type { SwitchBotPlatform } from '../platform.js'
9
9
  import type { devicesConfig } from '../settings.js'
@@ -137,7 +137,7 @@ export class Humidifier extends deviceBase {
137
137
  this.debugLog('Retrieve initial values and update Homekit')
138
138
  this.refreshStatus()
139
139
  } catch (e: any) {
140
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
140
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
141
141
  }
142
142
 
143
143
  // regisiter webhook event handler if enabled
@@ -145,7 +145,7 @@ export class Humidifier extends deviceBase {
145
145
  this.debugLog('Registering Webhook Event Handler')
146
146
  this.registerWebhook()
147
147
  } catch (e: any) {
148
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
148
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
149
149
  }
150
150
 
151
151
  // regisiter platform BLE event handler if enabled
@@ -153,7 +153,7 @@ export class Humidifier extends deviceBase {
153
153
  this.debugLog('Registering Platform BLE Event Handler')
154
154
  this.registerPlatformBLE()
155
155
  } catch (e: any) {
156
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
156
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
157
157
  }
158
158
 
159
159
  // Start an update interval
@@ -317,22 +317,22 @@ export class Humidifier extends deviceBase {
317
317
 
318
318
  async BLERefreshStatus(): Promise<void> {
319
319
  await this.debugLog('BLERefreshStatus')
320
- const switchbot = await this.switchbotBLE()
321
- if (switchbot === undefined) {
322
- await this.BLERefreshConnection(switchbot)
320
+ const switchBotBLE = await this.switchbotBLE()
321
+ if (switchBotBLE === undefined) {
322
+ await this.BLERefreshConnection(switchBotBLE)
323
323
  } else {
324
324
  // Start to monitor advertisement packets
325
325
  (async () => {
326
326
  // Start to monitor advertisement packets
327
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData
327
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as humidifierServiceData
328
328
  // Update HomeKit
329
329
  if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
330
330
  this.serviceData = serviceData
331
331
  await this.BLEparseStatus()
332
332
  await this.updateHomeKitCharacteristics()
333
333
  } else {
334
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
335
- await this.BLERefreshConnection(switchbot)
334
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
335
+ await this.BLERefreshConnection(switchBotBLE)
336
336
  }
337
337
  })()
338
338
  }
@@ -353,7 +353,7 @@ export class Humidifier extends deviceBase {
353
353
  await this.BLEparseStatus()
354
354
  await this.updateHomeKitCharacteristics()
355
355
  } catch (e: any) {
356
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
356
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
357
357
  }
358
358
  }
359
359
  } catch (error) {
@@ -395,7 +395,7 @@ export class Humidifier extends deviceBase {
395
395
  await this.parseStatusWebhook()
396
396
  await this.updateHomeKitCharacteristics()
397
397
  } catch (e: any) {
398
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
398
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
399
399
  }
400
400
  }
401
401
  }
@@ -429,16 +429,17 @@ export class Humidifier extends deviceBase {
429
429
  if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
430
430
  && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
431
431
  && (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
432
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
432
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
433
433
  try {
434
434
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
435
435
  this.device.bleMac = formattedDeviceId
436
436
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
437
- if (switchbot !== false) {
438
- switchbot
437
+ if (switchBotBLE !== false) {
438
+ switchBotBLE
439
439
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
440
- .then(async (device_list: any) => {
441
- return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
440
+ .then(async (device_list: SwitchbotDevice[]) => {
441
+ const deviceList = device_list as unknown as WoHumi[]
442
+ return await deviceList[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
442
443
  })
443
444
  .then(async () => {
444
445
  await this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold} sent over BLE, sent successfully`)
@@ -450,7 +451,7 @@ export class Humidifier extends deviceBase {
450
451
  await this.BLEPushConnection()
451
452
  })
452
453
  } else {
453
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
454
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
454
455
  await this.BLEPushConnection()
455
456
  }
456
457
  } catch (error) {
@@ -148,7 +148,7 @@ export class IOSensor extends deviceBase {
148
148
  this.debugLog('Retrieve initial values and update Homekit')
149
149
  this.refreshStatus()
150
150
  } catch (e: any) {
151
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
151
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
152
152
  }
153
153
 
154
154
  // regisiter webhook event handler if enabled
@@ -156,7 +156,7 @@ export class IOSensor extends deviceBase {
156
156
  this.debugLog('Registering Webhook Event Handler')
157
157
  this.registerWebhook()
158
158
  } catch (e: any) {
159
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
159
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
160
160
  }
161
161
 
162
162
  // regisiter platform BLE event handler if enabled
@@ -164,7 +164,7 @@ export class IOSensor extends deviceBase {
164
164
  this.debugLog('Registering Platform BLE Event Handler')
165
165
  this.registerPlatformBLE()
166
166
  } catch (e: any) {
167
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
167
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
168
168
  }
169
169
 
170
170
  // Start an update interval
@@ -282,22 +282,22 @@ export class IOSensor extends deviceBase {
282
282
 
283
283
  async BLERefreshStatus(): Promise<void> {
284
284
  await this.debugLog('BLERefreshStatus')
285
- const switchbot = await this.switchbotBLE()
286
- if (switchbot === undefined) {
287
- await this.BLERefreshConnection(switchbot)
285
+ const switchBotBLE = await this.switchbotBLE()
286
+ if (switchBotBLE === undefined) {
287
+ await this.BLERefreshConnection(switchBotBLE)
288
288
  } else {
289
289
  // Start to monitor advertisement packets
290
290
  (async () => {
291
291
  // Start to monitor advertisement packets
292
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData
292
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as outdoorMeterServiceData
293
293
  // Update HomeKit
294
294
  if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
295
295
  this.serviceData = serviceData
296
296
  await this.BLEparseStatus()
297
297
  await this.updateHomeKitCharacteristics()
298
298
  } else {
299
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
300
- await this.BLERefreshConnection(switchbot)
299
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
300
+ await this.BLERefreshConnection(switchBotBLE)
301
301
  }
302
302
  })()
303
303
  }
@@ -318,7 +318,7 @@ export class IOSensor extends deviceBase {
318
318
  await this.BLEparseStatus()
319
319
  await this.updateHomeKitCharacteristics()
320
320
  } catch (e: any) {
321
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
321
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
322
322
  }
323
323
  }
324
324
  } catch (error) {
@@ -360,7 +360,7 @@ export class IOSensor extends deviceBase {
360
360
  await this.parseStatusWebhook()
361
361
  await this.updateHomeKitCharacteristics()
362
362
  } catch (e: any) {
363
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
363
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
364
364
  }
365
365
  }
366
366
  } else {
@@ -3,7 +3,7 @@
3
3
  * lightstrip.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
6
- import type { bodyChange, device, stripLightServiceData, stripLightStatus, stripLightWebhookContext } from 'node-switchbot'
6
+ import type { bodyChange, device, stripLightServiceData, stripLightStatus, stripLightWebhookContext, SwitchbotDevice, WoStrip } from 'node-switchbot'
7
7
 
8
8
  import type { SwitchBotPlatform } from '../platform.js'
9
9
  import type { devicesConfig } from '../settings.js'
@@ -148,7 +148,7 @@ export class StripLight extends deviceBase {
148
148
  this.debugLog('Retrieve initial values and update Homekit')
149
149
  this.refreshStatus()
150
150
  } catch (e: any) {
151
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
151
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
152
152
  }
153
153
 
154
154
  // regisiter webhook event handler if enabled
@@ -156,7 +156,7 @@ export class StripLight extends deviceBase {
156
156
  this.debugLog('Registering Webhook Event Handler')
157
157
  this.registerWebhook()
158
158
  } catch (e: any) {
159
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
159
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
160
160
  }
161
161
 
162
162
  // regisiter platform BLE event handler if enabled
@@ -164,7 +164,7 @@ export class StripLight extends deviceBase {
164
164
  this.debugLog('Registering Platform BLE Event Handler')
165
165
  this.registerPlatformBLE()
166
166
  } catch (e: any) {
167
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
167
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
168
168
  }
169
169
 
170
170
  // Start an update interval
@@ -309,22 +309,22 @@ export class StripLight extends deviceBase {
309
309
 
310
310
  async BLERefreshStatus(): Promise<void> {
311
311
  await this.debugLog('BLERefreshStatus')
312
- const switchbot = await this.switchbotBLE()
313
- if (switchbot === undefined) {
314
- await this.BLERefreshConnection(switchbot)
312
+ const switchBotBLE = await this.switchbotBLE()
313
+ if (switchBotBLE === undefined) {
314
+ await this.BLERefreshConnection(switchBotBLE)
315
315
  } else {
316
316
  // Start to monitor advertisement packets
317
317
  (async () => {
318
318
  // Start to monitor advertisement packets
319
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData
319
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as stripLightServiceData
320
320
  // Update HomeKit
321
321
  if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
322
322
  this.serviceData = serviceData
323
323
  await this.BLEparseStatus()
324
324
  await this.updateHomeKitCharacteristics()
325
325
  } else {
326
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
327
- await this.BLERefreshConnection(switchbot)
326
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
327
+ await this.BLERefreshConnection(switchBotBLE)
328
328
  }
329
329
  })()
330
330
  }
@@ -345,7 +345,7 @@ export class StripLight extends deviceBase {
345
345
  await this.BLEparseStatus()
346
346
  await this.updateHomeKitCharacteristics()
347
347
  } catch (e: any) {
348
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
348
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
349
349
  }
350
350
  }
351
351
  } catch (error) {
@@ -387,7 +387,7 @@ export class StripLight extends deviceBase {
387
387
  await this.parseStatusWebhook()
388
388
  await this.updateHomeKitCharacteristics()
389
389
  } catch (e: any) {
390
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
390
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
391
391
  }
392
392
  }
393
393
  } else {
@@ -456,23 +456,24 @@ export class StripLight extends deviceBase {
456
456
  await this.debugLog('BLEpushChanges')
457
457
  if (this.LightBulb.On !== this.accessory.context.On) {
458
458
  await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
459
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
459
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
460
460
  try {
461
461
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
462
462
  this.device.bleMac = formattedDeviceId
463
463
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
464
- if (switchbot !== false) {
465
- switchbot
464
+ if (switchBotBLE !== false) {
465
+ switchBotBLE
466
466
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
467
- .then(async (device_list: any) => {
467
+ .then(async (device_list: SwitchbotDevice[]) => {
468
+ const deviceList = device_list as unknown as WoStrip[]
468
469
  await this.infoLog(`On: ${this.LightBulb.On}`)
469
470
  return await this.retryBLE({
470
471
  max: await this.maxRetryBLE(),
471
472
  fn: async () => {
472
473
  if (this.LightBulb.On) {
473
- return await device_list[0].turnOn({ id: this.device.bleMac })
474
+ return await deviceList[0].turnOn()
474
475
  } else {
475
- return await device_list[0].turnOff({ id: this.device.bleMac })
476
+ return await deviceList[0].turnOff()
476
477
  }
477
478
  },
478
479
  })
@@ -487,7 +488,7 @@ export class StripLight extends deviceBase {
487
488
  await this.BLEPushConnection()
488
489
  })
489
490
  } else {
490
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
491
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
491
492
  await this.BLEPushConnection()
492
493
  }
493
494
  } catch (error) {
@@ -501,15 +502,15 @@ export class StripLight extends deviceBase {
501
502
  async BLEpushBrightnessChanges(): Promise<void> {
502
503
  await this.debugLog('BLEpushBrightnessChanges')
503
504
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
504
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
505
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
505
506
  try {
506
507
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
507
508
  this.device.bleMac = formattedDeviceId
508
509
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
509
- if (switchbot !== false) {
510
- switchbot
510
+ if (switchBotBLE !== false) {
511
+ switchBotBLE
511
512
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
512
- .then(async (device_list: any) => {
513
+ .then(async (device_list: SwitchbotDevice[]) => {
513
514
  await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
514
515
  return await device_list[0].setBrightness(this.LightBulb.Brightness)
515
516
  })
@@ -523,7 +524,7 @@ export class StripLight extends deviceBase {
523
524
  await this.BLEPushConnection()
524
525
  })
525
526
  } else {
526
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
527
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
527
528
  await this.BLEPushConnection()
528
529
  }
529
530
  } catch (error) {
@@ -540,15 +541,15 @@ export class StripLight extends deviceBase {
540
541
  await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
541
542
  const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
542
543
  await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
543
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
544
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
544
545
  try {
545
546
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
546
547
  this.device.bleMac = formattedDeviceId
547
548
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
548
- if (switchbot !== false) {
549
- switchbot
549
+ if (switchBotBLE !== false) {
550
+ switchBotBLE
550
551
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
551
- .then(async (device_list: any) => {
552
+ .then(async (device_list: SwitchbotDevice[]) => {
552
553
  await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
553
554
  return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
554
555
  })
@@ -562,7 +563,7 @@ export class StripLight extends deviceBase {
562
563
  await this.BLEPushConnection()
563
564
  })
564
565
  } else {
565
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
566
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
566
567
  await this.BLEPushConnection()
567
568
  }
568
569
  } catch (error) {
@@ -3,7 +3,7 @@
3
3
  * lock.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
- import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext } from 'node-switchbot'
6
+ import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext, SwitchbotDevice } from 'node-switchbot'
7
7
 
8
8
  import type { SwitchBotPlatform } from '../platform.js'
9
9
  import type { devicesConfig } from '../settings.js'
@@ -155,7 +155,7 @@ export class Lock extends deviceBase {
155
155
  this.debugLog('Retrieve initial values and update Homekit')
156
156
  this.refreshStatus()
157
157
  } catch (e: any) {
158
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
158
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
159
159
  }
160
160
 
161
161
  // regisiter webhook event handler if enabled
@@ -163,7 +163,7 @@ export class Lock extends deviceBase {
163
163
  this.debugLog('Registering Webhook Event Handler')
164
164
  this.registerWebhook()
165
165
  } catch (e: any) {
166
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
166
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
167
167
  }
168
168
 
169
169
  // regisiter platform BLE event handler if enabled
@@ -171,7 +171,7 @@ export class Lock extends deviceBase {
171
171
  this.debugLog('Registering Platform BLE Event Handler')
172
172
  this.registerPlatformBLE()
173
173
  } catch (e: any) {
174
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
174
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
175
175
  }
176
176
 
177
177
  // Start an update interval
@@ -321,14 +321,14 @@ export class Lock extends deviceBase {
321
321
 
322
322
  async BLERefreshStatus(): Promise<void> {
323
323
  await this.debugLog('BLERefreshStatus')
324
- const switchbot = await this.switchbotBLE()
325
- if (switchbot === undefined) {
326
- await this.BLERefreshConnection(switchbot)
324
+ const switchBotBLE = await this.switchbotBLE()
325
+ if (switchBotBLE === undefined) {
326
+ await this.BLERefreshConnection(switchBotBLE)
327
327
  } else {
328
328
  // Start to monitor advertisement packets
329
329
  (async () => {
330
330
  // Start to monitor advertisement packets
331
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData
331
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as lockServiceData | lockProServiceData
332
332
  // Update HomeKit
333
333
  if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
334
334
  && (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
@@ -336,8 +336,8 @@ export class Lock extends deviceBase {
336
336
  await this.BLEparseStatus()
337
337
  await this.updateHomeKitCharacteristics()
338
338
  } else {
339
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
340
- await this.BLERefreshConnection(switchbot)
339
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
340
+ await this.BLERefreshConnection(switchBotBLE)
341
341
  }
342
342
  })()
343
343
  }
@@ -358,7 +358,7 @@ export class Lock extends deviceBase {
358
358
  await this.BLEparseStatus()
359
359
  await this.updateHomeKitCharacteristics()
360
360
  } catch (e: any) {
361
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
361
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
362
362
  }
363
363
  }
364
364
  } catch (error) {
@@ -400,7 +400,7 @@ export class Lock extends deviceBase {
400
400
  await this.parseStatusWebhook()
401
401
  await this.updateHomeKitCharacteristics()
402
402
  } catch (e: any) {
403
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
403
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
404
404
  }
405
405
  }
406
406
  } else {
@@ -437,15 +437,15 @@ export class Lock extends deviceBase {
437
437
  async BLEpushChanges(): Promise<void> {
438
438
  await this.debugLog('BLEpushChanges')
439
439
  if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
440
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
440
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
441
441
  try {
442
442
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
443
443
  this.device.bleMac = formattedDeviceId
444
444
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
445
- if (switchbot !== false) {
446
- switchbot
445
+ if (switchBotBLE !== false) {
446
+ switchBotBLE
447
447
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
448
- .then(async (device_list: any) => {
448
+ .then(async (device_list: SwitchbotDevice[]) => {
449
449
  return await this.retryBLE({
450
450
  max: await this.maxRetryBLE(),
451
451
  fn: async () => {
@@ -467,7 +467,7 @@ export class Lock extends deviceBase {
467
467
  await this.BLEPushConnection()
468
468
  })
469
469
  } else {
470
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
470
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
471
471
  await this.BLEPushConnection()
472
472
  }
473
473
  } catch (error) {
@@ -545,7 +545,7 @@ export class Lock extends deviceBase {
545
545
  }
546
546
  }).catch(async (e: any) => {
547
547
  // Log the error if the operation failed
548
- await this.debugLog(`Error opening latch: ${e}`)
548
+ await this.debugLog(`Error opening latch: ${e.message ?? e}`)
549
549
  // Ensure we turn the switch back off even in case of an error
550
550
  if (this.Switch?.Service) {
551
551
  this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
@@ -141,7 +141,7 @@ export class Meter extends deviceBase {
141
141
  this.debugLog('Retrieve initial values and update Homekit')
142
142
  this.refreshStatus()
143
143
  } catch (e: any) {
144
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
144
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
145
145
  }
146
146
 
147
147
  // regisiter webhook event handler if enabled
@@ -149,7 +149,7 @@ export class Meter extends deviceBase {
149
149
  this.debugLog('Registering Webhook Event Handler')
150
150
  this.registerWebhook()
151
151
  } catch (e: any) {
152
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
152
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
153
153
  }
154
154
 
155
155
  // regisiter platform BLE event handler if enabled
@@ -157,7 +157,7 @@ export class Meter extends deviceBase {
157
157
  this.debugLog('Registering Platform BLE Event Handler')
158
158
  this.registerPlatformBLE()
159
159
  } catch (e: any) {
160
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
160
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
161
161
  }
162
162
 
163
163
  // Start an update interval
@@ -277,22 +277,22 @@ export class Meter extends deviceBase {
277
277
 
278
278
  async BLERefreshStatus(): Promise<void> {
279
279
  await this.debugLog('BLERefreshStatus')
280
- const switchbot = await this.switchbotBLE()
281
- if (switchbot === undefined) {
282
- await this.BLERefreshConnection(switchbot)
280
+ const switchBotBLE = await this.switchbotBLE()
281
+ if (switchBotBLE === undefined) {
282
+ await this.BLERefreshConnection(switchBotBLE)
283
283
  } else {
284
284
  // Start to monitor advertisement packets
285
285
  (async () => {
286
286
  // Start to monitor advertisement packets
287
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData
287
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterServiceData
288
288
  // Update HomeKit
289
289
  if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
290
290
  this.serviceData = serviceData
291
291
  await this.BLEparseStatus()
292
292
  await this.updateHomeKitCharacteristics()
293
293
  } else {
294
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
295
- await this.BLERefreshConnection(switchbot)
294
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
295
+ await this.BLERefreshConnection(switchBotBLE)
296
296
  }
297
297
  })()
298
298
  }
@@ -313,7 +313,7 @@ export class Meter extends deviceBase {
313
313
  await this.BLEparseStatus()
314
314
  await this.updateHomeKitCharacteristics()
315
315
  } catch (e: any) {
316
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
316
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
317
317
  }
318
318
  }
319
319
  } catch (error) {
@@ -355,7 +355,7 @@ export class Meter extends deviceBase {
355
355
  await this.parseStatusWebhook()
356
356
  await this.updateHomeKitCharacteristics()
357
357
  } catch (e: any) {
358
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
358
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
359
359
  }
360
360
  }
361
361
  } else {