@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
@@ -156,59 +156,59 @@ export class RobotVacuumCleaner extends deviceBase {
156
156
  await this.pushChanges()
157
157
  } catch (e: any) {
158
158
  await this.apiError(e)
159
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
159
+ this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
160
160
  }
161
161
  this.robotVacuumCleanerUpdateInProgress = false
162
162
  })
163
163
  }
164
164
 
165
165
  async BLEparseStatus(): Promise<void> {
166
- await this.debugLog('BLEparseStatus')
167
- await this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`)
166
+ this.debugLog('BLEparseStatus')
167
+ this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`)
168
168
 
169
169
  // On
170
170
  this.LightBulb.On = !!['InDustCollecting', 'Clearing'].includes(this.deviceStatus.workingStatus)
171
- await this.debugLog(`On: ${this.LightBulb.On}`)
171
+ this.debugLog(`On: ${this.LightBulb.On}`)
172
172
 
173
173
  // BatteryLevel
174
174
  this.Battery.BatteryLevel = this.serviceData.battery
175
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
175
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
176
176
 
177
177
  // StatusLowBattery
178
178
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
179
179
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
180
180
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
181
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
181
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
182
182
  }
183
183
 
184
184
  async openAPIparseStatus() {
185
- await this.debugLog('openAPIparseStatus')
186
- await this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery}, ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
185
+ this.debugLog('openAPIparseStatus')
186
+ this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery}, ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
187
187
 
188
188
  // On
189
189
  this.LightBulb.On = this.deviceStatus.onlineStatus === 'online'
190
- await this.debugLog(`On: ${this.LightBulb.On}`)
190
+ this.debugLog(`On: ${this.LightBulb.On}`)
191
191
 
192
192
  // BatteryLevel
193
193
  this.Battery.BatteryLevel = this.deviceStatus.battery
194
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
194
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
195
195
 
196
196
  // StatusLowBattery
197
197
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
198
198
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
199
199
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
200
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
200
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
201
201
 
202
202
  // ChargingState
203
203
  this.Battery.ChargingState = this.deviceStatus.workingStatus === 'Charging'
204
204
  ? this.hap.Characteristic.ChargingState.CHARGING
205
205
  : this.hap.Characteristic.ChargingState.NOT_CHARGING
206
- await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
206
+ this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
207
207
 
208
208
  // Firmware Version
209
209
  if (this.deviceStatus.version) {
210
210
  const version = this.deviceStatus.version.toString()
211
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
211
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
212
212
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
213
213
  this.accessory
214
214
  .getService(this.hap.Service.AccessoryInformation)!
@@ -217,33 +217,33 @@ export class RobotVacuumCleaner extends deviceBase {
217
217
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
218
218
  .updateValue(deviceVersion)
219
219
  this.accessory.context.version = deviceVersion
220
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
220
+ this.debugSuccessLog(`version: ${this.accessory.context.version}`)
221
221
  }
222
222
  }
223
223
 
224
224
  async parseStatusWebhook(): Promise<void> {
225
- await this.debugLog('parseStatusWebhook')
226
- await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery}, ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
225
+ this.debugLog('parseStatusWebhook')
226
+ this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery}, ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
227
227
 
228
228
  // On
229
229
  this.LightBulb.On = this.webhookContext.onlineStatus === 'online'
230
- await this.debugLog(`On: ${this.LightBulb.On}`)
230
+ this.debugLog(`On: ${this.LightBulb.On}`)
231
231
 
232
232
  // BatteryLevel
233
233
  this.Battery.BatteryLevel = this.webhookContext.battery
234
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
234
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
235
235
 
236
236
  // StatusLowBattery
237
237
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
238
238
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
239
239
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
240
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
240
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
241
241
 
242
242
  // ChargingState
243
243
  this.Battery.ChargingState = this.webhookContext.workingStatus === 'Charging'
244
244
  ? this.hap.Characteristic.ChargingState.CHARGING
245
245
  : this.hap.Characteristic.ChargingState.NOT_CHARGING
246
- await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
246
+ this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
247
247
  }
248
248
 
249
249
  /**
@@ -251,19 +251,19 @@ export class RobotVacuumCleaner extends deviceBase {
251
251
  */
252
252
  async refreshStatus(): Promise<void> {
253
253
  if (!this.device.enableCloudService && this.OpenAPI) {
254
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
254
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
255
255
  } else if (this.BLE) {
256
256
  await this.BLERefreshStatus()
257
257
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
258
258
  await this.openAPIRefreshStatus()
259
259
  } else {
260
260
  await this.offlineOff()
261
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
261
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
262
262
  }
263
263
  }
264
264
 
265
265
  async BLERefreshStatus(): Promise<void> {
266
- await this.debugLog('BLERefreshStatus')
266
+ this.debugLog('BLERefreshStatus')
267
267
  const switchBotBLE = await this.switchbotBLE()
268
268
  if (switchBotBLE === undefined) {
269
269
  await this.BLERefreshConnection(switchBotBLE)
@@ -278,7 +278,7 @@ export class RobotVacuumCleaner extends deviceBase {
278
278
  await this.BLEparseStatus()
279
279
  await this.updateHomeKitCharacteristics()
280
280
  } else {
281
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
281
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
282
282
  await this.BLERefreshConnection(switchBotBLE)
283
283
  }
284
284
  })()
@@ -286,67 +286,67 @@ export class RobotVacuumCleaner extends deviceBase {
286
286
  }
287
287
 
288
288
  async registerPlatformBLE(): Promise<void> {
289
- await this.debugLog('registerPlatformBLE')
289
+ this.debugLog('registerPlatformBLE')
290
290
  if (this.config.options?.BLE) {
291
- await this.debugLog('is listening to Platform BLE.')
291
+ this.debugLog('is listening to Platform BLE.')
292
292
  try {
293
293
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
294
294
  this.device.bleMac = formattedDeviceId
295
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
295
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
296
296
  this.platform.bleEventHandler[this.device.bleMac] = async (context: robotVacuumCleanerServiceData) => {
297
297
  try {
298
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
298
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
299
299
  this.serviceData = context
300
300
  await this.BLEparseStatus()
301
301
  await this.updateHomeKitCharacteristics()
302
302
  } catch (e: any) {
303
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
303
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
304
304
  }
305
305
  }
306
306
  } catch (error) {
307
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
307
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
308
308
  }
309
309
  } else {
310
- await this.debugLog('is not listening to Platform BLE')
310
+ this.debugLog('is not listening to Platform BLE')
311
311
  }
312
312
  }
313
313
 
314
314
  async openAPIRefreshStatus(): Promise<void> {
315
- await this.debugLog('openAPIRefreshStatus')
315
+ this.debugLog('openAPIRefreshStatus')
316
316
  try {
317
- const { body } = await this.deviceRefreshStatus()
318
- const deviceStatus: any = await body
319
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
317
+ const response = await this.deviceRefreshStatus()
318
+ const deviceStatus: any = response.body
319
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
320
320
  if (await this.successfulStatusCodes(deviceStatus)) {
321
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
321
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
322
322
  this.deviceStatus = deviceStatus.body
323
323
  await this.openAPIparseStatus()
324
324
  await this.updateHomeKitCharacteristics()
325
325
  } else {
326
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
327
- await this.debugWarnLog(deviceStatus)
326
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
327
+ this.debugWarnLog(deviceStatus)
328
328
  }
329
329
  } catch (e: any) {
330
330
  await this.apiError(e)
331
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
331
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
332
332
  }
333
333
  }
334
334
 
335
335
  async registerWebhook() {
336
336
  if (this.device.webhook) {
337
- await this.debugLog('is listening webhook.')
337
+ this.debugLog('is listening webhook.')
338
338
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
339
339
  try {
340
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
340
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
341
341
  this.webhookContext = context
342
342
  await this.parseStatusWebhook()
343
343
  await this.updateHomeKitCharacteristics()
344
344
  } catch (e: any) {
345
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
345
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
346
346
  }
347
347
  }
348
348
  } else {
349
- await this.debugLog('is not listening webhook.')
349
+ this.debugLog('is not listening webhook.')
350
350
  }
351
351
  }
352
352
 
@@ -360,14 +360,14 @@ export class RobotVacuumCleaner extends deviceBase {
360
360
  */
361
361
  async pushChanges(): Promise<void> {
362
362
  if (!this.device.enableCloudService && this.OpenAPI) {
363
- await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
363
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
364
364
  } else if (this.BLE) {
365
365
  await this.BLEpushChanges()
366
366
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
367
367
  await this.openAPIpushChanges()
368
368
  } else {
369
369
  await this.offlineOff()
370
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
370
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
371
371
  }
372
372
  // Refresh the status from the API
373
373
  interval(15000)
@@ -379,21 +379,21 @@ export class RobotVacuumCleaner extends deviceBase {
379
379
  }
380
380
 
381
381
  async BLEpushChanges(): Promise<void> {
382
- await this.debugLog('BLEpushChanges')
382
+ this.debugLog('BLEpushChanges')
383
383
  if (this.LightBulb.On !== this.accessory.context.On) {
384
384
  const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
385
385
  try {
386
386
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
387
387
  this.device.bleMac = formattedDeviceId
388
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
388
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
389
389
  if (switchBotBLE !== false) {
390
390
  switchBotBLE
391
391
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
392
392
  .then(async (device_list: SwitchbotDevice[]) => {
393
393
  const deviceList = device_list as unknown as SwitchbotDevice[]
394
- await this.infoLog(`On: ${this.LightBulb.On}`)
394
+ this.infoLog(`On: ${this.LightBulb.On}`)
395
395
  return await this.retryBLE({
396
- max: await this.maxRetryBLE(),
396
+ max: this.maxRetryBLE(),
397
397
  fn: async () => {
398
398
  if (this.LightBulb.On) {
399
399
  return await deviceList[0].turnOn()
@@ -404,28 +404,28 @@ export class RobotVacuumCleaner extends deviceBase {
404
404
  })
405
405
  })
406
406
  .then(async () => {
407
- await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
407
+ this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
408
408
  await this.updateHomeKitCharacteristics()
409
409
  })
410
410
  .catch(async (e: any) => {
411
411
  await this.apiError(e)
412
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
412
+ this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
413
413
  await this.BLEPushConnection()
414
414
  })
415
415
  } else {
416
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
416
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
417
417
  await this.BLEPushConnection()
418
418
  }
419
419
  } catch (error) {
420
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
420
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
421
421
  }
422
422
  } else {
423
- await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
423
+ this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
424
424
  }
425
425
  }
426
426
 
427
427
  async openAPIpushChanges() {
428
- await this.debugLog('openAPIpushChanges')
428
+ this.debugLog('openAPIpushChanges')
429
429
  if (this.LightBulb.On !== this.accessory.context.On) {
430
430
  const command = this.LightBulb.On ? 'start' : 'dock'
431
431
  const bodyChange: bodyChange = {
@@ -433,28 +433,28 @@ export class RobotVacuumCleaner extends deviceBase {
433
433
  parameter: 'default',
434
434
  commandType: 'command',
435
435
  }
436
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
436
+ this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
437
437
  try {
438
- const { body } = await this.pushChangeRequest(bodyChange)
439
- const deviceStatus: any = await body
440
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
438
+ const response = await this.pushChangeRequest(bodyChange)
439
+ const deviceStatus: any = response.body
440
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
441
441
  if (await this.successfulStatusCodes(deviceStatus)) {
442
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
442
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
443
443
  await this.updateHomeKitCharacteristics()
444
444
  } else {
445
445
  await this.statusCode(deviceStatus.statusCode)
446
446
  }
447
447
  } catch (e: any) {
448
448
  await this.apiError(e)
449
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
449
+ this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
450
450
  }
451
451
  } else {
452
- await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
452
+ this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
453
453
  }
454
454
  }
455
455
 
456
456
  async openAPIpushBrightnessChanges() {
457
- await this.debugLog('openAPIpushBrightnessChanges')
457
+ this.debugLog('openAPIpushBrightnessChanges')
458
458
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
459
459
  const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel'
460
460
  const parameter = this.LightBulb.Brightness === 25
@@ -469,23 +469,23 @@ export class RobotVacuumCleaner extends deviceBase {
469
469
  parameter: `${parameter}`,
470
470
  commandType: 'command',
471
471
  }
472
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
472
+ this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
473
473
  try {
474
- const { body } = await this.pushChangeRequest(bodyChange)
475
- const deviceStatus: any = await body
476
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
474
+ const response = await this.pushChangeRequest(bodyChange)
475
+ const deviceStatus: any = response.body
476
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
477
477
  if (await this.successfulStatusCodes(deviceStatus)) {
478
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
478
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
479
479
  await this.updateHomeKitCharacteristics()
480
480
  } else {
481
481
  await this.statusCode(deviceStatus.statusCode)
482
482
  }
483
483
  } catch (e: any) {
484
484
  await this.apiError(e)
485
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
485
+ this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
486
486
  }
487
487
  } else {
488
- await this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
488
+ this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
489
489
  }
490
490
  }
491
491
 
@@ -508,7 +508,7 @@ export class RobotVacuumCleaner extends deviceBase {
508
508
  */
509
509
  async BrightnessSet(value: CharacteristicValue): Promise<void> {
510
510
  if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
511
- await this.infoLog(`Set Brightness: ${value}`)
511
+ this.infoLog(`Set Brightness: ${value}`)
512
512
  } else {
513
513
  if (this.LightBulb.On) {
514
514
  this.debugLog(`No Changes, Brightness: ${value}`)
@@ -536,15 +536,15 @@ export class RobotVacuumCleaner extends deviceBase {
536
536
 
537
537
  async BLEPushConnection() {
538
538
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
539
- await this.warnLog('Using OpenAPI Connection to Push Changes')
539
+ this.warnLog('Using OpenAPI Connection to Push Changes')
540
540
  await this.openAPIpushChanges()
541
541
  }
542
542
  }
543
543
 
544
544
  async BLERefreshConnection(switchbot: any): Promise<void> {
545
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
545
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
546
546
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
547
- await this.warnLog('Using OpenAPI Connection to Refresh Status')
547
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
548
548
  await this.openAPIRefreshStatus()
549
549
  }
550
550
  }
@@ -139,20 +139,20 @@ export class WaterDetector extends deviceBase {
139
139
  interval(this.deviceRefreshRate * 1000)
140
140
  .pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
141
141
  .subscribe(async () => {
142
- await this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`)
142
+ this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`)
143
143
  await this.refreshStatus()
144
144
  })
145
145
  }
146
146
 
147
147
  async BLEparseStatus(): Promise<void> {
148
- await this.debugLog('BLEparseStatus')
149
- await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
148
+ this.debugLog('BLEparseStatus')
149
+ this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
150
150
 
151
151
  // LeakSensor
152
152
  if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
153
153
  // StatusActive
154
154
  this.LeakSensor.StatusActive = this.serviceData.state
155
- await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
155
+ this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
156
156
 
157
157
  // LeakDetected
158
158
  if ((this.device as waterDetectorConfig).dry) {
@@ -165,23 +165,23 @@ export class WaterDetector extends deviceBase {
165
165
  }
166
166
  // BatteryLevel
167
167
  this.Battery.BatteryLevel = this.serviceData.battery
168
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
168
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
169
169
  // StatusLowBattery
170
170
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
171
171
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
172
172
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
173
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
173
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
174
174
  }
175
175
 
176
176
  async openAPIparseStatus(): Promise<void> {
177
- await this.debugLog('openAPIparseStatus')
178
- await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
177
+ this.debugLog('openAPIparseStatus')
178
+ this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
179
179
 
180
180
  // LeakSensor
181
181
  if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
182
182
  // StatusActive
183
183
  this.LeakSensor.StatusActive = this.deviceStatus.battery !== 0
184
- await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
184
+ this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
185
185
 
186
186
  // LeakDetected
187
187
  if ((this.device as waterDetectorConfig).dry) {
@@ -195,18 +195,18 @@ export class WaterDetector extends deviceBase {
195
195
 
196
196
  // BatteryLevel
197
197
  this.Battery.BatteryLevel = this.deviceStatus.battery
198
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
198
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
199
199
 
200
200
  // StatusLowBattery
201
201
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
202
202
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
203
203
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
204
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
204
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
205
205
 
206
206
  // FirmwareVersion
207
207
  if (this.deviceStatus.version) {
208
208
  const version = this.deviceStatus.version.toString()
209
- await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`)
209
+ this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`)
210
210
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
211
211
  this.accessory
212
212
  .getService(this.hap.Service.AccessoryInformation)!
@@ -215,19 +215,19 @@ export class WaterDetector extends deviceBase {
215
215
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
216
216
  .updateValue(deviceVersion)
217
217
  this.accessory.context.version = deviceVersion
218
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
218
+ this.debugSuccessLog(`version: ${this.accessory.context.version}`)
219
219
  }
220
220
  }
221
221
 
222
222
  async parseStatusWebhook(): Promise<void> {
223
- await this.debugLog('parseStatusWebhook')
224
- await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
223
+ this.debugLog('parseStatusWebhook')
224
+ this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
225
225
 
226
226
  // LeakSensor
227
227
  if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
228
228
  // StatusActive
229
229
  this.LeakSensor.StatusActive = !!this.webhookContext.detectionState
230
- await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
230
+ this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
231
231
 
232
232
  // LeakDetected
233
233
  if ((this.device as waterDetectorConfig).dry) {
@@ -235,19 +235,19 @@ export class WaterDetector extends deviceBase {
235
235
  this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
236
236
  } else {
237
237
  this.LeakSensor.LeakDetected = this.webhookContext.detectionState
238
- await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
238
+ this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
239
239
  }
240
240
  }
241
241
 
242
242
  // BatteryLevel
243
243
  this.Battery.BatteryLevel = this.webhookContext.battery
244
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
244
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
245
245
 
246
246
  // StatusLowBattery
247
247
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
248
248
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
249
249
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
250
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
250
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
251
251
  }
252
252
 
253
253
  /**
@@ -255,19 +255,19 @@ export class WaterDetector extends deviceBase {
255
255
  */
256
256
  async refreshStatus(): Promise<void> {
257
257
  if (!this.device.enableCloudService && this.OpenAPI) {
258
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
258
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
259
259
  } else if (this.BLE) {
260
260
  await this.BLERefreshStatus()
261
261
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
262
262
  await this.openAPIRefreshStatus()
263
263
  } else {
264
264
  await this.offlineOff()
265
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
265
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
266
266
  }
267
267
  }
268
268
 
269
269
  async BLERefreshStatus(): Promise<void> {
270
- await this.debugLog('BLERefreshStatus')
270
+ this.debugLog('BLERefreshStatus')
271
271
  const switchBotBLE = await this.switchbotBLE()
272
272
  if (switchBotBLE === undefined) {
273
273
  await this.BLERefreshConnection(switchBotBLE)
@@ -282,7 +282,7 @@ export class WaterDetector extends deviceBase {
282
282
  await this.BLEparseStatus()
283
283
  await this.updateHomeKitCharacteristics()
284
284
  } else {
285
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
285
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
286
286
  await this.BLERefreshConnection(switchBotBLE)
287
287
  }
288
288
  })()
@@ -290,67 +290,67 @@ export class WaterDetector extends deviceBase {
290
290
  }
291
291
 
292
292
  async registerPlatformBLE(): Promise<void> {
293
- await this.debugLog('registerPlatformBLE')
293
+ this.debugLog('registerPlatformBLE')
294
294
  if (this.config.options?.BLE) {
295
- await this.debugLog('is listening to Platform BLE.')
295
+ this.debugLog('is listening to Platform BLE.')
296
296
  try {
297
297
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
298
298
  this.device.bleMac = formattedDeviceId
299
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
299
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
300
300
  this.platform.bleEventHandler[this.device.bleMac] = async (context: waterLeakDetectorServiceData) => {
301
301
  try {
302
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
302
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
303
303
  this.serviceData = context
304
304
  await this.BLEparseStatus()
305
305
  await this.updateHomeKitCharacteristics()
306
306
  } catch (e: any) {
307
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
307
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
308
308
  }
309
309
  }
310
310
  } catch (error) {
311
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
311
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
312
312
  }
313
313
  } else {
314
- await this.debugLog('is not listening to Platform BLE')
314
+ this.debugLog('is not listening to Platform BLE')
315
315
  }
316
316
  }
317
317
 
318
318
  async openAPIRefreshStatus(): Promise<void> {
319
- await this.debugLog('openAPIRefreshStatus')
319
+ this.debugLog('openAPIRefreshStatus')
320
320
  try {
321
- const { body } = await this.deviceRefreshStatus()
322
- const deviceStatus: any = await body
323
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
321
+ const response = await this.deviceRefreshStatus()
322
+ const deviceStatus: any = response.body
323
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
324
324
  if (await this.successfulStatusCodes(deviceStatus)) {
325
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
325
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
326
326
  this.deviceStatus = deviceStatus.body
327
327
  await this.openAPIparseStatus()
328
328
  await this.updateHomeKitCharacteristics()
329
329
  } else {
330
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
331
- await this.debugWarnLog(deviceStatus)
330
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
331
+ this.debugWarnLog(deviceStatus)
332
332
  }
333
333
  } catch (e: any) {
334
334
  await this.apiError(e)
335
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
335
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
336
336
  }
337
337
  }
338
338
 
339
339
  async registerWebhook() {
340
340
  if (this.device.webhook) {
341
- await this.debugLog('is listening webhook.')
341
+ this.debugLog('is listening webhook.')
342
342
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
343
343
  try {
344
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
344
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
345
345
  this.webhookContext = context
346
346
  await this.parseStatusWebhook()
347
347
  await this.updateHomeKitCharacteristics()
348
348
  } catch (e: any) {
349
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
349
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
350
350
  }
351
351
  }
352
352
  } else {
353
- await this.debugLog('is not listening webhook.')
353
+ this.debugLog('is not listening webhook.')
354
354
  }
355
355
  }
356
356
 
@@ -371,9 +371,9 @@ export class WaterDetector extends deviceBase {
371
371
  }
372
372
 
373
373
  async BLERefreshConnection(switchbot: any): Promise<void> {
374
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
374
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
375
375
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
376
- await this.warnLog('Using OpenAPI Connection to Refresh Status')
376
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
377
377
  await this.openAPIRefreshStatus()
378
378
  }
379
379
  }