@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.4

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 (100) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/device/blindtilt.js +103 -103
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.js +84 -84
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/ceilinglight.js +97 -97
  7. package/dist/device/ceilinglight.js.map +1 -1
  8. package/dist/device/colorbulb.js +139 -139
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.js +47 -47
  11. package/dist/device/contact.js.map +1 -1
  12. package/dist/device/curtain.d.ts +1 -1
  13. package/dist/device/curtain.d.ts.map +1 -1
  14. package/dist/device/curtain.js +91 -89
  15. package/dist/device/curtain.js.map +1 -1
  16. package/dist/device/device.d.ts +12 -12
  17. package/dist/device/device.d.ts.map +1 -1
  18. package/dist/device/device.js +42 -42
  19. package/dist/device/device.js.map +1 -1
  20. package/dist/device/fan.js +95 -95
  21. package/dist/device/fan.js.map +1 -1
  22. package/dist/device/hub.js +46 -46
  23. package/dist/device/hub.js.map +1 -1
  24. package/dist/device/humidifier.js +84 -84
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/iosensor.js +44 -44
  27. package/dist/device/iosensor.js.map +1 -1
  28. package/dist/device/lightstrip.js +118 -118
  29. package/dist/device/lightstrip.js.map +1 -1
  30. package/dist/device/lock.js +74 -74
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.js +44 -44
  33. package/dist/device/meter.js.map +1 -1
  34. package/dist/device/meterplus.js +42 -42
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/meterpro.js +42 -42
  37. package/dist/device/meterpro.js.map +1 -1
  38. package/dist/device/motion.js +44 -44
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts.map +1 -1
  41. package/dist/device/plug.js +59 -59
  42. package/dist/device/plug.js.map +1 -1
  43. package/dist/device/robotvacuumcleaner.js +73 -73
  44. package/dist/device/robotvacuumcleaner.js.map +1 -1
  45. package/dist/device/waterdetector.js +44 -44
  46. package/dist/device/waterdetector.js.map +1 -1
  47. package/dist/irdevice/airconditioner.js +31 -31
  48. package/dist/irdevice/airconditioner.js.map +1 -1
  49. package/dist/irdevice/airpurifier.js +10 -10
  50. package/dist/irdevice/airpurifier.js.map +1 -1
  51. package/dist/irdevice/camera.js +9 -9
  52. package/dist/irdevice/camera.js.map +1 -1
  53. package/dist/irdevice/fan.js +11 -11
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/irdevice.js +11 -11
  56. package/dist/irdevice/irdevice.js.map +1 -1
  57. package/dist/irdevice/light.js +9 -9
  58. package/dist/irdevice/light.js.map +1 -1
  59. package/dist/irdevice/other.js +55 -55
  60. package/dist/irdevice/other.js.map +1 -1
  61. package/dist/irdevice/tv.js +33 -33
  62. package/dist/irdevice/tv.js.map +1 -1
  63. package/dist/irdevice/vacuumcleaner.js +9 -9
  64. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  65. package/dist/irdevice/waterheater.js +9 -9
  66. package/dist/irdevice/waterheater.js.map +1 -1
  67. package/dist/platform.js +228 -228
  68. package/dist/platform.js.map +1 -1
  69. package/package.json +9 -9
  70. package/src/device/blindtilt.ts +103 -103
  71. package/src/device/bot.ts +84 -84
  72. package/src/device/ceilinglight.ts +97 -97
  73. package/src/device/colorbulb.ts +139 -139
  74. package/src/device/contact.ts +47 -47
  75. package/src/device/curtain.ts +91 -89
  76. package/src/device/device.ts +42 -42
  77. package/src/device/fan.ts +95 -95
  78. package/src/device/hub.ts +46 -46
  79. package/src/device/humidifier.ts +84 -84
  80. package/src/device/iosensor.ts +44 -44
  81. package/src/device/lightstrip.ts +118 -118
  82. package/src/device/lock.ts +74 -74
  83. package/src/device/meter.ts +44 -44
  84. package/src/device/meterplus.ts +42 -42
  85. package/src/device/meterpro.ts +42 -42
  86. package/src/device/motion.ts +44 -44
  87. package/src/device/plug.ts +61 -61
  88. package/src/device/robotvacuumcleaner.ts +73 -73
  89. package/src/device/waterdetector.ts +44 -44
  90. package/src/irdevice/airconditioner.ts +31 -31
  91. package/src/irdevice/airpurifier.ts +10 -10
  92. package/src/irdevice/camera.ts +9 -9
  93. package/src/irdevice/fan.ts +11 -11
  94. package/src/irdevice/irdevice.ts +11 -11
  95. package/src/irdevice/light.ts +9 -9
  96. package/src/irdevice/other.ts +55 -55
  97. package/src/irdevice/tv.ts +33 -33
  98. package/src/irdevice/vacuumcleaner.ts +9 -9
  99. package/src/irdevice/waterheater.ts +9 -9
  100. package/src/platform.ts +228 -228
@@ -186,65 +186,65 @@ export class Contact extends deviceBase {
186
186
  }
187
187
 
188
188
  async BLEparseStatus(): Promise<void> {
189
- await this.debugLog('BLEparseStatus')
189
+ this.debugLog('BLEparseStatus')
190
190
  // ContactSensorState
191
191
  this.ContactSensor.ContactSensorState = this.getContactSensorState(this.serviceData.doorState)
192
- await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
192
+ this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
193
193
 
194
194
  // MotionDetected
195
195
  if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
196
196
  this.MotionSensor.MotionDetected = this.serviceData.movement
197
- await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
197
+ this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
198
198
  }
199
199
  // CurrentAmbientLightLevel
200
200
  if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
201
201
  const set_minLux = (this.device as contactConfig).set_minLux ?? 1
202
202
  const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
203
203
  const lightLevel = this.serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux
204
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
205
- await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
204
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
205
+ this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
206
206
  }
207
207
  // BatteryLevel
208
208
  this.Battery.BatteryLevel = this.serviceData.battery
209
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
209
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
210
210
  // StatusLowBattery
211
211
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
212
212
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
213
213
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
214
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
214
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
215
215
  }
216
216
 
217
217
  async openAPIparseStatus(): Promise<void> {
218
- await this.debugLog('openAPIparseStatus')
218
+ this.debugLog('openAPIparseStatus')
219
219
  // Contact State
220
220
  this.ContactSensor.ContactSensorState = this.getContactSensorState(this.deviceStatus.openState)
221
- await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
221
+ this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
222
222
 
223
223
  // MotionDetected
224
224
  if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
225
225
  this.MotionSensor.MotionDetected = this.deviceStatus.moveDetected
226
- await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
226
+ this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
227
227
  }
228
228
  // Light Level
229
229
  if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
230
230
  const set_minLux = (this.device as contactConfig).set_minLux ?? 1
231
231
  const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
232
232
  const lightLevel = this.deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux
233
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
234
- await this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
233
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
234
+ this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
235
235
  }
236
236
  // BatteryLevel
237
237
  this.Battery.BatteryLevel = this.deviceStatus.battery
238
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
238
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
239
239
  // StatusLowBattery
240
240
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
241
241
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
242
242
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
243
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
243
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
244
244
  // FirmwareVersion
245
245
  if (this.deviceStatus.version) {
246
246
  const version = this.deviceStatus.version.toString()
247
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
247
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
248
248
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
249
249
  this.accessory
250
250
  .getService(this.hap.Service.AccessoryInformation)!
@@ -253,27 +253,27 @@ export class Contact extends deviceBase {
253
253
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
254
254
  .updateValue(deviceVersion)
255
255
  this.accessory.context.version = deviceVersion
256
- await this.debugLog(`version: ${this.accessory.context.version}`)
256
+ this.debugLog(`version: ${this.accessory.context.version}`)
257
257
  }
258
258
  }
259
259
 
260
260
  async parseStatusWebhook(): Promise<void> {
261
- await this.debugLog('parseStatusWebhook')
262
- await this.debugLog(`(detectionState, brightness, openState) = Webhook:(${this.webhookContext.detectionState}, ${this.webhookContext.brightness}, ${this.webhookContext.openState}), current:(${this.MotionSensor?.MotionDetected}, ${this.LightSensor?.CurrentAmbientLightLevel}, ${this.ContactSensor.ContactSensorState})`)
261
+ this.debugLog('parseStatusWebhook')
262
+ this.debugLog(`(detectionState, brightness, openState) = Webhook:(${this.webhookContext.detectionState}, ${this.webhookContext.brightness}, ${this.webhookContext.openState}), current:(${this.MotionSensor?.MotionDetected}, ${this.LightSensor?.CurrentAmbientLightLevel}, ${this.ContactSensor.ContactSensorState})`)
263
263
  // ContactSensorState
264
264
  this.ContactSensor.ContactSensorState = this.getContactSensorState(this.webhookContext.openState)
265
- await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
265
+ this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
266
266
  if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
267
267
  // MotionDetected
268
268
  this.MotionSensor.MotionDetected = this.webhookContext.detectionState === 'DETECTED'
269
- await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
269
+ this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
270
270
  }
271
271
  if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
272
272
  const set_minLux = (this.device as contactConfig).set_minLux ?? 1
273
273
  const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
274
274
  const lightLevel = this.webhookContext.brightness === 'bright' ? set_maxLux : set_minLux
275
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
276
- await this.debugLog(`LightLevel: ${this.webhookContext.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
275
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
276
+ this.debugLog(`LightLevel: ${this.webhookContext.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
277
277
  }
278
278
  }
279
279
 
@@ -282,19 +282,19 @@ export class Contact extends deviceBase {
282
282
  */
283
283
  async refreshStatus(): Promise<void> {
284
284
  if (!this.device.enableCloudService && this.OpenAPI) {
285
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
285
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
286
286
  } else if (this.BLE) {
287
287
  await this.BLERefreshStatus()
288
288
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
289
289
  await this.openAPIRefreshStatus()
290
290
  } else {
291
291
  await this.offlineOff()
292
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
292
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
293
293
  }
294
294
  }
295
295
 
296
296
  async BLERefreshStatus(): Promise<void> {
297
- await this.debugLog('BLERefreshStatus')
297
+ this.debugLog('BLERefreshStatus')
298
298
  const switchBotBLE = await this.switchbotBLE()
299
299
  if (switchBotBLE === undefined) {
300
300
  await this.BLERefreshConnection(switchBotBLE)
@@ -309,7 +309,7 @@ export class Contact extends deviceBase {
309
309
  await this.BLEparseStatus()
310
310
  await this.updateHomeKitCharacteristics()
311
311
  } else {
312
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
312
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
313
313
  await this.BLERefreshConnection(switchBotBLE)
314
314
  }
315
315
  })()
@@ -317,67 +317,67 @@ export class Contact extends deviceBase {
317
317
  }
318
318
 
319
319
  async registerPlatformBLE(): Promise<void> {
320
- await this.debugLog('registerPlatformBLE')
320
+ this.debugLog('registerPlatformBLE')
321
321
  if (this.config.options?.BLE) {
322
- await this.debugLog('is listening to Platform BLE.')
322
+ this.debugLog('is listening to Platform BLE.')
323
323
  try {
324
324
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
325
325
  this.device.bleMac = formattedDeviceId
326
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
326
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
327
327
  this.platform.bleEventHandler[this.device.bleMac] = async (context: contactSensorServiceData) => {
328
328
  try {
329
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
329
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
330
330
  this.serviceData = context
331
331
  await this.BLEparseStatus()
332
332
  await this.updateHomeKitCharacteristics()
333
333
  } catch (e: any) {
334
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
334
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
335
335
  }
336
336
  }
337
337
  } catch (error) {
338
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
338
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
339
339
  }
340
340
  } else {
341
- await this.debugLog('is not listening to Platform BLE')
341
+ this.debugLog('is not listening to Platform BLE')
342
342
  }
343
343
  }
344
344
 
345
345
  async openAPIRefreshStatus(): Promise<void> {
346
- await this.debugLog('openAPIRefreshStatus')
346
+ this.debugLog('openAPIRefreshStatus')
347
347
  try {
348
- const { body } = await this.deviceRefreshStatus()
349
- const deviceStatus: any = await body
350
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
348
+ const response = await this.deviceRefreshStatus()
349
+ const deviceStatus: any = response.body
350
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
351
351
  if (await this.successfulStatusCodes(deviceStatus)) {
352
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
352
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
353
353
  this.deviceStatus = deviceStatus.body
354
354
  await this.openAPIparseStatus()
355
355
  await this.updateHomeKitCharacteristics()
356
356
  } else {
357
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
358
- await this.debugWarnLog(deviceStatus)
357
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
358
+ this.debugWarnLog(deviceStatus)
359
359
  }
360
360
  } catch (e: any) {
361
361
  await this.apiError(e)
362
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
362
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
363
363
  }
364
364
  }
365
365
 
366
366
  async registerWebhook() {
367
367
  if (this.device.webhook) {
368
- await this.debugLog('is listening webhook.')
368
+ this.debugLog('is listening webhook.')
369
369
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: contactSensorWebhookContext) => {
370
370
  try {
371
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
371
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
372
372
  this.webhookContext = context
373
373
  await this.parseStatusWebhook()
374
374
  await this.updateHomeKitCharacteristics()
375
375
  } catch (e: any) {
376
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
376
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
377
377
  }
378
378
  }
379
379
  } else {
380
- await this.debugLog('is not listening webhook.')
380
+ this.debugLog('is not listening webhook.')
381
381
  }
382
382
  }
383
383
 
@@ -402,9 +402,9 @@ export class Contact extends deviceBase {
402
402
  }
403
403
 
404
404
  async BLERefreshConnection(switchbot: any): Promise<void> {
405
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
405
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
406
406
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
407
- await this.warnLog('Using OpenAPI Connection to Refresh Status')
407
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
408
408
  await this.openAPIRefreshStatus()
409
409
  }
410
410
  }