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

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 (96) hide show
  1. package/dist/device/blindtilt.js +102 -102
  2. package/dist/device/blindtilt.js.map +1 -1
  3. package/dist/device/bot.js +85 -85
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/ceilinglight.js +98 -98
  6. package/dist/device/ceilinglight.js.map +1 -1
  7. package/dist/device/colorbulb.js +140 -140
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/contact.js +44 -44
  10. package/dist/device/contact.js.map +1 -1
  11. package/dist/device/curtain.js +82 -82
  12. package/dist/device/curtain.js.map +1 -1
  13. package/dist/device/device.d.ts +11 -11
  14. package/dist/device/device.d.ts.map +1 -1
  15. package/dist/device/device.js +41 -41
  16. package/dist/device/device.js.map +1 -1
  17. package/dist/device/fan.js +96 -96
  18. package/dist/device/fan.js.map +1 -1
  19. package/dist/device/hub.js +43 -43
  20. package/dist/device/hub.js.map +1 -1
  21. package/dist/device/humidifier.js +84 -84
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/iosensor.js +44 -44
  24. package/dist/device/iosensor.js.map +1 -1
  25. package/dist/device/lightstrip.js +119 -119
  26. package/dist/device/lightstrip.js.map +1 -1
  27. package/dist/device/lock.js +75 -75
  28. package/dist/device/lock.js.map +1 -1
  29. package/dist/device/meter.js +44 -44
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/meterplus.js +42 -42
  32. package/dist/device/meterplus.js.map +1 -1
  33. package/dist/device/meterpro.js +42 -42
  34. package/dist/device/meterpro.js.map +1 -1
  35. package/dist/device/motion.js +42 -42
  36. package/dist/device/motion.js.map +1 -1
  37. package/dist/device/plug.js +60 -60
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/device/robotvacuumcleaner.js +74 -74
  40. package/dist/device/robotvacuumcleaner.js.map +1 -1
  41. package/dist/device/waterdetector.js +44 -44
  42. package/dist/device/waterdetector.js.map +1 -1
  43. package/dist/irdevice/airconditioner.js +31 -31
  44. package/dist/irdevice/airconditioner.js.map +1 -1
  45. package/dist/irdevice/airpurifier.js +10 -10
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.js +9 -9
  48. package/dist/irdevice/camera.js.map +1 -1
  49. package/dist/irdevice/fan.js +11 -11
  50. package/dist/irdevice/fan.js.map +1 -1
  51. package/dist/irdevice/irdevice.js +11 -11
  52. package/dist/irdevice/irdevice.js.map +1 -1
  53. package/dist/irdevice/light.js +9 -9
  54. package/dist/irdevice/light.js.map +1 -1
  55. package/dist/irdevice/other.js +55 -55
  56. package/dist/irdevice/other.js.map +1 -1
  57. package/dist/irdevice/tv.js +33 -33
  58. package/dist/irdevice/tv.js.map +1 -1
  59. package/dist/irdevice/vacuumcleaner.js +9 -9
  60. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  61. package/dist/irdevice/waterheater.js +9 -9
  62. package/dist/irdevice/waterheater.js.map +1 -1
  63. package/dist/platform.js +228 -228
  64. package/dist/platform.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/device/blindtilt.ts +102 -102
  67. package/src/device/bot.ts +85 -85
  68. package/src/device/ceilinglight.ts +98 -98
  69. package/src/device/colorbulb.ts +140 -140
  70. package/src/device/contact.ts +44 -44
  71. package/src/device/curtain.ts +82 -82
  72. package/src/device/device.ts +41 -41
  73. package/src/device/fan.ts +96 -96
  74. package/src/device/hub.ts +43 -43
  75. package/src/device/humidifier.ts +84 -84
  76. package/src/device/iosensor.ts +44 -44
  77. package/src/device/lightstrip.ts +119 -119
  78. package/src/device/lock.ts +75 -75
  79. package/src/device/meter.ts +44 -44
  80. package/src/device/meterplus.ts +42 -42
  81. package/src/device/meterpro.ts +42 -42
  82. package/src/device/motion.ts +42 -42
  83. package/src/device/plug.ts +60 -60
  84. package/src/device/robotvacuumcleaner.ts +74 -74
  85. package/src/device/waterdetector.ts +44 -44
  86. package/src/irdevice/airconditioner.ts +31 -31
  87. package/src/irdevice/airpurifier.ts +10 -10
  88. package/src/irdevice/camera.ts +9 -9
  89. package/src/irdevice/fan.ts +11 -11
  90. package/src/irdevice/irdevice.ts +11 -11
  91. package/src/irdevice/light.ts +9 -9
  92. package/src/irdevice/other.ts +55 -55
  93. package/src/irdevice/tv.ts +33 -33
  94. package/src/irdevice/vacuumcleaner.ts +9 -9
  95. package/src/irdevice/waterheater.ts +9 -9
  96. package/src/platform.ts +228 -228
@@ -195,85 +195,85 @@ export class Lock extends deviceBase {
195
195
  await this.pushChanges()
196
196
  } catch (e: any) {
197
197
  await this.apiError(e)
198
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
198
+ this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
199
199
  }
200
200
  this.lockUpdateInProgress = false
201
201
  })
202
202
  }
203
203
 
204
204
  async BLEparseStatus(): Promise<void> {
205
- await this.debugLog('BLEparseStatus')
206
- await this.debugLog(`(lockState) = BLE:(${this.serviceData.status}), current:(${this.LockMechanism.LockCurrentState})`)
205
+ this.debugLog('BLEparseStatus')
206
+ this.debugLog(`(lockState) = BLE:(${this.serviceData.status}), current:(${this.LockMechanism.LockCurrentState})`)
207
207
 
208
208
  // LockCurrentState
209
209
  this.LockMechanism.LockCurrentState = this.serviceData.status === 'locked'
210
210
  ? this.hap.Characteristic.LockCurrentState.SECURED
211
211
  : this.hap.Characteristic.LockCurrentState.UNSECURED
212
- await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
212
+ this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
213
213
 
214
214
  // LockTargetState
215
215
  this.LockMechanism.LockTargetState = this.serviceData.status === 'locked'
216
216
  ? this.hap.Characteristic.LockTargetState.SECURED
217
217
  : this.hap.Characteristic.LockTargetState.UNSECURED
218
- await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
218
+ this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
219
219
 
220
220
  // Contact Sensor
221
221
  if (!(this.device as lockConfig).hide_contactsensor && this.ContactSensor?.Service) {
222
222
  this.ContactSensor.ContactSensorState = this.serviceData.door_open
223
223
  ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
224
224
  : this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
225
- await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
225
+ this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
226
226
  }
227
227
 
228
228
  // BatteryLevel
229
229
  this.Battery.BatteryLevel = this.serviceData.battery
230
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
230
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
231
231
 
232
232
  // StatusLowBattery
233
233
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
234
234
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
235
235
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
236
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
236
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
237
237
  }
238
238
 
239
239
  async openAPIparseStatus(): Promise<void> {
240
- await this.debugLog('openAPIparseStatus')
241
- await this.debugLog(`(lockState) = OpenAPI:(${this.deviceStatus.lockState}), current:(${this.LockMechanism.LockCurrentState})`)
240
+ this.debugLog('openAPIparseStatus')
241
+ this.debugLog(`(lockState) = OpenAPI:(${this.deviceStatus.lockState}), current:(${this.LockMechanism.LockCurrentState})`)
242
242
 
243
243
  // LockCurrentState
244
244
  this.LockMechanism.LockCurrentState = this.deviceStatus.lockState === 'locked'
245
245
  ? this.hap.Characteristic.LockCurrentState.SECURED
246
246
  : this.hap.Characteristic.LockCurrentState.UNSECURED
247
- await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
247
+ this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
248
248
 
249
249
  // LockTargetState
250
250
  this.LockMechanism.LockTargetState = this.deviceStatus.lockState === 'locked'
251
251
  ? this.hap.Characteristic.LockTargetState.SECURED
252
252
  : this.hap.Characteristic.LockTargetState.UNSECURED
253
- await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
253
+ this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
254
254
 
255
255
  // ContactSensorState
256
256
  if (!(this.device as lockConfig).hide_contactsensor && this.ContactSensor?.Service) {
257
257
  this.ContactSensor.ContactSensorState = this.deviceStatus.doorState === 'opened'
258
258
  ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
259
259
  : this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
260
- await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
260
+ this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
261
261
  }
262
262
 
263
263
  // BatteryLevel
264
264
  this.Battery.BatteryLevel = this.deviceStatus.battery
265
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
265
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
266
266
 
267
267
  // StatusLowBattery
268
268
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
269
269
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
270
270
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
271
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
271
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
272
272
 
273
273
  // Firmware Version
274
274
  if (this.deviceStatus.version) {
275
275
  const version = this.deviceStatus.version.toString()
276
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
276
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
277
277
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
278
278
  this.accessory
279
279
  .getService(this.hap.Service.AccessoryInformation)!
@@ -282,25 +282,25 @@ export class Lock extends deviceBase {
282
282
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
283
283
  .updateValue(deviceVersion)
284
284
  this.accessory.context.version = deviceVersion
285
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
285
+ this.debugSuccessLog(`version: ${this.accessory.context.version}`)
286
286
  }
287
287
  }
288
288
 
289
289
  async parseStatusWebhook(): Promise<void> {
290
- await this.debugLog('parseStatusWebhook')
291
- await this.debugLog(`(lockState) = Webhook:(${this.webhookContext.lockState}), current:(${this.LockMechanism.LockCurrentState})`)
290
+ this.debugLog('parseStatusWebhook')
291
+ this.debugLog(`(lockState) = Webhook:(${this.webhookContext.lockState}), current:(${this.LockMechanism.LockCurrentState})`)
292
292
 
293
293
  // LockCurrentState
294
294
  this.LockMechanism.LockCurrentState = this.webhookContext.lockState === 'LOCKED'
295
295
  ? this.hap.Characteristic.LockCurrentState.SECURED
296
296
  : this.hap.Characteristic.LockCurrentState.UNSECURED
297
- await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
297
+ this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
298
298
 
299
299
  // LockTargetState
300
300
  this.LockMechanism.LockTargetState = this.webhookContext.lockState === 'LOCKED'
301
301
  ? this.hap.Characteristic.LockTargetState.SECURED
302
302
  : this.hap.Characteristic.LockTargetState.UNSECURED
303
- await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
303
+ this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`)
304
304
  }
305
305
 
306
306
  /**
@@ -308,19 +308,19 @@ export class Lock extends deviceBase {
308
308
  */
309
309
  async refreshStatus(): Promise<void> {
310
310
  if (!this.device.enableCloudService && this.OpenAPI) {
311
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
311
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
312
312
  } else if (this.BLE) {
313
313
  await this.BLERefreshStatus()
314
314
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
315
315
  await this.openAPIRefreshStatus()
316
316
  } else {
317
317
  await this.offlineOff()
318
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
318
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
319
319
  }
320
320
  }
321
321
 
322
322
  async BLERefreshStatus(): Promise<void> {
323
- await this.debugLog('BLERefreshStatus')
323
+ this.debugLog('BLERefreshStatus')
324
324
  const switchBotBLE = await this.switchbotBLE()
325
325
  if (switchBotBLE === undefined) {
326
326
  await this.BLERefreshConnection(switchBotBLE)
@@ -336,7 +336,7 @@ export class Lock extends deviceBase {
336
336
  await this.BLEparseStatus()
337
337
  await this.updateHomeKitCharacteristics()
338
338
  } else {
339
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
339
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
340
340
  await this.BLERefreshConnection(switchBotBLE)
341
341
  }
342
342
  })()
@@ -344,67 +344,67 @@ export class Lock extends deviceBase {
344
344
  }
345
345
 
346
346
  async registerPlatformBLE(): Promise<void> {
347
- await this.debugLog('registerPlatformBLE')
347
+ this.debugLog('registerPlatformBLE')
348
348
  if (this.config.options?.BLE) {
349
- await this.debugLog('is listening to Platform BLE.')
349
+ this.debugLog('is listening to Platform BLE.')
350
350
  try {
351
351
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
352
352
  this.device.bleMac = formattedDeviceId
353
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
353
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
354
354
  this.platform.bleEventHandler[this.device.bleMac] = async (context: lockServiceData | lockProServiceData) => {
355
355
  try {
356
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
356
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
357
357
  this.serviceData = context
358
358
  await this.BLEparseStatus()
359
359
  await this.updateHomeKitCharacteristics()
360
360
  } catch (e: any) {
361
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
361
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
362
362
  }
363
363
  }
364
364
  } catch (error) {
365
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
365
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
366
366
  }
367
367
  } else {
368
- await this.debugLog('is not listening to Platform BLE')
368
+ this.debugLog('is not listening to Platform BLE')
369
369
  }
370
370
  }
371
371
 
372
372
  async openAPIRefreshStatus(): Promise<void> {
373
- await this.debugLog('openAPIRefreshStatus')
373
+ this.debugLog('openAPIRefreshStatus')
374
374
  try {
375
- const { body } = await this.deviceRefreshStatus()
376
- const deviceStatus: any = await body
377
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
375
+ const response = await this.deviceRefreshStatus()
376
+ const deviceStatus: any = response.body
377
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
378
378
  if (await this.successfulStatusCodes(deviceStatus)) {
379
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
379
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
380
380
  this.deviceStatus = deviceStatus.body
381
381
  await this.openAPIparseStatus()
382
382
  await this.updateHomeKitCharacteristics()
383
383
  } else {
384
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
385
- await this.debugWarnLog(deviceStatus)
384
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
385
+ this.debugWarnLog(deviceStatus)
386
386
  }
387
387
  } catch (e: any) {
388
388
  await this.apiError(e)
389
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
389
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
390
390
  }
391
391
  }
392
392
 
393
393
  async registerWebhook() {
394
394
  if (this.device.webhook) {
395
- await this.debugLog('is listening webhook.')
395
+ this.debugLog('is listening webhook.')
396
396
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: lockWebhookContext | lockProWebhookContext) => {
397
397
  try {
398
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
398
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
399
399
  this.webhookContext = context
400
400
  await this.parseStatusWebhook()
401
401
  await this.updateHomeKitCharacteristics()
402
402
  } catch (e: any) {
403
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
403
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
404
404
  }
405
405
  }
406
406
  } else {
407
- await this.debugLog('is not listening webhook.')
407
+ this.debugLog('is not listening webhook.')
408
408
  }
409
409
  }
410
410
 
@@ -416,14 +416,14 @@ export class Lock extends deviceBase {
416
416
  */
417
417
  async pushChanges(): Promise<void> {
418
418
  if (!this.device.enableCloudService && this.OpenAPI) {
419
- await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
419
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
420
420
  } else if (this.BLE) {
421
421
  await this.BLEpushChanges()
422
422
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
423
423
  await this.openAPIpushChanges()
424
424
  } else {
425
425
  await this.offlineOff()
426
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
426
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
427
427
  }
428
428
  // Refresh the status from the API
429
429
  interval(15000)
@@ -435,19 +435,19 @@ export class Lock extends deviceBase {
435
435
  }
436
436
 
437
437
  async BLEpushChanges(): Promise<void> {
438
- await this.debugLog('BLEpushChanges')
438
+ this.debugLog('BLEpushChanges')
439
439
  if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
440
440
  const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
441
441
  try {
442
442
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
443
443
  this.device.bleMac = formattedDeviceId
444
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
444
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
445
445
  if (switchBotBLE !== false) {
446
446
  switchBotBLE
447
447
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
448
448
  .then(async (device_list: SwitchbotDevice[]) => {
449
449
  return await this.retryBLE({
450
- max: await this.maxRetryBLE(),
450
+ max: this.maxRetryBLE(),
451
451
  fn: async () => {
452
452
  if (this.LockMechanism.LockTargetState === this.hap.Characteristic.LockTargetState.SECURED) {
453
453
  return await device_list[0].lock({ id: this.device.bleMac })
@@ -458,28 +458,28 @@ export class Lock extends deviceBase {
458
458
  })
459
459
  })
460
460
  .then(async () => {
461
- await this.successLog(`LockTargetState: ${this.LockMechanism.LockTargetState} sent over SwitchBot BLE, sent successfully`)
461
+ this.successLog(`LockTargetState: ${this.LockMechanism.LockTargetState} sent over SwitchBot BLE, sent successfully`)
462
462
  await this.updateHomeKitCharacteristics()
463
463
  })
464
464
  .catch(async (e: any) => {
465
465
  await this.apiError(e)
466
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
466
+ this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
467
467
  await this.BLEPushConnection()
468
468
  })
469
469
  } else {
470
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
470
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
471
471
  await this.BLEPushConnection()
472
472
  }
473
473
  } catch (error) {
474
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
474
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
475
475
  }
476
476
  } else {
477
- await this.debugLog(`No changes (BLEpushChanges), LockTargetState: ${this.LockMechanism.LockTargetState}, LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
477
+ this.debugLog(`No changes (BLEpushChanges), LockTargetState: ${this.LockMechanism.LockTargetState}, LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
478
478
  }
479
479
  }
480
480
 
481
481
  async openAPIpushChanges(LatchUnlock?: boolean): Promise<void> {
482
- await this.debugLog('openAPIpushChanges')
482
+ this.debugLog('openAPIpushChanges')
483
483
  if ((this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) || LatchUnlock) {
484
484
  // Determine the command based on the LockTargetState or the forceUnlock parameter
485
485
  const command = LatchUnlock ? 'unlock' : this.LockMechanism.LockTargetState ? 'lock' : 'unlock'
@@ -488,23 +488,23 @@ export class Lock extends deviceBase {
488
488
  parameter: 'default',
489
489
  commandType: 'command',
490
490
  }
491
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
491
+ this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
492
492
  try {
493
- const { body } = await this.pushChangeRequest(bodyChange)
494
- const deviceStatus: any = await body
495
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
493
+ const response = await this.pushChangeRequest(bodyChange)
494
+ const deviceStatus: any = response.body
495
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
496
496
  if (await this.successfulStatusCodes(deviceStatus)) {
497
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
497
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
498
498
  await this.updateHomeKitCharacteristics()
499
499
  } else {
500
500
  await this.statusCode(deviceStatus.statusCode)
501
501
  }
502
502
  } catch (e: any) {
503
503
  await this.apiError(e)
504
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
504
+ this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
505
505
  }
506
506
  } else {
507
- await this.debugLog(`No changes (openAPIpushChanges), LockCurrentState: ${this.LockMechanism.LockCurrentState}, TargetPosition: ${this.LockMechanism.LockTargetState}`)
507
+ this.debugLog(`No changes (openAPIpushChanges), LockCurrentState: ${this.LockMechanism.LockCurrentState}, TargetPosition: ${this.LockMechanism.LockTargetState}`)
508
508
  }
509
509
  }
510
510
 
@@ -513,9 +513,9 @@ export class Lock extends deviceBase {
513
513
  */
514
514
  async LockTargetStateSet(value: CharacteristicValue): Promise<void> {
515
515
  if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
516
- await this.infoLog(`Set LockTargetState: ${value}`)
516
+ this.infoLog(`Set LockTargetState: ${value}`)
517
517
  } else {
518
- await this.debugLog(`No Changes, LockTargetState: ${value}`)
518
+ this.debugLog(`No Changes, LockTargetState: ${value}`)
519
519
  }
520
520
 
521
521
  this.LockMechanism.LockTargetState = value
@@ -526,13 +526,13 @@ export class Lock extends deviceBase {
526
526
  * Handle requests to set the value of the "On" characteristic
527
527
  */
528
528
  async OnSet(value: CharacteristicValue): Promise<void> {
529
- await this.debugLog(`Latch Button Set On: ${value}`)
529
+ this.debugLog(`Latch Button Set On: ${value}`)
530
530
  if (value) {
531
- await this.debugLog('Attempting to open the latch')
531
+ this.debugLog('Attempting to open the latch')
532
532
 
533
533
  this.openAPIpushChanges(value as boolean).then(async () => {
534
- await this.debugLog('Latch opened successfully')
535
- await this.debugLog(`SwitchService is: ${this.Switch?.Service ? 'available' : 'not available'}`)
534
+ this.debugLog('Latch opened successfully')
535
+ this.debugLog(`SwitchService is: ${this.Switch?.Service ? 'available' : 'not available'}`)
536
536
 
537
537
  // simulate button press to turn the switch back off
538
538
  if (this.Switch?.Service) {
@@ -540,20 +540,20 @@ export class Lock extends deviceBase {
540
540
  // Simulate a button press by waiting a short period before turning the switch off
541
541
  setTimeout(async () => {
542
542
  SwitchService.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
543
- await this.debugLog('Latch button switched off automatically.')
543
+ this.debugLog('Latch button switched off automatically.')
544
544
  }, 500) // 500 ms delay
545
545
  }
546
546
  }).catch(async (e: any) => {
547
547
  // Log the error if the operation failed
548
- await this.debugLog(`Error opening latch: ${e.message ?? e}`)
548
+ this.debugLog(`Error opening latch: ${e.message ?? e}`)
549
549
  // Ensure we turn the switch back off even in case of an error
550
550
  if (this.Switch?.Service) {
551
551
  this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
552
- await this.debugLog('Latch button switched off after an error.')
552
+ this.debugLog('Latch button switched off after an error.')
553
553
  }
554
554
  })
555
555
  } else {
556
- await this.debugLog('Switch is off, nothing to do')
556
+ this.debugLog('Switch is off, nothing to do')
557
557
  }
558
558
 
559
559
  this.Switch!.On = value
@@ -577,15 +577,15 @@ export class Lock extends deviceBase {
577
577
 
578
578
  async BLEPushConnection() {
579
579
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
580
- await this.warnLog('Using OpenAPI Connection to Push Changes')
580
+ this.warnLog('Using OpenAPI Connection to Push Changes')
581
581
  await this.openAPIpushChanges()
582
582
  }
583
583
  }
584
584
 
585
585
  async BLERefreshConnection(switchbot: any): Promise<void> {
586
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
586
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
587
587
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
588
- await this.warnLog('Using OpenAPI Connection to Refresh Status')
588
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
589
589
  await this.openAPIRefreshStatus()
590
590
  }
591
591
  }