@switchbot/homebridge-switchbot 2.2.2-beta.2 → 2.2.2-beta.21

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 (91) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/config.schema.json +0 -31
  3. package/dist/device/bot.d.ts +1 -3
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +2 -2
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts +1 -3
  8. package/dist/device/ceilinglight.d.ts.map +1 -1
  9. package/dist/device/ceilinglight.js +5 -5
  10. package/dist/device/ceilinglight.js.map +1 -1
  11. package/dist/device/colorbulb.d.ts +1 -3
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +7 -7
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts +1 -3
  16. package/dist/device/contact.d.ts.map +1 -1
  17. package/dist/device/contact.js +1 -1
  18. package/dist/device/contact.js.map +1 -1
  19. package/dist/device/curtain.js +1 -1
  20. package/dist/device/curtain.js.map +1 -1
  21. package/dist/device/humidifier.d.ts +7 -9
  22. package/dist/device/humidifier.d.ts.map +1 -1
  23. package/dist/device/humidifier.js +16 -10
  24. package/dist/device/humidifier.js.map +1 -1
  25. package/dist/device/lock.js +1 -1
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +1 -3
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +1 -1
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/meterplus.d.ts +1 -3
  32. package/dist/device/meterplus.d.ts.map +1 -1
  33. package/dist/device/meterplus.js +1 -1
  34. package/dist/device/meterplus.js.map +1 -1
  35. package/dist/device/motion.d.ts +2 -3
  36. package/dist/device/motion.d.ts.map +1 -1
  37. package/dist/device/motion.js +17 -11
  38. package/dist/device/motion.js.map +1 -1
  39. package/dist/device/plug.d.ts +1 -3
  40. package/dist/device/plug.d.ts.map +1 -1
  41. package/dist/device/plug.js +2 -2
  42. package/dist/device/plug.js.map +1 -1
  43. package/dist/device/striplight.d.ts +8 -3
  44. package/dist/device/striplight.d.ts.map +1 -1
  45. package/dist/device/striplight.js +151 -132
  46. package/dist/device/striplight.js.map +1 -1
  47. package/dist/irdevice/airconditioner.js +2 -2
  48. package/dist/irdevice/airconditioner.js.map +1 -1
  49. package/dist/irdevice/airpurifier.js +2 -2
  50. package/dist/irdevice/airpurifier.js.map +1 -1
  51. package/dist/irdevice/camera.js +2 -2
  52. package/dist/irdevice/camera.js.map +1 -1
  53. package/dist/irdevice/fan.js +2 -2
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/light.js +2 -2
  56. package/dist/irdevice/light.js.map +1 -1
  57. package/dist/irdevice/other.js +2 -2
  58. package/dist/irdevice/other.js.map +1 -1
  59. package/dist/irdevice/tv.d.ts.map +1 -1
  60. package/dist/irdevice/tv.js +18 -15
  61. package/dist/irdevice/tv.js.map +1 -1
  62. package/dist/irdevice/vacuumcleaner.js +2 -2
  63. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  64. package/dist/irdevice/waterheater.js +2 -2
  65. package/dist/irdevice/waterheater.js.map +1 -1
  66. package/dist/settings.d.ts +1 -16
  67. package/dist/settings.d.ts.map +1 -1
  68. package/dist/settings.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/device/bot.ts +2 -2
  71. package/src/device/ceilinglight.ts +5 -5
  72. package/src/device/colorbulb.ts +7 -7
  73. package/src/device/contact.ts +1 -1
  74. package/src/device/curtain.ts +1 -1
  75. package/src/device/humidifier.ts +14 -10
  76. package/src/device/lock.ts +1 -1
  77. package/src/device/meter.ts +1 -1
  78. package/src/device/meterplus.ts +1 -1
  79. package/src/device/motion.ts +18 -11
  80. package/src/device/plug.ts +2 -2
  81. package/src/device/striplight.ts +148 -127
  82. package/src/irdevice/airconditioner.ts +2 -2
  83. package/src/irdevice/airpurifier.ts +2 -2
  84. package/src/irdevice/camera.ts +2 -2
  85. package/src/irdevice/fan.ts +2 -2
  86. package/src/irdevice/light.ts +2 -2
  87. package/src/irdevice/other.ts +2 -2
  88. package/src/irdevice/tv.ts +14 -12
  89. package/src/irdevice/vacuumcleaner.ts +2 -2
  90. package/src/irdevice/waterheater.ts +2 -2
  91. package/src/settings.ts +1 -23
@@ -392,7 +392,7 @@ export class ColorBulb {
392
392
  if (this.serviceData) {
393
393
  this.connected = true;
394
394
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
395
- await this.stopScanning({ switchbot });
395
+ await this.stopScanning(switchbot);
396
396
  } else {
397
397
  this.connected = false;
398
398
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -403,7 +403,7 @@ export class ColorBulb {
403
403
  })
404
404
  .then(async () => {
405
405
  // Stop to monitor
406
- await this.stopScanning({ switchbot });
406
+ await this.stopScanning(switchbot);
407
407
  })
408
408
  .catch(async (e: any) => {
409
409
  this.apiError(e);
@@ -689,7 +689,7 @@ export class ColorBulb {
689
689
  'parameter': 'default',
690
690
  'commandType': 'command',
691
691
  });
692
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
692
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
693
693
  const options = {
694
694
  hostname: HostDomain,
695
695
  port: 443,
@@ -766,7 +766,7 @@ export class ColorBulb {
766
766
  'parameter': `${red}:${green}:${blue}`,
767
767
  'commandType': 'command',
768
768
  });
769
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
769
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
770
770
  const options = {
771
771
  hostname: HostDomain,
772
772
  port: 443,
@@ -825,7 +825,7 @@ export class ColorBulb {
825
825
  'parameter': `${kelvin}`,
826
826
  'commandType': 'command',
827
827
  });
828
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
828
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
829
829
  const options = {
830
830
  hostname: HostDomain,
831
831
  port: 443,
@@ -882,7 +882,7 @@ export class ColorBulb {
882
882
  'parameter': `${this.Brightness}`,
883
883
  'commandType': 'command',
884
884
  });
885
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
885
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
886
886
  const options = {
887
887
  hostname: HostDomain,
888
888
  port: 443,
@@ -1065,7 +1065,7 @@ export class ColorBulb {
1065
1065
  }
1066
1066
  }
1067
1067
 
1068
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
1068
+ async stopScanning(switchbot: any) {
1069
1069
  await switchbot.stopScan();
1070
1070
  if (this.connected) {
1071
1071
  await this.BLEparseStatus();
@@ -450,7 +450,7 @@ export class Contact {
450
450
  }
451
451
  }
452
452
 
453
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
453
+ async stopScanning(switchbot: any) {
454
454
  await switchbot.stopScan();
455
455
  if (this.connected) {
456
456
  await this.BLEparseStatus();
@@ -617,7 +617,7 @@ export class Curtain {
617
617
  'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
618
618
  'commandType': 'command',
619
619
  });
620
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
620
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
621
621
  const options = {
622
622
  hostname: HostDomain,
623
623
  port: 443,
@@ -484,7 +484,7 @@ export class Humidifier {
484
484
  'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
485
485
  'commandType': 'command',
486
486
  });
487
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
487
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
488
488
  const options = {
489
489
  hostname: HostDomain,
490
490
  port: 443,
@@ -552,7 +552,7 @@ export class Humidifier {
552
552
  'parameter': 'auto',
553
553
  'commandType': 'command',
554
554
  });
555
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
555
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
556
556
  const options = {
557
557
  hostname: HostDomain,
558
558
  port: 443,
@@ -613,7 +613,7 @@ export class Humidifier {
613
613
  'parameter': 'default',
614
614
  'commandType': 'command',
615
615
  });
616
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
616
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
617
617
  const options = {
618
618
  hostname: HostDomain,
619
619
  port: 443,
@@ -765,7 +765,7 @@ export class Humidifier {
765
765
  }
766
766
  }
767
767
 
768
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
768
+ async stopScanning(switchbot: any) {
769
769
  await switchbot.stopScan();
770
770
  if (this.connected) {
771
771
  await this.BLEparseStatus();
@@ -923,11 +923,15 @@ export class Humidifier {
923
923
  }
924
924
  if (this.TargetHumidifierDehumidifierState === undefined) {
925
925
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
926
+ } else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
927
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
926
928
  } else {
927
929
  this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
928
930
  }
929
931
  if (this.CurrentHumidifierDehumidifierState === undefined) {
930
932
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
933
+ } else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
934
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
931
935
  } else {
932
936
  this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
933
937
  }
@@ -1000,19 +1004,19 @@ export class Humidifier {
1000
1004
  /**
1001
1005
  * Logging for Device
1002
1006
  */
1003
- infoLog(...log: any[]): void {
1007
+ async infoLog(...log: any[]): Promise<void> {
1004
1008
  if (this.enablingDeviceLogging()) {
1005
1009
  this.platform.log.info(String(...log));
1006
1010
  }
1007
1011
  }
1008
1012
 
1009
- warnLog(...log: any[]): void {
1013
+ async warnLog(...log: any[]): Promise<void> {
1010
1014
  if (this.enablingDeviceLogging()) {
1011
1015
  this.platform.log.warn(String(...log));
1012
1016
  }
1013
1017
  }
1014
1018
 
1015
- debugWarnLog(...log: any[]): void {
1019
+ async debugWarnLog(...log: any[]): Promise<void> {
1016
1020
  if (this.enablingDeviceLogging()) {
1017
1021
  if (this.deviceLogging?.includes('debug')) {
1018
1022
  this.platform.log.warn('[DEBUG]', String(...log));
@@ -1020,13 +1024,13 @@ export class Humidifier {
1020
1024
  }
1021
1025
  }
1022
1026
 
1023
- errorLog(...log: any[]): void {
1027
+ async errorLog(...log: any[]): Promise<void> {
1024
1028
  if (this.enablingDeviceLogging()) {
1025
1029
  this.platform.log.error(String(...log));
1026
1030
  }
1027
1031
  }
1028
1032
 
1029
- debugErrorLog(...log: any[]): void {
1033
+ async debugErrorLog(...log: any[]): Promise<void> {
1030
1034
  if (this.enablingDeviceLogging()) {
1031
1035
  if (this.deviceLogging?.includes('debug')) {
1032
1036
  this.platform.log.error('[DEBUG]', String(...log));
@@ -1034,7 +1038,7 @@ export class Humidifier {
1034
1038
  }
1035
1039
  }
1036
1040
 
1037
- debugLog(...log: any[]): void {
1041
+ async debugLog(...log: any[]): Promise<void> {
1038
1042
  if (this.enablingDeviceLogging()) {
1039
1043
  if (this.deviceLogging === 'debug') {
1040
1044
  this.platform.log.info('[DEBUG]', String(...log));
@@ -408,7 +408,7 @@ export class Lock {
408
408
  'parameter': 'default',
409
409
  'commandType': 'command',
410
410
  });
411
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
411
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
412
412
  const options = {
413
413
  hostname: HostDomain,
414
414
  port: 443,
@@ -488,7 +488,7 @@ export class Meter {
488
488
  : null;
489
489
  }
490
490
 
491
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
491
+ async stopScanning(switchbot: any) {
492
492
  await switchbot.stopScan();
493
493
  if (this.connected) {
494
494
  await this.BLEparseStatus();
@@ -487,7 +487,7 @@ export class MeterPlus {
487
487
  : null;
488
488
  }
489
489
 
490
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
490
+ async stopScanning(switchbot: any) {
491
491
  await switchbot.stopScan();
492
492
  if (this.connected) {
493
493
  await this.BLEparseStatus();
@@ -44,6 +44,7 @@ export class Motion {
44
44
  led!: any;
45
45
  iot!: any;
46
46
  sense_distance!: any;
47
+ scanning!: boolean;
47
48
 
48
49
  // Config
49
50
  set_minLux!: number;
@@ -255,6 +256,7 @@ export class Motion {
255
256
  })
256
257
  .then(async () => {
257
258
  // Set an event hander
259
+ this.scanning = true;
258
260
  switchbot.onadvertisement = async (ad: any) => {
259
261
  this.address = ad.address;
260
262
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
@@ -278,6 +280,8 @@ export class Motion {
278
280
  this.connected = true;
279
281
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
280
282
  await this.stopScanning(switchbot);
283
+ this.scanning = false;
284
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
281
285
  } else {
282
286
  this.connected = false;
283
287
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -288,7 +292,10 @@ export class Motion {
288
292
  })
289
293
  .then(async () => {
290
294
  // Stop to monitor
291
- await this.stopScanning(switchbot);
295
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
296
+ if (this.scanning) {
297
+ await this.stopScanning(switchbot);
298
+ }
292
299
  })
293
300
  .catch(async (e: any) => {
294
301
  this.apiError(e);
@@ -301,6 +308,16 @@ export class Motion {
301
308
  }
302
309
  }
303
310
 
311
+ async stopScanning(switchbot: any) {
312
+ await switchbot.stopScan();
313
+ if (this.connected) {
314
+ await this.BLEparseStatus();
315
+ await this.updateHomeKitCharacteristics();
316
+ } else {
317
+ await this.BLERefreshConnection(switchbot);
318
+ }
319
+ }
320
+
304
321
  async openAPIRefreshStatus(): Promise<void> {
305
322
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
306
323
  try {
@@ -394,16 +411,6 @@ export class Motion {
394
411
  }
395
412
  }
396
413
 
397
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
398
- await await switchbot.stopScan();
399
- if (this.connected) {
400
- await this.BLEparseStatus();
401
- await this.updateHomeKitCharacteristics();
402
- } else {
403
- await this.BLERefreshConnection(switchbot);
404
- }
405
- }
406
-
407
414
  async getCustomBLEAddress(switchbot: any) {
408
415
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
409
416
  (async () => {
@@ -392,7 +392,7 @@ export class Plug {
392
392
  'parameter': 'default',
393
393
  'commandType': 'command',
394
394
  });
395
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
395
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
396
396
  const options = {
397
397
  hostname: HostDomain,
398
398
  port: 443,
@@ -458,7 +458,7 @@ export class Plug {
458
458
  }
459
459
  }
460
460
 
461
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
461
+ async stopScanning(switchbot: any) {
462
462
  await switchbot.stopScan();
463
463
  if (this.connected) {
464
464
  await this.BLEparseStatus();