@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/.prettierrc +1 -1
  3. package/.vscode/settings.json +1 -1
  4. package/CHANGELOG.md +10 -0
  5. package/config.schema.json +8 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +49 -59
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +44 -50
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +60 -63
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +68 -70
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +22 -25
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +50 -58
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/hub.d.ts +6 -0
  25. package/dist/device/hub.d.ts.map +1 -1
  26. package/dist/device/hub.js +168 -26
  27. package/dist/device/hub.js.map +1 -1
  28. package/dist/device/humidifier.d.ts.map +1 -1
  29. package/dist/device/humidifier.js +49 -56
  30. package/dist/device/humidifier.js.map +1 -1
  31. package/dist/device/iosensor.d.ts.map +1 -1
  32. package/dist/device/iosensor.js +18 -20
  33. package/dist/device/iosensor.js.map +1 -1
  34. package/dist/device/lightstrip.d.ts.map +1 -1
  35. package/dist/device/lightstrip.js +59 -61
  36. package/dist/device/lightstrip.js.map +1 -1
  37. package/dist/device/lock.d.ts.map +1 -1
  38. package/dist/device/lock.js +40 -41
  39. package/dist/device/lock.js.map +1 -1
  40. package/dist/device/meter.d.ts +3 -3
  41. package/dist/device/meter.d.ts.map +1 -1
  42. package/dist/device/meter.js +65 -68
  43. package/dist/device/meter.js.map +1 -1
  44. package/dist/device/meterplus.d.ts.map +1 -1
  45. package/dist/device/meterplus.js +18 -20
  46. package/dist/device/meterplus.js.map +1 -1
  47. package/dist/device/motion.d.ts.map +1 -1
  48. package/dist/device/motion.js +20 -23
  49. package/dist/device/motion.js.map +1 -1
  50. package/dist/device/plug.d.ts.map +1 -1
  51. package/dist/device/plug.js +30 -33
  52. package/dist/device/plug.js.map +1 -1
  53. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  54. package/dist/device/robotvacuumcleaner.js +48 -51
  55. package/dist/device/robotvacuumcleaner.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  57. package/dist/irdevice/airconditioner.js +57 -61
  58. package/dist/irdevice/airconditioner.js.map +1 -1
  59. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  60. package/dist/irdevice/airpurifier.js +29 -31
  61. package/dist/irdevice/airpurifier.js.map +1 -1
  62. package/dist/irdevice/camera.d.ts.map +1 -1
  63. package/dist/irdevice/camera.js +17 -20
  64. package/dist/irdevice/camera.js.map +1 -1
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +27 -29
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts.map +1 -1
  69. package/dist/irdevice/light.js +23 -26
  70. package/dist/irdevice/light.js.map +1 -1
  71. package/dist/irdevice/other.d.ts.map +1 -1
  72. package/dist/irdevice/other.js +19 -20
  73. package/dist/irdevice/other.js.map +1 -1
  74. package/dist/irdevice/tv.d.ts.map +1 -1
  75. package/dist/irdevice/tv.js +44 -47
  76. package/dist/irdevice/tv.js.map +1 -1
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +17 -20
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts.map +1 -1
  81. package/dist/irdevice/waterheater.js +19 -20
  82. package/dist/irdevice/waterheater.js.map +1 -1
  83. package/dist/platform.d.ts.map +1 -1
  84. package/dist/platform.js +44 -43
  85. package/dist/platform.js.map +1 -1
  86. package/dist/settings.d.ts +1 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js.map +1 -1
  89. package/dist/utils.js +1 -1
  90. package/dist/utils.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/device/blindtilt.ts +106 -72
  93. package/src/device/bot.ts +94 -58
  94. package/src/device/ceilinglight.ts +102 -68
  95. package/src/device/colorbulb.ts +134 -82
  96. package/src/device/contact.ts +54 -33
  97. package/src/device/curtain.ts +130 -101
  98. package/src/device/hub.ts +198 -35
  99. package/src/device/humidifier.ts +128 -80
  100. package/src/device/iosensor.ts +43 -27
  101. package/src/device/lightstrip.ts +108 -67
  102. package/src/device/lock.ts +73 -45
  103. package/src/device/meter.ts +94 -75
  104. package/src/device/meterplus.ts +43 -27
  105. package/src/device/motion.ts +50 -32
  106. package/src/device/plug.ts +62 -39
  107. package/src/device/robotvacuumcleaner.ts +78 -54
  108. package/src/irdevice/airconditioner.ts +111 -83
  109. package/src/irdevice/airpurifier.ts +55 -34
  110. package/src/irdevice/camera.ts +35 -23
  111. package/src/irdevice/fan.ts +47 -33
  112. package/src/irdevice/light.ts +43 -29
  113. package/src/irdevice/other.ts +39 -23
  114. package/src/irdevice/tv.ts +65 -51
  115. package/src/irdevice/vacuumcleaner.ts +35 -23
  116. package/src/irdevice/waterheater.ts +43 -27
  117. package/src/platform.ts +85 -55
  118. package/src/settings.ts +41 -40
  119. package/src/utils.ts +1 -1
@@ -68,13 +68,17 @@ export class Curtain {
68
68
  doCurtainUpdate!: Subject<void>;
69
69
 
70
70
  // Connection
71
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
72
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
71
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
72
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
73
73
 
74
74
  // EVE history service handler
75
75
  historyService: any = null;
76
76
 
77
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
77
+ constructor(
78
+ private readonly platform: SwitchBotPlatform,
79
+ private accessory: PlatformAccessory,
80
+ public device: device & devicesConfig,
81
+ ) {
78
82
  // default placeholders
79
83
  this.logs(device);
80
84
  this.refreshRate(device);
@@ -218,8 +222,10 @@ export class Curtain {
218
222
  await this.pushChanges();
219
223
  } catch (e: any) {
220
224
  this.apiError(e);
221
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
222
- + ` Error Message: ${JSON.stringify(e.message)}`);
225
+ this.errorLog(
226
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
227
+ ` Error Message: ${JSON.stringify(e.message)}`,
228
+ );
223
229
  }
224
230
  this.curtainUpdateInProgress = false;
225
231
  });
@@ -229,66 +235,65 @@ export class Curtain {
229
235
  }
230
236
 
231
237
  /*
232
- * Setup EVE history features for curtain devices.
238
+ * Setup EVE history features for curtain devices.
233
239
  */
234
240
  async setupHistoryService(device: device & devicesConfig): Promise<void> {
235
241
  if (device.history !== true) {
236
242
  return;
237
243
  }
238
-
244
+
239
245
  const mac = this.device
240
246
  .deviceId!.match(/.{1,2}/g)!
241
247
  .join(':')
242
248
  .toLowerCase();
243
- this.historyService =
244
- new this.platform.fakegatoAPI('custom', this.accessory, {
245
- log: this.platform.log,
246
- storage: 'fs',
247
- filename: `${hostname().split(".")[0]}_${mac}_persist.json`
248
- });
249
+ this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
250
+ log: this.platform.log,
251
+ storage: 'fs',
252
+ filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
253
+ });
249
254
  const motion: Service =
250
- this.accessory.getService(this.platform.Service.MotionSensor) ||
251
- this.accessory.addService(this.platform.Service.MotionSensor,
252
- `${this.accessory.displayName} Motion`);
255
+ this.accessory.getService(this.platform.Service.MotionSensor) ||
256
+ this.accessory.addService(this.platform.Service.MotionSensor, `${this.accessory.displayName} Motion`);
253
257
  motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation);
254
- motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation)
255
- .onGet(() => {
256
- const lastActivation = this.accessory.context.lastActivation ?
257
- Math.max(0, this.accessory.context.lastActivation -
258
- this.historyService.getInitialTime()) : 0;
259
- return lastActivation;
260
- });
258
+ motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
259
+ const lastActivation = this.accessory.context.lastActivation
260
+ ? Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime())
261
+ : 0;
262
+ return lastActivation;
263
+ });
261
264
  await this.setMinMax();
262
- motion.getCharacteristic(this.platform.Characteristic.MotionDetected)
263
- .on('change', (event: CharacteristicChange) => {
264
- if (event.newValue !== event.oldValue) {
265
- const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
266
- const entry = {
267
- time: Math.round(new Date().valueOf()/1000),
268
- motion: event.newValue
269
- };
270
- this.accessory.context.lastActivation = entry.time;
271
- sensor?.updateCharacteristic(
272
- this.platform.eve.Characteristics.LastActivation,
273
- Math.max(0, this.accessory.context.lastActivation -
274
- this.historyService.getInitialTime()));
275
- this.historyService.addEntry(entry);
276
- }
277
- });
265
+ motion.getCharacteristic(this.platform.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
266
+ if (event.newValue !== event.oldValue) {
267
+ const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
268
+ const entry = {
269
+ time: Math.round(new Date().valueOf() / 1000),
270
+ motion: event.newValue,
271
+ };
272
+ this.accessory.context.lastActivation = entry.time;
273
+ sensor?.updateCharacteristic(
274
+ this.platform.eve.Characteristics.LastActivation,
275
+ Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime()),
276
+ );
277
+ this.historyService.addEntry(entry);
278
+ }
279
+ });
278
280
  this.updateHistory();
279
281
  }
280
282
 
281
- async updateHistory() : Promise<void>{
283
+ async updateHistory(): Promise<void> {
282
284
  const motion = Number(this.CurrentPosition) > 0 ? 1 : 0;
283
- this.historyService.addEntry ({
284
- time: Math.round(new Date().valueOf()/1000),
285
- motion: motion
285
+ this.historyService.addEntry({
286
+ time: Math.round(new Date().valueOf() / 1000),
287
+ motion: motion,
286
288
  });
287
- setTimeout(() => {
288
- this.updateHistory();
289
- }, 10 * 60 * 1000);
289
+ setTimeout(
290
+ () => {
291
+ this.updateHistory();
292
+ },
293
+ 10 * 60 * 1000,
294
+ );
290
295
  }
291
-
296
+
292
297
  /**
293
298
  * Parse the device status from the SwitchBot api
294
299
  */
@@ -301,8 +306,9 @@ export class Curtain {
301
306
  await this.openAPIparseStatus();
302
307
  } else {
303
308
  await this.offlineOff();
304
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
305
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
309
+ this.debugWarnLog(
310
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
311
+ );
306
312
  }
307
313
  }
308
314
 
@@ -394,8 +400,8 @@ export class Curtain {
394
400
  this.debugLog();
395
401
  }
396
402
  this.debugLog(
397
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
398
- + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
403
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
404
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
399
405
  );
400
406
  }
401
407
  // Battery
@@ -405,8 +411,9 @@ export class Curtain {
405
411
  } else {
406
412
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
407
413
  }
408
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
409
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
414
+ this.debugLog(
415
+ `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
416
+ );
410
417
  }
411
418
 
412
419
  async openAPIparseStatus(): Promise<void> {
@@ -473,8 +480,10 @@ export class Curtain {
473
480
  await this.openAPIRefreshStatus();
474
481
  } else {
475
482
  await this.offlineOff();
476
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
477
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
483
+ this.debugWarnLog(
484
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
485
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
486
+ );
478
487
  }
479
488
  }
480
489
 
@@ -499,8 +508,10 @@ export class Curtain {
499
508
  // Set an event hander
500
509
  switchbot.onadvertisement = async (ad: any) => {
501
510
  this.address = ad.address;
502
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
503
- + ` BLE Address Found: ${this.address}`);
511
+ this.debugLog(
512
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
513
+ ` BLE Address Found: ${this.address}`,
514
+ );
504
515
  this.serviceData = ad.serviceData;
505
516
  this.calibration = ad.serviceData.calibration;
506
517
  this.battery = ad.serviceData.battery;
@@ -511,7 +522,8 @@ export class Curtain {
511
522
  this.debugLog(
512
523
  `${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
513
524
  `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
514
- `inMotion: ${ad.serviceData.inMotion}`);
525
+ `inMotion: ${ad.serviceData.inMotion}`,
526
+ );
515
527
 
516
528
  if (this.serviceData) {
517
529
  this.connected = true;
@@ -531,8 +543,10 @@ export class Curtain {
531
543
  })
532
544
  .catch(async (e: any) => {
533
545
  this.apiError(e);
534
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
535
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
546
+ this.errorLog(
547
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
548
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
549
+ );
536
550
  await this.BLERefreshConnection(switchbot);
537
551
  });
538
552
  } else {
@@ -550,10 +564,7 @@ export class Curtain {
550
564
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
551
565
  this.statusCode(statusCode);
552
566
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
553
- this.debugLog(
554
- `${this.device.deviceType}: ${this.accessory.displayName
555
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
556
- );
567
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
557
568
  this.slidePosition = deviceStatus.body.slidePosition;
558
569
  this.moving = deviceStatus.body.moving;
559
570
  this.brightness = deviceStatus.body.brightness;
@@ -561,8 +572,10 @@ export class Curtain {
561
572
  this.updateHomeKitCharacteristics();
562
573
  } catch (e: any) {
563
574
  this.apiError(e);
564
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
565
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
575
+ this.errorLog(
576
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
577
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
578
+ );
566
579
  }
567
580
  }
568
581
 
@@ -575,8 +588,9 @@ export class Curtain {
575
588
  await this.openAPIpushChanges();
576
589
  } else {
577
590
  await this.offlineOff();
578
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
579
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
591
+ this.debugWarnLog(
592
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
593
+ );
580
594
  }
581
595
  // Refresh the status from the API
582
596
  interval(15000)
@@ -618,8 +632,10 @@ export class Curtain {
618
632
  })
619
633
  .catch(async (e: any) => {
620
634
  this.apiError(e);
621
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
622
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
635
+ this.errorLog(
636
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
637
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
638
+ );
623
639
  await this.BLEPushConnection();
624
640
  throw new Error('Connection error');
625
641
  });
@@ -630,7 +646,8 @@ export class Curtain {
630
646
  await this.BLEPushConnection();
631
647
  }
632
648
  } else {
633
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
649
+ this.debugLog(
650
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
634
651
  ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
635
652
  );
636
653
  }
@@ -658,7 +675,7 @@ export class Curtain {
658
675
 
659
676
  async openAPIpushChanges(): Promise<void> {
660
677
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
661
- if ((this.TargetPosition !== this.CurrentPosition) || this.device.disableCaching) {
678
+ if (this.TargetPosition !== this.CurrentPosition || this.device.disableCaching) {
662
679
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition}`);
663
680
  const adjustedTargetPosition = 100 - Number(this.TargetPosition);
664
681
  if (Number(this.TargetPosition) > 50) {
@@ -676,9 +693,9 @@ export class Curtain {
676
693
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`);
677
694
  const adjustedMode = this.setPositionMode || 'ff';
678
695
  const bodyChange = JSON.stringify({
679
- 'command': 'setPosition',
680
- 'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
681
- 'commandType': 'command',
696
+ command: 'setPosition',
697
+ parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
698
+ commandType: 'command',
682
699
  });
683
700
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
684
701
  try {
@@ -693,13 +710,16 @@ export class Curtain {
693
710
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
694
711
  } catch (e: any) {
695
712
  this.apiError(e);
696
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
697
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
713
+ this.errorLog(
714
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
715
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
698
716
  );
699
717
  }
700
718
  } else {
701
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
702
- + ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
719
+ this.debugLog(
720
+ `${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
721
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
722
+ );
703
723
  }
704
724
  }
705
725
 
@@ -791,14 +811,16 @@ export class Curtain {
791
811
  }
792
812
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
793
813
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
794
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
795
- + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
796
- if (this.device.history) {
797
- this.historyService?.addEntry ({
798
- time: Math.round(new Date().valueOf()/1000),
799
- lux: this.CurrentAmbientLightLevel
800
- });
801
- }
814
+ this.debugLog(
815
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
816
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
817
+ );
818
+ if (this.device.history) {
819
+ this.historyService?.addEntry({
820
+ time: Math.round(new Date().valueOf() / 1000),
821
+ lux: this.CurrentAmbientLightLevel,
822
+ });
823
+ }
802
824
  }
803
825
  }
804
826
  if (this.BLE) {
@@ -970,8 +992,10 @@ export class Curtain {
970
992
  if (this.updateRate > device.scanDuration) {
971
993
  this.scanDuration = this.updateRate;
972
994
  if (this.BLE) {
973
- this.warnLog(`${this.device.deviceType}: `
974
- + `${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`);
995
+ this.warnLog(
996
+ `${this.device.deviceType}: ` +
997
+ `${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`,
998
+ );
975
999
  }
976
1000
  } else {
977
1001
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
@@ -1007,8 +1031,10 @@ export class Curtain {
1007
1031
  this.offlineOff();
1008
1032
  break;
1009
1033
  case 171:
1010
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
1011
- + `Hub: ${this.device.hubDeviceId}`);
1034
+ this.errorLog(
1035
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
1036
+ `Hub: ${this.device.hubDeviceId}`,
1037
+ );
1012
1038
  this.offlineOff();
1013
1039
  break;
1014
1040
  case 190:
@@ -1024,8 +1050,10 @@ export class Curtain {
1024
1050
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
1025
1051
  break;
1026
1052
  default:
1027
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
1028
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
1053
+ this.infoLog(
1054
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
1055
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
1056
+ );
1029
1057
  }
1030
1058
  }
1031
1059
 
@@ -1052,8 +1080,9 @@ export class Curtain {
1052
1080
 
1053
1081
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
1054
1082
  let FirmwareRevision: string;
1055
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
1056
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
1083
+ this.debugLog(
1084
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
1085
+ );
1057
1086
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1058
1087
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1059
1088
  if (accessory.context.FirmwareRevision) {
@@ -1087,23 +1116,23 @@ export class Curtain {
1087
1116
 
1088
1117
  if (!this.device.curtain?.hide_lightsensor) {
1089
1118
  if (this.accessory.context.CurrentAmbientLightLevel !== undefined) {
1090
- this.CurrentAmbientLightLevel = this.accessory.context.CurrentAmbientLightLevel;
1119
+ this.CurrentAmbientLightLevel = this.accessory.context.CurrentAmbientLightLevel;
1091
1120
  }
1092
1121
  }
1093
1122
 
1094
1123
  if (this.BLE) {
1095
1124
  if (this.accessory.context.BatteryLevel === undefined) {
1096
- this.BatteryLevel = 100;
1125
+ this.BatteryLevel = 100;
1097
1126
  } else {
1098
- this.BatteryLevel = this.accessory.context.BatteryLevel;
1127
+ this.BatteryLevel = this.accessory.context.BatteryLevel;
1099
1128
  }
1100
1129
  if (this.accessory.context.StatusLowBattery === undefined) {
1101
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1130
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1102
1131
  } else {
1103
- this.StatusLowBattery = this.accessory.context.StatusLowBattery;
1132
+ this.StatusLowBattery = this.accessory.context.StatusLowBattery;
1104
1133
  }
1105
1134
  }
1106
-
1135
+
1107
1136
  if (this.device.history === true) {
1108
1137
  // initialize when this accessory is newly created.
1109
1138
  this.accessory.context.lastActivation = this.accessory.context.lastActivation ?? 0;