@switchbot/homebridge-switchbot 3.8.3-beta.3 → 3.8.3-beta.31

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 (203) hide show
  1. package/.github/workflows/beta-release.yml +7 -4
  2. package/.github/workflows/release.yml +7 -6
  3. package/CHANGELOG.md +2 -1
  4. package/config.schema.json +24 -0
  5. package/dist/device/blindtilt.d.ts +1 -4
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +33 -34
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +1 -4
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +30 -31
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +1 -4
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +50 -54
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +1 -4
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +62 -66
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +1 -4
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +18 -18
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +1 -4
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +31 -32
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/device.d.ts +6 -6
  30. package/dist/device/device.d.ts.map +1 -1
  31. package/dist/device/device.js +33 -17
  32. package/dist/device/device.js.map +1 -1
  33. package/dist/device/fan.d.ts +1 -4
  34. package/dist/device/fan.d.ts.map +1 -1
  35. package/dist/device/fan.js +47 -49
  36. package/dist/device/fan.js.map +1 -1
  37. package/dist/device/hub.d.ts +1 -4
  38. package/dist/device/hub.d.ts.map +1 -1
  39. package/dist/device/hub.js +18 -18
  40. package/dist/device/hub.js.map +1 -1
  41. package/dist/device/humidifier.d.ts +1 -4
  42. package/dist/device/humidifier.d.ts.map +1 -1
  43. package/dist/device/humidifier.js +43 -46
  44. package/dist/device/humidifier.js.map +1 -1
  45. package/dist/device/iosensor.d.ts +1 -4
  46. package/dist/device/iosensor.d.ts.map +1 -1
  47. package/dist/device/iosensor.js +18 -18
  48. package/dist/device/iosensor.js.map +1 -1
  49. package/dist/device/lightstrip.d.ts +1 -4
  50. package/dist/device/lightstrip.d.ts.map +1 -1
  51. package/dist/device/lightstrip.js +51 -54
  52. package/dist/device/lightstrip.js.map +1 -1
  53. package/dist/device/lock.d.ts +1 -4
  54. package/dist/device/lock.d.ts.map +1 -1
  55. package/dist/device/lock.js +31 -32
  56. package/dist/device/lock.js.map +1 -1
  57. package/dist/device/meter.d.ts +1 -4
  58. package/dist/device/meter.d.ts.map +1 -1
  59. package/dist/device/meter.js +18 -18
  60. package/dist/device/meter.js.map +1 -1
  61. package/dist/device/meterplus.d.ts +1 -4
  62. package/dist/device/meterplus.d.ts.map +1 -1
  63. package/dist/device/meterplus.js +18 -18
  64. package/dist/device/meterplus.js.map +1 -1
  65. package/dist/device/motion.d.ts +1 -4
  66. package/dist/device/motion.d.ts.map +1 -1
  67. package/dist/device/motion.js +18 -18
  68. package/dist/device/motion.js.map +1 -1
  69. package/dist/device/plug.d.ts +1 -4
  70. package/dist/device/plug.d.ts.map +1 -1
  71. package/dist/device/plug.js +29 -30
  72. package/dist/device/plug.js.map +1 -1
  73. package/dist/device/robotvacuumcleaner.d.ts +1 -4
  74. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  75. package/dist/device/robotvacuumcleaner.js +36 -38
  76. package/dist/device/robotvacuumcleaner.js.map +1 -1
  77. package/dist/device/waterdetector.d.ts +1 -4
  78. package/dist/device/waterdetector.d.ts.map +1 -1
  79. package/dist/device/waterdetector.js +18 -18
  80. package/dist/device/waterdetector.js.map +1 -1
  81. package/dist/irdevice/airconditioner.d.ts +1 -1
  82. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  83. package/dist/irdevice/airconditioner.js +11 -12
  84. package/dist/irdevice/airconditioner.js.map +1 -1
  85. package/dist/irdevice/airpurifier.d.ts +1 -1
  86. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  87. package/dist/irdevice/airpurifier.js +11 -12
  88. package/dist/irdevice/airpurifier.js.map +1 -1
  89. package/dist/irdevice/camera.d.ts +1 -1
  90. package/dist/irdevice/camera.d.ts.map +1 -1
  91. package/dist/irdevice/camera.js +9 -10
  92. package/dist/irdevice/camera.js.map +1 -1
  93. package/dist/irdevice/fan.d.ts +1 -1
  94. package/dist/irdevice/fan.d.ts.map +1 -1
  95. package/dist/irdevice/fan.js +15 -16
  96. package/dist/irdevice/fan.js.map +1 -1
  97. package/dist/irdevice/irdevice.d.ts +6 -6
  98. package/dist/irdevice/irdevice.d.ts.map +1 -1
  99. package/dist/irdevice/irdevice.js +7 -13
  100. package/dist/irdevice/irdevice.js.map +1 -1
  101. package/dist/irdevice/light.d.ts +1 -1
  102. package/dist/irdevice/light.d.ts.map +1 -1
  103. package/dist/irdevice/light.js +9 -10
  104. package/dist/irdevice/light.js.map +1 -1
  105. package/dist/irdevice/other.d.ts +1 -1
  106. package/dist/irdevice/other.d.ts.map +1 -1
  107. package/dist/irdevice/other.js +9 -10
  108. package/dist/irdevice/other.js.map +1 -1
  109. package/dist/irdevice/tv.d.ts +1 -1
  110. package/dist/irdevice/tv.d.ts.map +1 -1
  111. package/dist/irdevice/tv.js +27 -28
  112. package/dist/irdevice/tv.js.map +1 -1
  113. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  115. package/dist/irdevice/vacuumcleaner.js +9 -10
  116. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  117. package/dist/irdevice/waterheater.d.ts +1 -1
  118. package/dist/irdevice/waterheater.d.ts.map +1 -1
  119. package/dist/irdevice/waterheater.js +9 -10
  120. package/dist/irdevice/waterheater.js.map +1 -1
  121. package/dist/platform.d.ts +6 -14
  122. package/dist/platform.d.ts.map +1 -1
  123. package/dist/platform.js +127 -188
  124. package/dist/platform.js.map +1 -1
  125. package/dist/settings.d.ts +4 -3
  126. package/dist/settings.d.ts.map +1 -1
  127. package/dist/settings.js.map +1 -1
  128. package/dist/utils.d.ts +1 -1
  129. package/dist/utils.d.ts.map +1 -1
  130. package/dist/utils.js.map +1 -1
  131. package/docs/assets/highlight.css +42 -0
  132. package/docs/assets/main.js +1 -1
  133. package/docs/functions/default.html +1 -1
  134. package/docs/index.html +61 -50
  135. package/docs/media/security-privacy-bluetooth.png +0 -0
  136. package/package.json +14 -15
  137. package/src/device/blindtilt.ts +35 -39
  138. package/src/device/bot.ts +31 -35
  139. package/src/device/ceilinglight.ts +51 -58
  140. package/src/device/colorbulb.ts +63 -70
  141. package/src/device/contact.ts +19 -22
  142. package/src/device/curtain.ts +33 -37
  143. package/src/device/device.ts +32 -21
  144. package/src/device/fan.ts +48 -53
  145. package/src/device/hub.ts +19 -22
  146. package/src/device/humidifier.ts +44 -50
  147. package/src/device/iosensor.ts +19 -22
  148. package/src/device/lightstrip.ts +52 -58
  149. package/src/device/lock.ts +32 -36
  150. package/src/device/meter.ts +19 -22
  151. package/src/device/meterplus.ts +19 -22
  152. package/src/device/motion.ts +19 -22
  153. package/src/device/plug.ts +30 -34
  154. package/src/device/robotvacuumcleaner.ts +37 -46
  155. package/src/device/waterdetector.ts +19 -22
  156. package/src/irdevice/airconditioner.ts +12 -14
  157. package/src/irdevice/airpurifier.ts +12 -13
  158. package/src/irdevice/camera.ts +10 -11
  159. package/src/irdevice/fan.ts +16 -17
  160. package/src/irdevice/irdevice.ts +9 -17
  161. package/src/irdevice/light.ts +10 -11
  162. package/src/irdevice/other.ts +10 -11
  163. package/src/irdevice/tv.ts +28 -29
  164. package/src/irdevice/vacuumcleaner.ts +10 -11
  165. package/src/irdevice/waterheater.ts +10 -11
  166. package/src/platform.ts +131 -188
  167. package/src/settings.ts +8 -4
  168. package/src/utils.ts +2 -1
  169. package/dist/types/bledevicestatus.d.ts +0 -281
  170. package/dist/types/bledevicestatus.d.ts.map +0 -1
  171. package/dist/types/bledevicestatus.js +0 -2
  172. package/dist/types/bledevicestatus.js.map +0 -1
  173. package/dist/types/devicelist.d.ts +0 -89
  174. package/dist/types/devicelist.d.ts.map +0 -1
  175. package/dist/types/devicelist.js +0 -6
  176. package/dist/types/devicelist.js.map +0 -1
  177. package/dist/types/deviceresponse.d.ts +0 -13
  178. package/dist/types/deviceresponse.d.ts.map +0 -1
  179. package/dist/types/deviceresponse.js +0 -2
  180. package/dist/types/deviceresponse.js.map +0 -1
  181. package/dist/types/devicestatus.d.ts +0 -149
  182. package/dist/types/devicestatus.d.ts.map +0 -1
  183. package/dist/types/devicestatus.js +0 -3
  184. package/dist/types/devicestatus.js.map +0 -1
  185. package/dist/types/devicewebhookstatus.d.ts +0 -156
  186. package/dist/types/devicewebhookstatus.d.ts.map +0 -1
  187. package/dist/types/devicewebhookstatus.js +0 -2
  188. package/dist/types/devicewebhookstatus.js.map +0 -1
  189. package/dist/types/irdevicelist.d.ts +0 -10
  190. package/dist/types/irdevicelist.d.ts.map +0 -1
  191. package/dist/types/irdevicelist.js +0 -2
  192. package/dist/types/irdevicelist.js.map +0 -1
  193. package/dist/types/pushbody.d.ts +0 -6
  194. package/dist/types/pushbody.d.ts.map +0 -1
  195. package/dist/types/pushbody.js +0 -2
  196. package/dist/types/pushbody.js.map +0 -1
  197. package/src/types/bledevicestatus.ts +0 -303
  198. package/src/types/devicelist.ts +0 -124
  199. package/src/types/deviceresponse.ts +0 -14
  200. package/src/types/devicestatus.ts +0 -178
  201. package/src/types/devicewebhookstatus.ts +0 -191
  202. package/src/types/irdevicelist.ts +0 -15
  203. package/src/types/pushbody.ts +0 -9
@@ -3,13 +3,10 @@
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
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { lockProServiceData, lockServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { lockProStatus, lockStatus } from '../types/devicestatus.js'
12
- import type { lockProWebhookContext, lockWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -158,7 +155,7 @@ export class Lock extends deviceBase {
158
155
  this.debugLog('Retrieve initial values and update Homekit')
159
156
  this.refreshStatus()
160
157
  } catch (e: any) {
161
- 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}`)
162
159
  }
163
160
 
164
161
  // regisiter webhook event handler if enabled
@@ -166,7 +163,7 @@ export class Lock extends deviceBase {
166
163
  this.debugLog('Registering Webhook Event Handler')
167
164
  this.registerWebhook()
168
165
  } catch (e: any) {
169
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
166
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
170
167
  }
171
168
 
172
169
  // regisiter platform BLE event handler if enabled
@@ -174,7 +171,7 @@ export class Lock extends deviceBase {
174
171
  this.debugLog('Registering Platform BLE Event Handler')
175
172
  this.registerPlatformBLE()
176
173
  } catch (e: any) {
177
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
174
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
178
175
  }
179
176
 
180
177
  // Start an update interval
@@ -222,7 +219,7 @@ export class Lock extends deviceBase {
222
219
 
223
220
  // Contact Sensor
224
221
  if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
225
- this.ContactSensor.ContactSensorState = this.serviceData.door_open === 'opened'
222
+ this.ContactSensor.ContactSensorState = this.serviceData.door_open
226
223
  ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
227
224
  : this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
228
225
  await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
@@ -324,14 +321,14 @@ export class Lock extends deviceBase {
324
321
 
325
322
  async BLERefreshStatus(): Promise<void> {
326
323
  await this.debugLog('BLERefreshStatus')
327
- const switchbot = await this.switchbotBLE()
328
- if (switchbot === undefined) {
329
- await this.BLERefreshConnection(switchbot)
324
+ const switchBotBLE = await this.switchbotBLE()
325
+ if (switchBotBLE === undefined) {
326
+ await this.BLERefreshConnection(switchBotBLE)
330
327
  } else {
331
328
  // Start to monitor advertisement packets
332
329
  (async () => {
333
330
  // Start to monitor advertisement packets
334
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData
331
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as lockServiceData | lockProServiceData
335
332
  // Update HomeKit
336
333
  if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
337
334
  && (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
@@ -339,8 +336,8 @@ export class Lock extends deviceBase {
339
336
  await this.BLEparseStatus()
340
337
  await this.updateHomeKitCharacteristics()
341
338
  } else {
342
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
343
- await this.BLERefreshConnection(switchbot)
339
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
340
+ await this.BLERefreshConnection(switchBotBLE)
344
341
  }
345
342
  })()
346
343
  }
@@ -361,7 +358,7 @@ export class Lock extends deviceBase {
361
358
  await this.BLEparseStatus()
362
359
  await this.updateHomeKitCharacteristics()
363
360
  } catch (e: any) {
364
- 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}`)
365
362
  }
366
363
  }
367
364
  } catch (error) {
@@ -375,17 +372,17 @@ export class Lock extends deviceBase {
375
372
  async openAPIRefreshStatus(): Promise<void> {
376
373
  await this.debugLog('openAPIRefreshStatus')
377
374
  try {
378
- const { body, statusCode } = await this.deviceRefreshStatus()
379
- const deviceStatus: any = await body.json()
380
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
381
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
382
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
375
+ const { body } = await this.deviceRefreshStatus()
376
+ const deviceStatus: any = await body
377
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
378
+ if (await this.successfulStatusCodes(deviceStatus)) {
379
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
383
380
  this.deviceStatus = deviceStatus.body
384
381
  await this.openAPIparseStatus()
385
382
  await this.updateHomeKitCharacteristics()
386
383
  } else {
387
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
388
- await this.debugWarnLog(statusCode, deviceStatus)
384
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
385
+ await this.debugWarnLog(deviceStatus)
389
386
  }
390
387
  } catch (e: any) {
391
388
  await this.apiError(e)
@@ -403,7 +400,7 @@ export class Lock extends deviceBase {
403
400
  await this.parseStatusWebhook()
404
401
  await this.updateHomeKitCharacteristics()
405
402
  } catch (e: any) {
406
- 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}`)
407
404
  }
408
405
  }
409
406
  } else {
@@ -440,13 +437,13 @@ export class Lock extends deviceBase {
440
437
  async BLEpushChanges(): Promise<void> {
441
438
  await this.debugLog('BLEpushChanges')
442
439
  if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
443
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
440
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
444
441
  try {
445
442
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
446
443
  this.device.bleMac = formattedDeviceId
447
444
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
448
- if (switchbot !== false) {
449
- switchbot
445
+ if (switchBotBLE !== false) {
446
+ switchBotBLE
450
447
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
451
448
  .then(async (device_list: any) => {
452
449
  return await this.retryBLE({
@@ -470,7 +467,7 @@ export class Lock extends deviceBase {
470
467
  await this.BLEPushConnection()
471
468
  })
472
469
  } else {
473
- 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)}`)
474
471
  await this.BLEPushConnection()
475
472
  }
476
473
  } catch (error) {
@@ -486,21 +483,20 @@ export class Lock extends deviceBase {
486
483
  if ((this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) || LatchUnlock) {
487
484
  // Determine the command based on the LockTargetState or the forceUnlock parameter
488
485
  const command = LatchUnlock ? 'unlock' : this.LockMechanism.LockTargetState ? 'lock' : 'unlock'
489
- const bodyChange = JSON.stringify({
486
+ const bodyChange: bodyChange = {
490
487
  command: `${command}`,
491
488
  parameter: 'default',
492
489
  commandType: 'command',
493
- })
490
+ }
494
491
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
495
492
  try {
496
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
497
- const deviceStatus: any = await body.json()
498
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
499
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
500
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
493
+ const { body } = await this.pushChangeRequest(bodyChange)
494
+ const deviceStatus: any = await body
495
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
496
+ if (await this.successfulStatusCodes(deviceStatus)) {
497
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
501
498
  await this.updateHomeKitCharacteristics()
502
499
  } else {
503
- await this.statusCode(statusCode)
504
500
  await this.statusCode(deviceStatus.statusCode)
505
501
  }
506
502
  } catch (e: any) {
@@ -549,7 +545,7 @@ export class Lock extends deviceBase {
549
545
  }
550
546
  }).catch(async (e: any) => {
551
547
  // Log the error if the operation failed
552
- await this.debugLog(`Error opening latch: ${e}`)
548
+ await this.debugLog(`Error opening latch: ${e.message ?? e}`)
553
549
  // Ensure we turn the switch back off even in case of an error
554
550
  if (this.Switch?.Service) {
555
551
  this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
@@ -3,13 +3,10 @@
3
3
  * meter.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { device, meterServiceData, meterStatus, meterWebhookContext } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { meterServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { meterStatus } from '../types/devicestatus.js'
12
- import type { meterWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  import { Units } from 'homebridge'
15
12
  /*
@@ -144,7 +141,7 @@ export class Meter extends deviceBase {
144
141
  this.debugLog('Retrieve initial values and update Homekit')
145
142
  this.refreshStatus()
146
143
  } catch (e: any) {
147
- 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}`)
148
145
  }
149
146
 
150
147
  // regisiter webhook event handler if enabled
@@ -152,7 +149,7 @@ export class Meter extends deviceBase {
152
149
  this.debugLog('Registering Webhook Event Handler')
153
150
  this.registerWebhook()
154
151
  } catch (e: any) {
155
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
152
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
156
153
  }
157
154
 
158
155
  // regisiter platform BLE event handler if enabled
@@ -160,7 +157,7 @@ export class Meter extends deviceBase {
160
157
  this.debugLog('Registering Platform BLE Event Handler')
161
158
  this.registerPlatformBLE()
162
159
  } catch (e: any) {
163
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
160
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
164
161
  }
165
162
 
166
163
  // Start an update interval
@@ -280,22 +277,22 @@ export class Meter extends deviceBase {
280
277
 
281
278
  async BLERefreshStatus(): Promise<void> {
282
279
  await this.debugLog('BLERefreshStatus')
283
- const switchbot = await this.switchbotBLE()
284
- if (switchbot === undefined) {
285
- await this.BLERefreshConnection(switchbot)
280
+ const switchBotBLE = await this.switchbotBLE()
281
+ if (switchBotBLE === undefined) {
282
+ await this.BLERefreshConnection(switchBotBLE)
286
283
  } else {
287
284
  // Start to monitor advertisement packets
288
285
  (async () => {
289
286
  // Start to monitor advertisement packets
290
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData
287
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterServiceData
291
288
  // Update HomeKit
292
289
  if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
293
290
  this.serviceData = serviceData
294
291
  await this.BLEparseStatus()
295
292
  await this.updateHomeKitCharacteristics()
296
293
  } else {
297
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
298
- await this.BLERefreshConnection(switchbot)
294
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
295
+ await this.BLERefreshConnection(switchBotBLE)
299
296
  }
300
297
  })()
301
298
  }
@@ -316,7 +313,7 @@ export class Meter extends deviceBase {
316
313
  await this.BLEparseStatus()
317
314
  await this.updateHomeKitCharacteristics()
318
315
  } catch (e: any) {
319
- 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}`)
320
317
  }
321
318
  }
322
319
  } catch (error) {
@@ -330,17 +327,17 @@ export class Meter extends deviceBase {
330
327
  async openAPIRefreshStatus(): Promise<void> {
331
328
  await this.debugLog('openAPIRefreshStatus')
332
329
  try {
333
- const { body, statusCode } = await this.deviceRefreshStatus()
334
- const deviceStatus: any = await body.json()
335
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
336
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
337
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
330
+ const { body } = await this.deviceRefreshStatus()
331
+ const deviceStatus: any = await body
332
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
333
+ if (await this.successfulStatusCodes(deviceStatus)) {
334
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
338
335
  this.deviceStatus = deviceStatus.body
339
336
  await this.openAPIparseStatus()
340
337
  await this.updateHomeKitCharacteristics()
341
338
  } else {
342
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
343
- await this.debugWarnLog(statusCode, deviceStatus)
339
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
340
+ await this.debugWarnLog(deviceStatus)
344
341
  }
345
342
  } catch (e: any) {
346
343
  await this.apiError(e)
@@ -358,7 +355,7 @@ export class Meter extends deviceBase {
358
355
  await this.parseStatusWebhook()
359
356
  await this.updateHomeKitCharacteristics()
360
357
  } catch (e: any) {
361
- 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}`)
362
359
  }
363
360
  }
364
361
  } else {
@@ -3,13 +3,10 @@
3
3
  * meterplus.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { device, meterPlusServiceData, meterPlusStatus, meterPlusWebhookContext } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { meterPlusServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { meterPlusStatus } from '../types/devicestatus.js'
12
- import type { meterPlusWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  import { Units } from 'homebridge'
15
12
  /*
@@ -149,7 +146,7 @@ export class MeterPlus extends deviceBase {
149
146
  this.debugLog('Retrieve initial values and update Homekit')
150
147
  this.refreshStatus()
151
148
  } catch (e: any) {
152
- 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}`)
153
150
  }
154
151
 
155
152
  // regisiter webhook event handler if enabled
@@ -157,7 +154,7 @@ export class MeterPlus extends deviceBase {
157
154
  this.debugLog('Registering Webhook Event Handler')
158
155
  this.registerWebhook()
159
156
  } catch (e: any) {
160
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
157
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
161
158
  }
162
159
 
163
160
  // regisiter platform BLE event handler if enabled
@@ -165,7 +162,7 @@ export class MeterPlus extends deviceBase {
165
162
  this.debugLog('Registering Platform BLE Event Handler')
166
163
  this.registerPlatformBLE()
167
164
  } catch (e: any) {
168
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
165
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
169
166
  }
170
167
 
171
168
  // Start an update interval
@@ -282,22 +279,22 @@ export class MeterPlus extends deviceBase {
282
279
 
283
280
  async BLERefreshStatus(): Promise<void> {
284
281
  await this.debugLog('BLERefreshStatus')
285
- const switchbot = await this.switchbotBLE()
286
- if (switchbot === undefined) {
287
- await this.BLERefreshConnection(switchbot)
282
+ const switchBotBLE = await this.switchbotBLE()
283
+ if (switchBotBLE === undefined) {
284
+ await this.BLERefreshConnection(switchBotBLE)
288
285
  } else {
289
286
  // Start to monitor advertisement packets
290
287
  (async () => {
291
288
  // Start to monitor advertisement packets
292
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterPlusServiceData
289
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterPlusServiceData
293
290
  // Update HomeKit
294
291
  if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
295
292
  this.serviceData = serviceData
296
293
  await this.BLEparseStatus()
297
294
  await this.updateHomeKitCharacteristics()
298
295
  } else {
299
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
300
- await this.BLERefreshConnection(switchbot)
296
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
297
+ await this.BLERefreshConnection(switchBotBLE)
301
298
  }
302
299
  })()
303
300
  }
@@ -318,7 +315,7 @@ export class MeterPlus extends deviceBase {
318
315
  await this.BLEparseStatus()
319
316
  await this.updateHomeKitCharacteristics()
320
317
  } catch (e: any) {
321
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
318
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
322
319
  }
323
320
  }
324
321
  } catch (error) {
@@ -332,17 +329,17 @@ export class MeterPlus extends deviceBase {
332
329
  async openAPIRefreshStatus(): Promise<void> {
333
330
  await this.debugLog('openAPIRefreshStatus')
334
331
  try {
335
- const { body, statusCode } = await this.deviceRefreshStatus()
336
- const deviceStatus: any = await body.json()
337
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
338
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
339
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
332
+ const { body } = await this.deviceRefreshStatus()
333
+ const deviceStatus: any = await body
334
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
335
+ if (await this.successfulStatusCodes(deviceStatus)) {
336
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
340
337
  this.deviceStatus = deviceStatus.body
341
338
  await this.openAPIparseStatus()
342
339
  await this.updateHomeKitCharacteristics()
343
340
  } else {
344
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
345
- await this.debugWarnLog(statusCode, deviceStatus)
341
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
342
+ await this.debugWarnLog(deviceStatus)
346
343
  }
347
344
  } catch (e: any) {
348
345
  await this.apiError(e)
@@ -360,7 +357,7 @@ export class MeterPlus extends deviceBase {
360
357
  await this.parseStatusWebhook()
361
358
  await this.updateHomeKitCharacteristics()
362
359
  } catch (e: any) {
363
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
360
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
364
361
  }
365
362
  }
366
363
  } else {
@@ -3,13 +3,10 @@
3
3
  * motion.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { device, motionSensorServiceData, motionSensorStatus, motionSensorWebhookContext } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { motionSensorServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { motionSensorStatus } from '../types/devicestatus.js'
12
- import type { motionSensorWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -133,7 +130,7 @@ export class Motion extends deviceBase {
133
130
  this.debugLog('Retrieve initial values and update Homekit')
134
131
  this.refreshStatus()
135
132
  } catch (e: any) {
136
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
133
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
137
134
  }
138
135
 
139
136
  // regisiter webhook event handler if enabled
@@ -141,7 +138,7 @@ export class Motion extends deviceBase {
141
138
  this.debugLog('Registering Webhook Event Handler')
142
139
  this.registerWebhook()
143
140
  } catch (e: any) {
144
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
141
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
145
142
  }
146
143
 
147
144
  // regisiter platform BLE event handler if enabled
@@ -149,7 +146,7 @@ export class Motion extends deviceBase {
149
146
  this.debugLog('Registering Platform BLE Event Handler')
150
147
  this.registerPlatformBLE()
151
148
  } catch (e: any) {
152
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
149
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
153
150
  }
154
151
 
155
152
  // Start an update interval
@@ -257,22 +254,22 @@ export class Motion extends deviceBase {
257
254
 
258
255
  async BLERefreshStatus(): Promise<void> {
259
256
  await this.debugLog('BLERefreshStatus')
260
- const switchbot = await this.switchbotBLE()
261
- if (switchbot === undefined) {
262
- await this.BLERefreshConnection(switchbot)
257
+ const switchBotBLE = await this.switchbotBLE()
258
+ if (switchBotBLE === undefined) {
259
+ await this.BLERefreshConnection(switchBotBLE)
263
260
  } else {
264
261
  // Start to monitor advertisement packets
265
262
  (async () => {
266
263
  // Start to monitor advertisement packets
267
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData
264
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as motionSensorServiceData
268
265
  // Update HomeKit
269
266
  if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
270
267
  this.serviceData = serviceData
271
268
  await this.BLEparseStatus()
272
269
  await this.updateHomeKitCharacteristics()
273
270
  } else {
274
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
275
- await this.BLERefreshConnection(switchbot)
271
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
272
+ await this.BLERefreshConnection(switchBotBLE)
276
273
  }
277
274
  })()
278
275
  }
@@ -293,7 +290,7 @@ export class Motion extends deviceBase {
293
290
  await this.BLEparseStatus()
294
291
  await this.updateHomeKitCharacteristics()
295
292
  } catch (e: any) {
296
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
293
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
297
294
  }
298
295
  }
299
296
  } catch (error) {
@@ -307,17 +304,17 @@ export class Motion extends deviceBase {
307
304
  async openAPIRefreshStatus(): Promise<void> {
308
305
  await this.debugLog('openAPIRefreshStatus')
309
306
  try {
310
- const { body, statusCode } = await this.deviceRefreshStatus()
311
- const deviceStatus: any = await body.json()
312
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
313
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
314
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
307
+ const { body } = await this.deviceRefreshStatus()
308
+ const deviceStatus: any = await body
309
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
310
+ if (await this.successfulStatusCodes(deviceStatus)) {
311
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
315
312
  this.deviceStatus = deviceStatus.body
316
313
  await this.openAPIparseStatus()
317
314
  await this.updateHomeKitCharacteristics()
318
315
  } else {
319
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
320
- await this.debugWarnLog(statusCode, deviceStatus)
316
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
317
+ await this.debugWarnLog(deviceStatus)
321
318
  }
322
319
  } catch (e: any) {
323
320
  await this.apiError(e)
@@ -335,7 +332,7 @@ export class Motion extends deviceBase {
335
332
  await this.parseStatusWebhook()
336
333
  await this.updateHomeKitCharacteristics()
337
334
  } catch (e: any) {
338
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
335
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
339
336
  }
340
337
  }
341
338
  } else {