@switchbot/homebridge-switchbot 3.8.3 → 4.0.0-beta.1

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 (205) hide show
  1. package/.github/npm-version-script.cjs +81 -0
  2. package/.github/workflows/beta-release.yml +12 -4
  3. package/CHANGELOG.md +15 -1
  4. package/config.schema.json +583 -937
  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 +68 -66
  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 +63 -59
  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 +56 -65
  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 +73 -80
  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 +38 -38
  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 +60 -60
  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 +86 -20
  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 +50 -51
  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 +48 -48
  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 +53 -55
  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 +35 -35
  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 +57 -65
  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 +38 -39
  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 +35 -35
  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 +35 -35
  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 +27 -27
  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 +32 -32
  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 +39 -40
  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 +28 -28
  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 +31 -32
  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 +22 -23
  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 +28 -14
  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 +12 -13
  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 +12 -15
  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 +9 -22
  122. package/dist/platform.d.ts.map +1 -1
  123. package/dist/platform.js +154 -260
  124. package/dist/platform.js.map +1 -1
  125. package/dist/settings.d.ts +64 -82
  126. package/dist/settings.d.ts.map +1 -1
  127. package/dist/settings.js +0 -20
  128. package/dist/settings.js.map +1 -1
  129. package/dist/utils.d.ts +1 -102
  130. package/dist/utils.d.ts.map +1 -1
  131. package/dist/utils.js +0 -105
  132. package/dist/utils.js.map +1 -1
  133. package/docs/assets/highlight.css +42 -0
  134. package/docs/assets/main.js +1 -1
  135. package/docs/functions/default.html +1 -1
  136. package/docs/index.html +61 -50
  137. package/docs/media/security-privacy-bluetooth.png +0 -0
  138. package/package.json +5 -7
  139. package/src/device/blindtilt.ts +74 -74
  140. package/src/device/bot.ts +68 -67
  141. package/src/device/ceilinglight.ts +59 -70
  142. package/src/device/colorbulb.ts +79 -88
  143. package/src/device/contact.ts +40 -43
  144. package/src/device/curtain.ts +66 -68
  145. package/src/device/device.ts +86 -40
  146. package/src/device/fan.ts +52 -56
  147. package/src/device/hub.ts +50 -53
  148. package/src/device/humidifier.ts +56 -61
  149. package/src/device/iosensor.ts +37 -40
  150. package/src/device/lightstrip.ts +62 -72
  151. package/src/device/lock.ts +41 -45
  152. package/src/device/meter.ts +37 -40
  153. package/src/device/meterplus.ts +37 -40
  154. package/src/device/motion.ts +29 -32
  155. package/src/device/plug.ts +34 -37
  156. package/src/device/robotvacuumcleaner.ts +41 -49
  157. package/src/device/waterdetector.ts +30 -33
  158. package/src/irdevice/airconditioner.ts +33 -35
  159. package/src/irdevice/airpurifier.ts +12 -13
  160. package/src/irdevice/camera.ts +10 -11
  161. package/src/irdevice/fan.ts +24 -25
  162. package/src/irdevice/irdevice.ts +31 -27
  163. package/src/irdevice/light.ts +14 -15
  164. package/src/irdevice/other.ts +14 -17
  165. package/src/irdevice/tv.ts +28 -29
  166. package/src/irdevice/vacuumcleaner.ts +10 -11
  167. package/src/irdevice/waterheater.ts +10 -11
  168. package/src/platform.ts +178 -287
  169. package/src/settings.ts +67 -88
  170. package/src/utils.ts +2 -106
  171. package/dist/types/bledevicestatus.d.ts +0 -281
  172. package/dist/types/bledevicestatus.d.ts.map +0 -1
  173. package/dist/types/bledevicestatus.js +0 -2
  174. package/dist/types/bledevicestatus.js.map +0 -1
  175. package/dist/types/devicelist.d.ts +0 -89
  176. package/dist/types/devicelist.d.ts.map +0 -1
  177. package/dist/types/devicelist.js +0 -6
  178. package/dist/types/devicelist.js.map +0 -1
  179. package/dist/types/deviceresponse.d.ts +0 -13
  180. package/dist/types/deviceresponse.d.ts.map +0 -1
  181. package/dist/types/deviceresponse.js +0 -2
  182. package/dist/types/deviceresponse.js.map +0 -1
  183. package/dist/types/devicestatus.d.ts +0 -149
  184. package/dist/types/devicestatus.d.ts.map +0 -1
  185. package/dist/types/devicestatus.js +0 -3
  186. package/dist/types/devicestatus.js.map +0 -1
  187. package/dist/types/devicewebhookstatus.d.ts +0 -156
  188. package/dist/types/devicewebhookstatus.d.ts.map +0 -1
  189. package/dist/types/devicewebhookstatus.js +0 -2
  190. package/dist/types/devicewebhookstatus.js.map +0 -1
  191. package/dist/types/irdevicelist.d.ts +0 -10
  192. package/dist/types/irdevicelist.d.ts.map +0 -1
  193. package/dist/types/irdevicelist.js +0 -2
  194. package/dist/types/irdevicelist.js.map +0 -1
  195. package/dist/types/pushbody.d.ts +0 -6
  196. package/dist/types/pushbody.d.ts.map +0 -1
  197. package/dist/types/pushbody.js +0 -2
  198. package/dist/types/pushbody.js.map +0 -1
  199. package/src/types/bledevicestatus.ts +0 -303
  200. package/src/types/devicelist.ts +0 -124
  201. package/src/types/deviceresponse.ts +0 -14
  202. package/src/types/devicestatus.ts +0 -178
  203. package/src/types/devicewebhookstatus.ts +0 -191
  204. package/src/types/irdevicelist.ts +0 -15
  205. 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, SwitchbotDevice, WoBulb } from 'node-switchbot'
6
7
 
7
8
  import type { SwitchBotPlatform } from '../platform.js'
8
- 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'
9
+ import type { colorBulbConfig, devicesConfig } from '../settings.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -110,7 +107,7 @@ export class ColorBulb extends deviceBase {
110
107
  }).onSet(this.OnSet.bind(this))
111
108
 
112
109
  this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Brightness).setProps({
113
- minStep: device.colorbulb?.set_minStep ?? 1,
110
+ minStep: (device as colorBulbConfig)?.set_minStep ?? 1,
114
111
  minValue: 0,
115
112
  maxValue: 100,
116
113
  validValueRanges: [0, 100],
@@ -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,23 +452,23 @@ 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
- .then(async (device_list: any) => {
463
+ .then(async (device_list: WoBulb[]) => {
467
464
  await this.infoLog(`On: ${this.LightBulb.On}`)
468
465
  return await this.retryBLE({
469
466
  max: await this.maxRetryBLE(),
470
467
  fn: async () => {
471
468
  if (this.LightBulb.On) {
472
- return await device_list[0].turnOn({ id: this.device.bleMac })
469
+ return await device_list[0].turnOn()
473
470
  } else {
474
- return await device_list[0].turnOff({ id: this.device.bleMac })
471
+ return await device_list[0].turnOff()
475
472
  }
476
473
  },
477
474
  })
@@ -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,17 +497,18 @@ 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
- .then(async (device_list: any) => {
508
+ .then(async (device_list: SwitchbotDevice[]) => {
509
+ const deviceList = device_list as unknown as WoBulb[]
512
510
  await this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`)
513
- return await device_list[0].setBrightness(this.LightBulb.Brightness)
511
+ return await deviceList[0].setBrightness(Number(this.LightBulb.Brightness))
514
512
  })
515
513
  .then(async () => {
516
514
  await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
@@ -522,7 +520,7 @@ export class ColorBulb extends deviceBase {
522
520
  await this.BLEPushConnection()
523
521
  })
524
522
  } else {
525
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
523
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
526
524
  await this.BLEPushConnection()
527
525
  }
528
526
  } catch (error) {
@@ -538,17 +536,18 @@ export class ColorBulb extends deviceBase {
538
536
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
539
537
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
540
538
  this.accessory.context.kelvin = kelvin
541
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
539
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
542
540
  try {
543
541
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
544
542
  this.device.bleMac = formattedDeviceId
545
543
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
546
- if (switchbot !== false) {
547
- switchbot
544
+ if (switchBotBLE !== false) {
545
+ switchBotBLE
548
546
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
549
- .then(async (device_list: any) => {
547
+ .then(async (device_list: SwitchbotDevice[]) => {
548
+ const deviceList = device_list as unknown as WoBulb[]
550
549
  await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
551
- return await device_list[0].setColorTemperature(kelvin)
550
+ return await deviceList[0].setColorTemperature(kelvin)
552
551
  })
553
552
  .then(async () => {
554
553
  await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`)
@@ -560,7 +559,7 @@ export class ColorBulb extends deviceBase {
560
559
  await this.BLEPushConnection()
561
560
  })
562
561
  } else {
563
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
562
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
564
563
  await this.BLEPushConnection()
565
564
  }
566
565
  } catch (error) {
@@ -577,17 +576,18 @@ export class ColorBulb extends deviceBase {
577
576
  await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
578
577
  const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
579
578
  await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
580
- const switchbot = await this.platform.connectBLE(this.accessory, this.device)
579
+ const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
581
580
  try {
582
581
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
583
582
  this.device.bleMac = formattedDeviceId
584
583
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
585
- if (switchbot !== false) {
586
- switchbot
584
+ if (switchBotBLE !== false) {
585
+ switchBotBLE
587
586
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
588
- .then(async (device_list: any) => {
587
+ .then(async (device_list: SwitchbotDevice[]) => {
588
+ const deviceList = device_list as unknown as WoBulb[]
589
589
  await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
590
- return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
590
+ return await deviceList[0].setRGB(Number(this.LightBulb.Brightness), red, green, blue)
591
591
  })
592
592
  .then(async () => {
593
593
  await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
@@ -599,7 +599,7 @@ export class ColorBulb extends deviceBase {
599
599
  await this.BLEPushConnection()
600
600
  })
601
601
  } else {
602
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
602
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
603
603
  await this.BLEPushConnection()
604
604
  }
605
605
  } catch (error) {
@@ -614,21 +614,20 @@ export class ColorBulb extends deviceBase {
614
614
  await this.debugLog('openAPIpushChanges')
615
615
  if (this.LightBulb.On !== this.accessory.context.On) {
616
616
  const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
617
- const bodyChange = JSON.stringify({
617
+ const bodyChange: bodyChange = {
618
618
  command: `${command}`,
619
619
  parameter: 'default',
620
620
  commandType: 'command',
621
- })
621
+ }
622
622
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
623
623
  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)}`)
624
+ const { body } = await this.pushChangeRequest(bodyChange)
625
+ const deviceStatus: any = await body
626
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
627
+ if (await this.successfulStatusCodes(deviceStatus)) {
628
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
629
629
  await this.updateHomeKitCharacteristics()
630
630
  } else {
631
- await this.statusCode(statusCode)
632
631
  await this.statusCode(deviceStatus.statusCode)
633
632
  }
634
633
  } catch (e: any) {
@@ -646,21 +645,20 @@ export class ColorBulb extends deviceBase {
646
645
  await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
647
646
  const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
648
647
  await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
649
- const bodyChange = JSON.stringify({
648
+ const bodyChange: bodyChange = {
650
649
  command: 'setColor',
651
650
  parameter: `${red}:${green}:${blue}`,
652
651
  commandType: 'command',
653
- })
652
+ }
654
653
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
655
654
  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)}`)
655
+ const { body } = await this.pushChangeRequest(bodyChange)
656
+ const deviceStatus: any = await body
657
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
658
+ if (await this.successfulStatusCodes(deviceStatus)) {
659
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
661
660
  await this.updateHomeKitCharacteristics()
662
661
  } else {
663
- await this.statusCode(statusCode)
664
662
  await this.statusCode(deviceStatus.statusCode)
665
663
  }
666
664
  } catch (e: any) {
@@ -677,21 +675,20 @@ export class ColorBulb extends deviceBase {
677
675
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
678
676
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
679
677
  this.accessory.context.kelvin = kelvin
680
- const bodyChange = JSON.stringify({
678
+ const bodyChange: bodyChange = {
681
679
  command: 'setColorTemperature',
682
680
  parameter: `${kelvin}`,
683
681
  commandType: 'command',
684
- })
682
+ }
685
683
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
686
684
  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)}`)
685
+ const { body } = await this.pushChangeRequest(bodyChange)
686
+ const deviceStatus: any = await body
687
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
688
+ if (await this.successfulStatusCodes(deviceStatus)) {
689
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
692
690
  await this.updateHomeKitCharacteristics()
693
691
  } else {
694
- await this.statusCode(statusCode)
695
692
  await this.statusCode(deviceStatus.statusCode)
696
693
  }
697
694
  } catch (e: any) {
@@ -706,21 +703,20 @@ export class ColorBulb extends deviceBase {
706
703
  async pushBrightnessChanges(): Promise<void> {
707
704
  await this.debugLog('pushBrightnessChanges')
708
705
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
709
- const bodyChange = JSON.stringify({
706
+ const bodyChange: bodyChange = {
710
707
  command: 'setBrightness',
711
708
  parameter: `${this.LightBulb.Brightness}`,
712
709
  commandType: 'command',
713
- })
710
+ }
714
711
  await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
715
712
  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)}`)
713
+ const { body } = await this.pushChangeRequest(bodyChange)
714
+ const deviceStatus: any = await body
715
+ await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
716
+ if (await this.successfulStatusCodes(deviceStatus)) {
717
+ await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
721
718
  await this.updateHomeKitCharacteristics()
722
719
  } else {
723
- await this.statusCode(statusCode)
724
720
  await this.statusCode(deviceStatus.statusCode)
725
721
  }
726
722
  } catch (e: any) {
@@ -857,13 +853,8 @@ export class ColorBulb extends deviceBase {
857
853
  this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
858
854
  await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
859
855
  // Adaptive Lighting Shift
860
- if (device.colorbulb?.adaptiveLightingShift) {
861
- this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift
862
- this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
863
- } else {
864
- this.adaptiveLightingShift = 0
865
- this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
866
- }
856
+ this.adaptiveLightingShift = (device as colorBulbConfig).adaptiveLightingShift ?? 0
857
+ this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
867
858
  }
868
859
 
869
860
  async BLEPushConnection() {
@@ -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
- 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'
9
+ import type { contactConfig, devicesConfig } from '../settings.js'
13
10
 
14
11
  /*
15
12
  * For Testing Locally:
@@ -113,7 +110,7 @@ export class Contact extends deviceBase {
113
110
  })
114
111
 
115
112
  // Initialize Motion Sensor Service
116
- if (this.device.contact?.hide_motionsensor) {
113
+ if ((this.device as contactConfig).hide_motionsensor) {
117
114
  if (this.MotionSensor) {
118
115
  this.debugLog('Removing Motion Sensor Service')
119
116
  this.MotionSensor.Service = accessory.getService(this.hap.Service.MotionSensor) as Service
@@ -135,7 +132,7 @@ export class Contact extends deviceBase {
135
132
  }
136
133
 
137
134
  // Initialize Light Sensor Service
138
- if (device.contact?.hide_lightsensor) {
135
+ if ((device as contactConfig).hide_lightsensor) {
139
136
  if (this.LightSensor) {
140
137
  this.debugLog('Removing Light Sensor Service')
141
138
  this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor) as Service
@@ -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
@@ -195,14 +192,14 @@ export class Contact extends deviceBase {
195
192
  await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
196
193
 
197
194
  // MotionDetected
198
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
195
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
199
196
  this.MotionSensor.MotionDetected = this.serviceData.movement
200
197
  await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
201
198
  }
202
199
  // CurrentAmbientLightLevel
203
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
204
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1
205
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
200
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
201
+ const set_minLux = (this.device as contactConfig).set_minLux ?? 1
202
+ const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
206
203
  const lightLevel = this.serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux
207
204
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
208
205
  await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
@@ -224,14 +221,14 @@ export class Contact extends deviceBase {
224
221
  await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
225
222
 
226
223
  // MotionDetected
227
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
224
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
228
225
  this.MotionSensor.MotionDetected = this.deviceStatus.moveDetected
229
226
  await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
230
227
  }
231
228
  // Light Level
232
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
233
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1
234
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
229
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
230
+ const set_minLux = (this.device as contactConfig).set_minLux ?? 1
231
+ const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
235
232
  const lightLevel = this.deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux
236
233
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
237
234
  await this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
@@ -266,14 +263,14 @@ export class Contact extends deviceBase {
266
263
  // ContactSensorState
267
264
  this.ContactSensor.ContactSensorState = this.getContactSensorState(this.webhookContext.openState)
268
265
  await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
269
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
266
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
270
267
  // MotionDetected
271
268
  this.MotionSensor.MotionDetected = this.webhookContext.detectionState === 'DETECTED'
272
269
  await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
273
270
  }
274
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
275
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1
276
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
271
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
272
+ const set_minLux = (this.device as contactConfig).set_minLux ?? 1
273
+ const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
277
274
  const lightLevel = this.webhookContext.brightness === 'bright' ? set_maxLux : set_minLux
278
275
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
279
276
  await this.debugLog(`LightLevel: ${this.webhookContext.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
@@ -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 {
@@ -391,11 +388,11 @@ export class Contact extends deviceBase {
391
388
  // ContactSensorState
392
389
  await this.updateCharacteristic(this.ContactSensor.Service, this.hap.Characteristic.ContactSensorState, this.ContactSensor.ContactSensorState, 'ContactSensorState')
393
390
  // MotionDetected
394
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
391
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
395
392
  await this.updateCharacteristic(this.MotionSensor.Service, this.hap.Characteristic.MotionDetected, this.MotionSensor.MotionDetected, 'MotionDetected')
396
393
  }
397
394
  // CurrentAmbientLightLevel
398
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
395
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
399
396
  await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel')
400
397
  }
401
398
  // BatteryLevel
@@ -415,10 +412,10 @@ export class Contact extends deviceBase {
415
412
  async offlineOff(): Promise<void> {
416
413
  if (this.device.offline) {
417
414
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED)
418
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
415
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
419
416
  this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, false)
420
417
  }
421
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
418
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
422
419
  this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, 100)
423
420
  }
424
421
  }
@@ -427,11 +424,11 @@ export class Contact extends deviceBase {
427
424
  async apiError(e: any): Promise<void> {
428
425
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e)
429
426
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
430
- if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
427
+ if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
431
428
  this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e)
432
429
  this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
433
430
  }
434
- if (!this.device.contact?.hide_lightsensor && this.LightSensor?.Service) {
431
+ if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
435
432
  this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
436
433
  this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
437
434
  }