@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
@@ -209,7 +209,7 @@ export class Curtain extends deviceBase {
209
209
  if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
210
210
  return;
211
211
  }
212
- await this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`);
212
+ this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`);
213
213
  await this.refreshStatus();
214
214
  });
215
215
  // Watch for Curtain change events
@@ -224,7 +224,7 @@ export class Curtain extends deviceBase {
224
224
  }
225
225
  catch (e) {
226
226
  await this.apiError(e);
227
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
227
+ this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
228
228
  }
229
229
  this.curtainUpdateInProgress = false;
230
230
  });
@@ -251,7 +251,7 @@ export class Curtain extends deviceBase {
251
251
  try {
252
252
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
253
253
  this.device.bleMac = formattedDeviceId;
254
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
254
+ this.debugLog(`bleMac: ${this.device.bleMac}`);
255
255
  this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
256
256
  log: this.platform.log,
257
257
  storage: 'fs',
@@ -282,45 +282,47 @@ export class Curtain extends deviceBase {
282
282
  this.updateHistory();
283
283
  }
284
284
  catch (error) {
285
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
285
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
286
286
  }
287
287
  }
288
- async updateHistory() {
288
+ updateHistory() {
289
289
  const motion = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0;
290
290
  this.historyService.addEntry({
291
291
  time: Math.round(new Date().valueOf() / 1000),
292
292
  motion,
293
293
  });
294
- setTimeout(async () => {
295
- await this.updateHistory();
294
+ setTimeout(() => {
295
+ this.updateHistory();
296
296
  }, 10 * 60 * 1000);
297
297
  }
298
298
  async BLEparseStatus() {
299
- await this.debugLog('BLEparseStatus');
300
- await this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
299
+ this.debugLog('BLEparseStatus');
300
+ this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
301
301
  // CurrentPosition
302
- this.WindowCovering.CurrentPosition = 100 - this.serviceData.position;
303
- await this.getCurrentPostion();
302
+ if (this.serviceData.position) {
303
+ this.WindowCovering.CurrentPosition = 100 - this.serviceData.position;
304
+ await this.getCurrentPostion();
305
+ }
304
306
  // CurrentAmbientLightLevel
305
- if (!this.device.hide_lightsensor && this.LightSensor?.Service) {
307
+ if (!this.device.hide_lightsensor && this.LightSensor?.Service && this.serviceData.lightLevel) {
306
308
  const set_minLux = this.device.set_minLux ?? 1;
307
309
  const set_maxLux = this.device.set_maxLux ?? 6001;
308
310
  const lightLevel = this.serviceData.lightLevel;
309
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19);
311
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19);
310
312
  this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
311
313
  }
312
314
  // BatteryLevel
313
315
  this.Battery.BatteryLevel = this.serviceData.battery;
314
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
316
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
315
317
  // StatusLowBattery
316
318
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
317
319
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
318
320
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
319
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
321
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
320
322
  }
321
323
  async openAPIparseStatus() {
322
- await this.debugLog('openAPIparseStatus');
323
- await this.debugLog(`(slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
324
+ this.debugLog('openAPIparseStatus');
325
+ this.debugLog(`(slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
324
326
  // CurrentPosition
325
327
  this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition;
326
328
  await this.getCurrentPostion();
@@ -329,21 +331,21 @@ export class Curtain extends deviceBase {
329
331
  const set_minLux = this.device.set_minLux ?? 1;
330
332
  const set_maxLux = this.device.set_maxLux ?? 6001;
331
333
  const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux;
332
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
333
- await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
334
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
335
+ this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
334
336
  }
335
337
  // BatteryLevel
336
338
  this.Battery.BatteryLevel = this.deviceStatus.battery;
337
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
339
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
338
340
  // StatusLowBattery
339
341
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
340
342
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
341
343
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
342
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
344
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
343
345
  // Firmware Version
344
346
  if (this.deviceStatus.version) {
345
347
  const version = this.deviceStatus.version.toString();
346
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
348
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
347
349
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
348
350
  this.accessory
349
351
  .getService(this.hap.Service.AccessoryInformation)
@@ -352,30 +354,30 @@ export class Curtain extends deviceBase {
352
354
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
353
355
  .updateValue(deviceVersion);
354
356
  this.accessory.context.version = deviceVersion;
355
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
357
+ this.debugSuccessLog(`version: ${this.accessory.context.version}`);
356
358
  }
357
359
  }
358
360
  async parseStatusWebhook() {
359
- await this.debugLog('parseStatusWebhook');
360
- await this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
361
+ this.debugLog('parseStatusWebhook');
362
+ this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
361
363
  // CurrentPosition
362
364
  this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition;
363
365
  await this.getCurrentPostion();
364
366
  // BatteryLevel
365
367
  this.Battery.BatteryLevel = this.webhookContext.battery;
366
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
368
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
367
369
  // StatusLowBattery
368
370
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
369
371
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
370
372
  : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
371
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
373
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
372
374
  }
373
375
  /**
374
376
  * Asks the SwitchBot API for the latest device information
375
377
  */
376
378
  async refreshStatus() {
377
379
  if (!this.device.enableCloudService && this.OpenAPI) {
378
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
380
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
379
381
  }
380
382
  else if (this.BLE) {
381
383
  await this.BLERefreshStatus();
@@ -385,11 +387,11 @@ export class Curtain extends deviceBase {
385
387
  }
386
388
  else {
387
389
  await this.offlineOff();
388
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
390
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
389
391
  }
390
392
  }
391
393
  async BLERefreshStatus() {
392
- await this.debugLog('BLERefreshStatus');
394
+ this.debugLog('BLERefreshStatus');
393
395
  const switchBotBLE = await this.switchbotBLE();
394
396
  if (switchBotBLE === undefined) {
395
397
  await this.BLERefreshConnection(switchBotBLE);
@@ -407,79 +409,79 @@ export class Curtain extends deviceBase {
407
409
  await this.updateHomeKitCharacteristics();
408
410
  }
409
411
  else {
410
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
412
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
411
413
  await this.BLERefreshConnection(switchBotBLE);
412
414
  }
413
415
  })();
414
416
  }
415
417
  }
416
418
  async openAPIRefreshStatus() {
417
- await this.debugLog('openAPIRefreshStatus');
419
+ this.debugLog('openAPIRefreshStatus');
418
420
  try {
419
421
  const { body } = await this.deviceRefreshStatus();
420
422
  const deviceStatus = body;
421
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
423
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
422
424
  if (await this.successfulStatusCodes(deviceStatus)) {
423
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
425
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
424
426
  this.deviceStatus = deviceStatus.body;
425
427
  await this.openAPIparseStatus();
426
428
  await this.updateHomeKitCharacteristics();
427
429
  }
428
430
  else {
429
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
430
- await this.debugWarnLog(deviceStatus);
431
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
432
+ this.debugWarnLog(deviceStatus);
431
433
  }
432
434
  }
433
435
  catch (e) {
434
436
  await this.apiError(e);
435
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
437
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
436
438
  }
437
439
  }
438
440
  async registerWebhook() {
439
441
  if (this.device.webhook) {
440
- await this.debugLog('is listening webhook.');
442
+ this.debugLog('is listening webhook.');
441
443
  this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
442
444
  try {
443
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
445
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
444
446
  this.webhookContext = context;
445
447
  await this.parseStatusWebhook();
446
448
  await this.updateHomeKitCharacteristics();
447
449
  }
448
450
  catch (e) {
449
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
451
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
450
452
  }
451
453
  };
452
454
  }
453
455
  else {
454
- await this.debugLog('is not listening webhook.');
456
+ this.debugLog('is not listening webhook.');
455
457
  }
456
458
  }
457
459
  async registerPlatformBLE() {
458
- await this.debugLog('registerPlatformBLE');
460
+ this.debugLog('registerPlatformBLE');
459
461
  if (this.config.options?.BLE) {
460
- await this.debugLog('is listening to Platform BLE.');
462
+ this.debugLog('is listening to Platform BLE.');
461
463
  try {
462
464
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
463
465
  this.device.bleMac = formattedDeviceId;
464
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
466
+ this.debugLog(`bleMac: ${this.device.bleMac}`);
465
467
  this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
466
468
  try {
467
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
469
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`);
468
470
  this.serviceData = context;
469
471
  await this.BLEparseStatus();
470
472
  await this.updateHomeKitCharacteristics();
471
473
  }
472
474
  catch (e) {
473
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
475
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
474
476
  }
475
477
  };
476
478
  }
477
479
  catch (error) {
478
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
480
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
479
481
  }
480
482
  }
481
483
  else {
482
- await this.debugLog('is not listening to Platform BLE');
484
+ this.debugLog('is not listening to Platform BLE');
483
485
  }
484
486
  }
485
487
  /**
@@ -487,7 +489,7 @@ export class Curtain extends deviceBase {
487
489
  */
488
490
  async pushChanges() {
489
491
  if (!this.device.enableCloudService && this.OpenAPI) {
490
- await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
492
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
491
493
  }
492
494
  else if (this.BLE) {
493
495
  await this.BLEpushChanges();
@@ -497,7 +499,7 @@ export class Curtain extends deviceBase {
497
499
  }
498
500
  else {
499
501
  await this.offlineOff();
500
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
502
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
501
503
  }
502
504
  // Refresh the status from the API
503
505
  interval(15000)
@@ -508,16 +510,16 @@ export class Curtain extends deviceBase {
508
510
  });
509
511
  }
510
512
  async BLEpushChanges() {
511
- await this.debugLog('BLEpushChanges');
513
+ this.debugLog('BLEpushChanges');
512
514
  if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
513
515
  const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
514
516
  try {
515
517
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
516
518
  this.device.bleMac = formattedDeviceId;
517
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
519
+ this.debugLog(`bleMac: ${this.device.bleMac}`);
518
520
  const { setPositionMode, Mode } = await this.setPerformance();
519
521
  const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF;
520
- await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
522
+ this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
521
523
  if (switchBotBLE !== false) {
522
524
  switchBotBLE
523
525
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
@@ -531,35 +533,35 @@ export class Curtain extends deviceBase {
531
533
  });
532
534
  })
533
535
  .then(async () => {
534
- await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
536
+ this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
535
537
  await this.updateHomeKitCharacteristics();
536
538
  })
537
539
  .catch(async (e) => {
538
540
  await this.apiError(e);
539
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
541
+ this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
540
542
  await this.BLEPushConnection();
541
543
  });
542
544
  }
543
545
  else {
544
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
546
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
545
547
  await this.BLEPushConnection();
546
548
  }
547
549
  }
548
550
  catch (error) {
549
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
551
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
550
552
  }
551
553
  }
552
554
  else {
553
- await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
555
+ this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
554
556
  }
555
557
  }
556
558
  async openAPIpushChanges() {
557
- await this.debugLog('openAPIpushChanges');
559
+ this.debugLog('openAPIpushChanges');
558
560
  if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition || this.device.disableCaching) {
559
- await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`);
561
+ this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`);
560
562
  const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition);
561
563
  const { setPositionMode, Mode } = await this.setPerformance();
562
- await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
564
+ this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
563
565
  const adjustedMode = setPositionMode || 'ff';
564
566
  let bodyChange;
565
567
  if (this.WindowCovering.HoldPosition) {
@@ -576,13 +578,13 @@ export class Curtain extends deviceBase {
576
578
  commandType: 'command',
577
579
  };
578
580
  }
579
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
581
+ this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
580
582
  try {
581
- const { body } = await this.pushChangeRequest(bodyChange);
582
- const deviceStatus = await body;
583
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
583
+ const response = await this.pushChangeRequest(bodyChange);
584
+ const deviceStatus = response.body;
585
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
584
586
  if (await this.successfulStatusCodes(deviceStatus)) {
585
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
587
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
586
588
  await this.updateHomeKitCharacteristics();
587
589
  }
588
590
  else {
@@ -591,11 +593,11 @@ export class Curtain extends deviceBase {
591
593
  }
592
594
  catch (e) {
593
595
  await this.apiError(e);
594
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
596
+ this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
595
597
  }
596
598
  }
597
599
  else {
598
- await this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`);
600
+ this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`);
599
601
  }
600
602
  }
601
603
  /**
@@ -603,10 +605,10 @@ export class Curtain extends deviceBase {
603
605
  */
604
606
  async TargetPositionSet(value) {
605
607
  if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
606
- await this.infoLog(`Set TargetPosition: ${value}`);
608
+ this.infoLog(`Set TargetPosition: ${value}`);
607
609
  }
608
610
  else {
609
- await this.debugLog(`No Changes, TargetPosition: ${value}`);
611
+ this.debugLog(`No Changes, TargetPosition: ${value}`);
610
612
  }
611
613
  // Set HoldPosition to false when TargetPosition is changed
612
614
  this.WindowCovering.HoldPosition = false;
@@ -621,17 +623,17 @@ export class Curtain extends deviceBase {
621
623
  if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
622
624
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
623
625
  this.setNewTarget = true;
624
- await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
626
+ this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
625
627
  }
626
628
  else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
627
629
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
628
630
  this.setNewTarget = true;
629
- await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
631
+ this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
630
632
  }
631
633
  else {
632
634
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
633
635
  this.setNewTarget = false;
634
- await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
636
+ this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
635
637
  }
636
638
  this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
637
639
  this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
@@ -640,10 +642,10 @@ export class Curtain extends deviceBase {
640
642
  * The minimum time depends on the network control latency.
641
643
  */
642
644
  clearTimeout(this.setNewTargetTimer);
643
- await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
645
+ this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
644
646
  if (this.setNewTarget) {
645
647
  this.setNewTargetTimer = setTimeout(async () => {
646
- await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
648
+ this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
647
649
  this.setNewTarget = false;
648
650
  }, this.deviceUpdateRate * 1000);
649
651
  }
@@ -707,14 +709,14 @@ export class Curtain extends deviceBase {
707
709
  }
708
710
  async BLEPushConnection() {
709
711
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
710
- await this.warnLog('Using OpenAPI Connection to Push Changes');
712
+ this.warnLog('Using OpenAPI Connection to Push Changes');
711
713
  await this.openAPIpushChanges();
712
714
  }
713
715
  }
714
716
  async BLERefreshConnection(switchbot) {
715
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
717
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
716
718
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
717
- await this.warnLog('Using OpenAPI Connection to Refresh Status');
719
+ this.warnLog('Using OpenAPI Connection to Refresh Status');
718
720
  await this.openAPIRefreshStatus();
719
721
  }
720
722
  }
@@ -754,7 +756,7 @@ export class Curtain extends deviceBase {
754
756
  }
755
757
  async getCurrentPostion() {
756
758
  await this.setMinMax();
757
- await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
759
+ this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
758
760
  this.hasLoggedStandby = this.hasLoggedStandby ?? false;
759
761
  if (this.deviceStatus ? (this.setNewTarget || this.deviceStatus.moving) : this.setNewTarget) {
760
762
  this.hasLoggedStandby = false;
@@ -762,36 +764,36 @@ export class Curtain extends deviceBase {
762
764
  this.curtainMoving = true;
763
765
  await this.setMinMax();
764
766
  if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
765
- await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
767
+ this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
766
768
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
767
769
  this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
768
- await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
770
+ this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
769
771
  }
770
772
  else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
771
- await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
773
+ this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
772
774
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
773
775
  this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
774
- await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
776
+ this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
775
777
  }
776
778
  else {
777
- await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
779
+ this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
778
780
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
779
781
  this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
780
- await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
782
+ this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
781
783
  }
782
784
  }
783
785
  else {
784
786
  if (!this.hasLoggedStandby) {
785
- await this.infoLog('Standby ...');
787
+ this.infoLog('Standby ...');
786
788
  this.hasLoggedStandby = true;
787
789
  }
788
790
  this.curtainMoving = false;
789
- await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
791
+ this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
790
792
  this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
791
793
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
792
- await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
794
+ this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
793
795
  }
794
- await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
796
+ this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
795
797
  }
796
798
  async setMinMax() {
797
799
  if (this.device.set_min) {