@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
  * blindtilt.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
6
+ import type { bodyChange, colorBulbServiceData, colorBulbStatus, colorBulbWebhookContext, device } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { colorBulbServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { colorBulbStatus } from '../types/devicestatus.js'
12
- import type { colorBulbWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -147,7 +144,7 @@ export class ColorBulb extends deviceBase {
147
144
  this.debugLog('Retrieve initial values and update Homekit')
148
145
  this.refreshStatus()
149
146
  } catch (e: any) {
150
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
147
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
151
148
  }
152
149
 
153
150
  // regisiter webhook event handler if enabled
@@ -155,7 +152,7 @@ export class ColorBulb extends deviceBase {
155
152
  this.debugLog('Registering Webhook Event Handler')
156
153
  this.registerWebhook()
157
154
  } catch (e: any) {
158
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
155
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
159
156
  }
160
157
 
161
158
  // regisiter platform BLE event handler if enabled
@@ -163,7 +160,7 @@ export class ColorBulb extends deviceBase {
163
160
  this.debugLog('Registering Platform BLE Event Handler')
164
161
  this.registerPlatformBLE()
165
162
  } catch (e: any) {
166
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
163
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
167
164
  }
168
165
 
169
166
  // Start an update interval
@@ -308,22 +305,22 @@ export class ColorBulb extends deviceBase {
308
305
 
309
306
  async BLERefreshStatus(): Promise<void> {
310
307
  await this.debugLog('BLERefreshStatus')
311
- const switchbot = await this.switchbotBLE()
312
- if (switchbot === undefined) {
313
- await this.BLERefreshConnection(switchbot)
308
+ const switchBotBLE = await this.switchbotBLE()
309
+ if (switchBotBLE === undefined) {
310
+ await this.BLERefreshConnection(switchBotBLE)
314
311
  } else {
315
312
  // Start to monitor advertisement packets
316
313
  (async () => {
317
314
  // Start to monitor advertisement packets
318
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData
315
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as colorBulbServiceData
319
316
  // Update HomeKit
320
317
  if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
321
318
  this.serviceData = serviceData
322
319
  await this.BLEparseStatus()
323
320
  await this.updateHomeKitCharacteristics()
324
321
  } else {
325
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
326
- await this.BLERefreshConnection(switchbot)
322
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
323
+ await this.BLERefreshConnection(switchBotBLE)
327
324
  }
328
325
  })()
329
326
  }
@@ -344,7 +341,7 @@ export class ColorBulb extends deviceBase {
344
341
  await this.BLEparseStatus()
345
342
  await this.updateHomeKitCharacteristics()
346
343
  } catch (e: any) {
347
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
344
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
348
345
  }
349
346
  }
350
347
  } catch (error) {
@@ -358,17 +355,17 @@ export class ColorBulb extends deviceBase {
358
355
  async openAPIRefreshStatus(): Promise<void> {
359
356
  await this.debugLog('openAPIRefreshStatus')
360
357
  try {
361
- const { body, statusCode } = await this.deviceRefreshStatus()
362
- const deviceStatus: any = await body.json()
363
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
364
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
365
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
358
+ const { body } = await this.deviceRefreshStatus()
359
+ const deviceStatus: any = await body
360
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
361
+ if (await this.successfulStatusCodes(deviceStatus)) {
362
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
366
363
  this.deviceStatus = deviceStatus.body
367
364
  await this.openAPIparseStatus()
368
365
  await this.updateHomeKitCharacteristics()
369
366
  } else {
370
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
371
- await this.debugWarnLog(statusCode, deviceStatus)
367
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
368
+ await this.debugWarnLog(deviceStatus)
372
369
  }
373
370
  } catch (e: any) {
374
371
  await this.apiError(e)
@@ -386,7 +383,7 @@ export class ColorBulb extends deviceBase {
386
383
  await this.parseStatusWebhook()
387
384
  await this.updateHomeKitCharacteristics()
388
385
  } catch (e: any) {
389
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
386
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
390
387
  }
391
388
  }
392
389
  } else {
@@ -455,13 +452,13 @@ export class ColorBulb extends deviceBase {
455
452
  await this.debugLog('BLEpushChanges')
456
453
  if (this.LightBulb.On !== this.accessory.context.On) {
457
454
  await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
458
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
455
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
459
456
  try {
460
457
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
461
458
  this.device.bleMac = formattedDeviceId
462
459
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
463
- if (switchbot !== false) {
464
- switchbot
460
+ if (switchBotBLE !== false) {
461
+ switchBotBLE
465
462
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
466
463
  .then(async (device_list: any) => {
467
464
  await this.infoLog(`On: ${this.LightBulb.On}`)
@@ -486,7 +483,7 @@ export class ColorBulb extends deviceBase {
486
483
  await this.BLEPushConnection()
487
484
  })
488
485
  } else {
489
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
486
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
490
487
  await this.BLEPushConnection()
491
488
  }
492
489
  } catch (error) {
@@ -500,13 +497,13 @@ export class ColorBulb extends deviceBase {
500
497
  async BLEpushBrightnessChanges(): Promise<void> {
501
498
  await this.debugLog('BLEpushBrightnessChanges')
502
499
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
503
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
500
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
504
501
  try {
505
502
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
506
503
  this.device.bleMac = formattedDeviceId
507
504
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
508
- if (switchbot !== false) {
509
- switchbot
505
+ if (switchBotBLE !== false) {
506
+ switchBotBLE
510
507
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
511
508
  .then(async (device_list: any) => {
512
509
  await this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`)
@@ -522,7 +519,7 @@ export class ColorBulb extends deviceBase {
522
519
  await this.BLEPushConnection()
523
520
  })
524
521
  } else {
525
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
522
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
526
523
  await this.BLEPushConnection()
527
524
  }
528
525
  } catch (error) {
@@ -538,13 +535,13 @@ export class ColorBulb extends deviceBase {
538
535
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
539
536
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
540
537
  this.accessory.context.kelvin = kelvin
541
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
538
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
542
539
  try {
543
540
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
544
541
  this.device.bleMac = formattedDeviceId
545
542
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
546
- if (switchbot !== false) {
547
- switchbot
543
+ if (switchBotBLE !== false) {
544
+ switchBotBLE
548
545
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
549
546
  .then(async (device_list: any) => {
550
547
  await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
@@ -560,7 +557,7 @@ export class ColorBulb extends deviceBase {
560
557
  await this.BLEPushConnection()
561
558
  })
562
559
  } else {
563
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
560
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
564
561
  await this.BLEPushConnection()
565
562
  }
566
563
  } catch (error) {
@@ -577,13 +574,13 @@ export class ColorBulb extends deviceBase {
577
574
  await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
578
575
  const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
579
576
  await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
580
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
577
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
581
578
  try {
582
579
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
583
580
  this.device.bleMac = formattedDeviceId
584
581
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
585
- if (switchbot !== false) {
586
- switchbot
582
+ if (switchBotBLE !== false) {
583
+ switchBotBLE
587
584
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
588
585
  .then(async (device_list: any) => {
589
586
  await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
@@ -599,7 +596,7 @@ export class ColorBulb extends deviceBase {
599
596
  await this.BLEPushConnection()
600
597
  })
601
598
  } else {
602
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
599
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
603
600
  await this.BLEPushConnection()
604
601
  }
605
602
  } catch (error) {
@@ -614,21 +611,20 @@ export class ColorBulb extends deviceBase {
614
611
  await this.debugLog('openAPIpushChanges')
615
612
  if (this.LightBulb.On !== this.accessory.context.On) {
616
613
  const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
617
- const bodyChange = JSON.stringify({
614
+ const bodyChange: bodyChange = {
618
615
  command: `${command}`,
619
616
  parameter: 'default',
620
617
  commandType: 'command',
621
- })
618
+ }
622
619
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
623
620
  try {
624
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
625
- const deviceStatus: any = await body.json()
626
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
627
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
628
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
621
+ const { body } = await this.pushChangeRequest(bodyChange)
622
+ const deviceStatus: any = await body
623
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
624
+ if (await this.successfulStatusCodes(deviceStatus)) {
625
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
629
626
  await this.updateHomeKitCharacteristics()
630
627
  } else {
631
- await this.statusCode(statusCode)
632
628
  await this.statusCode(deviceStatus.statusCode)
633
629
  }
634
630
  } catch (e: any) {
@@ -646,21 +642,20 @@ export class ColorBulb extends deviceBase {
646
642
  await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
647
643
  const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
648
644
  await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
649
- const bodyChange = JSON.stringify({
645
+ const bodyChange: bodyChange = {
650
646
  command: 'setColor',
651
647
  parameter: `${red}:${green}:${blue}`,
652
648
  commandType: 'command',
653
- })
649
+ }
654
650
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
655
651
  try {
656
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
657
- const deviceStatus: any = await body.json()
658
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
659
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
660
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
652
+ const { body } = await this.pushChangeRequest(bodyChange)
653
+ const deviceStatus: any = await body
654
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
655
+ if (await this.successfulStatusCodes(deviceStatus)) {
656
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
661
657
  await this.updateHomeKitCharacteristics()
662
658
  } else {
663
- await this.statusCode(statusCode)
664
659
  await this.statusCode(deviceStatus.statusCode)
665
660
  }
666
661
  } catch (e: any) {
@@ -677,21 +672,20 @@ export class ColorBulb extends deviceBase {
677
672
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
678
673
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
679
674
  this.accessory.context.kelvin = kelvin
680
- const bodyChange = JSON.stringify({
675
+ const bodyChange: bodyChange = {
681
676
  command: 'setColorTemperature',
682
677
  parameter: `${kelvin}`,
683
678
  commandType: 'command',
684
- })
679
+ }
685
680
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
686
681
  try {
687
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
688
- const deviceStatus: any = await body.json()
689
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
690
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
691
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
682
+ const { body } = await this.pushChangeRequest(bodyChange)
683
+ const deviceStatus: any = await body
684
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
685
+ if (await this.successfulStatusCodes(deviceStatus)) {
686
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
692
687
  await this.updateHomeKitCharacteristics()
693
688
  } else {
694
- await this.statusCode(statusCode)
695
689
  await this.statusCode(deviceStatus.statusCode)
696
690
  }
697
691
  } catch (e: any) {
@@ -706,21 +700,20 @@ export class ColorBulb extends deviceBase {
706
700
  async pushBrightnessChanges(): Promise<void> {
707
701
  await this.debugLog('pushBrightnessChanges')
708
702
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
709
- const bodyChange = JSON.stringify({
703
+ const bodyChange: bodyChange = {
710
704
  command: 'setBrightness',
711
705
  parameter: `${this.LightBulb.Brightness}`,
712
706
  commandType: 'command',
713
- })
707
+ }
714
708
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
715
709
  try {
716
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
717
- const deviceStatus: any = await body.json()
718
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
719
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
720
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
710
+ const { body } = await this.pushChangeRequest(bodyChange)
711
+ const deviceStatus: any = await body
712
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
713
+ if (await this.successfulStatusCodes(deviceStatus)) {
714
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
721
715
  await this.updateHomeKitCharacteristics()
722
716
  } else {
723
- await this.statusCode(statusCode)
724
717
  await this.statusCode(deviceStatus.statusCode)
725
718
  }
726
719
  } catch (e: any) {
@@ -3,13 +3,10 @@
3
3
  * contact.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { contactSensorServiceData, contactSensorStatus, contactSensorWebhookContext, device } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { contactSensorServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { contactSensorStatus } from '../types/devicestatus.js'
12
- import type { contactSensorWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -161,7 +158,7 @@ export class Contact extends deviceBase {
161
158
  this.debugLog('Retrieve initial values and update Homekit')
162
159
  this.refreshStatus()
163
160
  } catch (e: any) {
164
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
161
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
165
162
  }
166
163
 
167
164
  // regisiter webhook event handler if enabled
@@ -169,7 +166,7 @@ export class Contact extends deviceBase {
169
166
  this.debugLog('Registering Webhook Event Handler')
170
167
  this.registerWebhook()
171
168
  } catch (e: any) {
172
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
169
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
173
170
  }
174
171
 
175
172
  // regisiter platform BLE event handler if enabled
@@ -177,7 +174,7 @@ export class Contact extends deviceBase {
177
174
  this.debugLog('Registering Platform BLE Event Handler')
178
175
  this.registerPlatformBLE()
179
176
  } catch (e: any) {
180
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
177
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
181
178
  }
182
179
 
183
180
  // Start an update interval
@@ -298,22 +295,22 @@ export class Contact extends deviceBase {
298
295
 
299
296
  async BLERefreshStatus(): Promise<void> {
300
297
  await this.debugLog('BLERefreshStatus')
301
- const switchbot = await this.switchbotBLE()
302
- if (switchbot === undefined) {
303
- await this.BLERefreshConnection(switchbot)
298
+ const switchBotBLE = await this.switchbotBLE()
299
+ if (switchBotBLE === undefined) {
300
+ await this.BLERefreshConnection(switchBotBLE)
304
301
  } else {
305
302
  // Start to monitor advertisement packets
306
303
  (async () => {
307
304
  // Start to monitor advertisement packets
308
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData
305
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as contactSensorServiceData
309
306
  // Update HomeKit
310
307
  if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
311
308
  this.serviceData = serviceData
312
309
  await this.BLEparseStatus()
313
310
  await this.updateHomeKitCharacteristics()
314
311
  } else {
315
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
316
- await this.BLERefreshConnection(switchbot)
312
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
313
+ await this.BLERefreshConnection(switchBotBLE)
317
314
  }
318
315
  })()
319
316
  }
@@ -334,7 +331,7 @@ export class Contact extends deviceBase {
334
331
  await this.BLEparseStatus()
335
332
  await this.updateHomeKitCharacteristics()
336
333
  } catch (e: any) {
337
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
334
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
338
335
  }
339
336
  }
340
337
  } catch (error) {
@@ -348,17 +345,17 @@ export class Contact extends deviceBase {
348
345
  async openAPIRefreshStatus(): Promise<void> {
349
346
  await this.debugLog('openAPIRefreshStatus')
350
347
  try {
351
- const { body, statusCode } = await this.deviceRefreshStatus()
352
- const deviceStatus: any = await body.json()
353
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
354
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
355
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
348
+ const { body } = await this.deviceRefreshStatus()
349
+ const deviceStatus: any = await body
350
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
351
+ if (await this.successfulStatusCodes(deviceStatus)) {
352
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
356
353
  this.deviceStatus = deviceStatus.body
357
354
  await this.openAPIparseStatus()
358
355
  await this.updateHomeKitCharacteristics()
359
356
  } else {
360
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
361
- await this.debugWarnLog(statusCode, deviceStatus)
357
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
358
+ await this.debugWarnLog(deviceStatus)
362
359
  }
363
360
  } catch (e: any) {
364
361
  await this.apiError(e)
@@ -376,7 +373,7 @@ export class Contact extends deviceBase {
376
373
  await this.parseStatusWebhook()
377
374
  await this.updateHomeKitCharacteristics()
378
375
  } catch (e: any) {
379
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
376
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
380
377
  }
381
378
  }
382
379
  } else {
@@ -3,13 +3,10 @@
3
3
  * curtain.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import type { CharacteristicChange, CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { bodyChange, curtain3ServiceData, curtain3WebhookContext, curtainServiceData, curtainStatus, curtainWebhookContext, device } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
9
  import type { devicesConfig } from '../settings.js'
9
- import type { curtain3ServiceData, curtainServiceData } from '../types/bledevicestatus.js'
10
- import type { device } from '../types/devicelist.js'
11
- import type { curtainStatus } from '../types/devicestatus.js'
12
- import type { curtain3WebhookContext, curtainWebhookContext } from '../types/devicewebhookstatus.js'
13
10
 
14
11
  import { hostname } from 'node:os'
15
12
 
@@ -244,7 +241,7 @@ export class Curtain extends deviceBase {
244
241
  this.debugLog('Retrieve initial values and update Homekit')
245
242
  this.refreshStatus()
246
243
  } catch (e: any) {
247
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
244
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
248
245
  }
249
246
 
250
247
  // regisiter webhook event handler if enabled
@@ -252,7 +249,7 @@ export class Curtain extends deviceBase {
252
249
  this.debugLog('Registering Webhook Event Handler')
253
250
  this.registerWebhook()
254
251
  } catch (e: any) {
255
- this.errorLog(`failed to registerWebhook, Error: ${e}`)
252
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
256
253
  }
257
254
 
258
255
  // regisiter platform BLE event handler if enabled
@@ -260,7 +257,7 @@ export class Curtain extends deviceBase {
260
257
  this.debugLog('Registering Platform BLE Event Handler')
261
258
  this.registerPlatformBLE()
262
259
  } catch (e: any) {
263
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
260
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
264
261
  }
265
262
 
266
263
  // History
@@ -480,14 +477,14 @@ export class Curtain extends deviceBase {
480
477
 
481
478
  async BLERefreshStatus(): Promise<void> {
482
479
  await this.debugLog('BLERefreshStatus')
483
- const switchbot = await this.switchbotBLE()
484
- if (switchbot === undefined) {
485
- await this.BLERefreshConnection(switchbot)
480
+ const switchBotBLE = await this.switchbotBLE()
481
+ if (switchBotBLE === undefined) {
482
+ await this.BLERefreshConnection(switchBotBLE)
486
483
  } else {
487
484
  // Start to monitor advertisement packets
488
485
  (async () => {
489
486
  // Start to monitor advertisement packets
490
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData
487
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as curtainServiceData | curtain3ServiceData
491
488
  // Update HomeKit
492
489
  if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
493
490
  && (serviceData.modelName === SwitchBotBLEModelName.Curtain || SwitchBotBLEModelName.Curtain3)) {
@@ -495,8 +492,8 @@ export class Curtain extends deviceBase {
495
492
  await this.BLEparseStatus()
496
493
  await this.updateHomeKitCharacteristics()
497
494
  } else {
498
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
499
- await this.BLERefreshConnection(switchbot)
495
+ await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
496
+ await this.BLERefreshConnection(switchBotBLE)
500
497
  }
501
498
  })()
502
499
  }
@@ -505,17 +502,17 @@ export class Curtain extends deviceBase {
505
502
  async openAPIRefreshStatus(): Promise<void> {
506
503
  await this.debugLog('openAPIRefreshStatus')
507
504
  try {
508
- const { body, statusCode } = await this.deviceRefreshStatus()
509
- const deviceStatus: any = await body.json()
510
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
511
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
512
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
505
+ const { body } = await this.deviceRefreshStatus()
506
+ const deviceStatus: any = await body
507
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
508
+ if (await this.successfulStatusCodes(deviceStatus)) {
509
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
513
510
  this.deviceStatus = deviceStatus.body
514
511
  await this.openAPIparseStatus()
515
512
  await this.updateHomeKitCharacteristics()
516
513
  } else {
517
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
518
- await this.debugWarnLog(statusCode, deviceStatus)
514
+ await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
515
+ await this.debugWarnLog(deviceStatus)
519
516
  }
520
517
  } catch (e: any) {
521
518
  await this.apiError(e)
@@ -533,7 +530,7 @@ export class Curtain extends deviceBase {
533
530
  await this.parseStatusWebhook()
534
531
  await this.updateHomeKitCharacteristics()
535
532
  } catch (e: any) {
536
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
533
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
537
534
  }
538
535
  }
539
536
  } else {
@@ -556,7 +553,7 @@ export class Curtain extends deviceBase {
556
553
  await this.BLEparseStatus()
557
554
  await this.updateHomeKitCharacteristics()
558
555
  } catch (e: any) {
559
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
556
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
560
557
  }
561
558
  }
562
559
  } catch (error) {
@@ -593,7 +590,7 @@ export class Curtain extends deviceBase {
593
590
  async BLEpushChanges(): Promise<void> {
594
591
  await this.debugLog('BLEpushChanges')
595
592
  if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
596
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
593
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
597
594
  try {
598
595
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
599
596
  this.device.bleMac = formattedDeviceId
@@ -601,8 +598,8 @@ export class Curtain extends deviceBase {
601
598
  const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
602
599
  const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF
603
600
  await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
604
- if (switchbot !== false) {
605
- switchbot
601
+ if (switchBotBLE !== false) {
602
+ switchBotBLE
606
603
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
607
604
  .then(async (device_list: any) => {
608
605
  return await this.retryBLE({
@@ -622,7 +619,7 @@ export class Curtain extends deviceBase {
622
619
  await this.BLEPushConnection()
623
620
  })
624
621
  } else {
625
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
622
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
626
623
  await this.BLEPushConnection()
627
624
  }
628
625
  } catch (error) {
@@ -641,30 +638,29 @@ export class Curtain extends deviceBase {
641
638
  const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
642
639
  await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
643
640
  const adjustedMode = setPositionMode || 'ff'
644
- let bodyChange: string
641
+ let bodyChange: bodyChange
645
642
  if (this.WindowCovering.HoldPosition) {
646
- bodyChange = JSON.stringify({
643
+ bodyChange = {
647
644
  command: 'pause',
648
645
  parameter: 'default',
649
646
  commandType: 'command',
650
- })
647
+ }
651
648
  } else {
652
- bodyChange = JSON.stringify({
649
+ bodyChange = {
653
650
  command: 'setPosition',
654
651
  parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
655
652
  commandType: 'command',
656
- })
653
+ }
657
654
  }
658
655
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
659
656
  try {
660
- const { body, statusCode } = await this.pushChangeRequest(bodyChange)
661
- const deviceStatus: any = await body.json()
662
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
663
- if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
664
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
657
+ const { body } = await this.pushChangeRequest(bodyChange)
658
+ const deviceStatus: any = await body
659
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
660
+ if (await this.successfulStatusCodes(deviceStatus)) {
661
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
665
662
  await this.updateHomeKitCharacteristics()
666
663
  } else {
667
- await this.statusCode(statusCode)
668
664
  await this.statusCode(deviceStatus.statusCode)
669
665
  }
670
666
  } catch (e: any) {