@switchbot/homebridge-switchbot 2.5.3-beta.9 → 2.5.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 (76) hide show
  1. package/.github/ISSUE_TEMPLATE/bug-report.yml +7 -7
  2. package/CHANGELOG.md +13 -0
  3. package/config.schema.json +6 -2
  4. package/dist/device/blindtilt.d.ts +1 -1
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +15 -17
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +1 -1
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +12 -14
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +1 -1
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +10 -12
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +1 -1
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +16 -18
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/curtain.d.ts +1 -1
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +34 -37
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.js +2 -2
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/iosensor.d.ts +94 -0
  27. package/dist/device/iosensor.d.ts.map +1 -0
  28. package/dist/device/iosensor.js +692 -0
  29. package/dist/device/iosensor.js.map +1 -0
  30. package/dist/device/meter.js +1 -1
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.d.ts +1 -0
  33. package/dist/device/meterplus.d.ts.map +1 -1
  34. package/dist/device/meterplus.js +2 -1
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/motion.d.ts +1 -1
  37. package/dist/device/motion.d.ts.map +1 -1
  38. package/dist/device/motion.js +7 -9
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts +1 -1
  41. package/dist/device/plug.d.ts.map +1 -1
  42. package/dist/device/plug.js +10 -12
  43. package/dist/device/plug.js.map +1 -1
  44. package/dist/device/robotvacuumcleaner.d.ts +1 -1
  45. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  46. package/dist/device/robotvacuumcleaner.js +10 -12
  47. package/dist/device/robotvacuumcleaner.js.map +1 -1
  48. package/dist/device/striplight.d.ts +1 -1
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +14 -16
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airpurifier.js +1 -1
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/platform.d.ts +1 -0
  55. package/dist/platform.d.ts.map +1 -1
  56. package/dist/platform.js +58 -0
  57. package/dist/platform.js.map +1 -1
  58. package/homebridge-ui/public/index.html +1 -1
  59. package/package.json +13 -13
  60. package/src/device/blindtilt.ts +15 -17
  61. package/src/device/bot.ts +12 -14
  62. package/src/device/ceilinglight.ts +10 -12
  63. package/src/device/colorbulb.ts +16 -18
  64. package/src/device/curtain.ts +35 -39
  65. package/src/device/humidifier.ts +2 -2
  66. package/src/device/iosensor.ts +747 -0
  67. package/src/device/meter.ts +1 -1
  68. package/src/device/meterplus.ts +3 -1
  69. package/src/device/motion.ts +7 -9
  70. package/src/device/plug.ts +10 -12
  71. package/src/device/robotvacuumcleaner.ts +10 -12
  72. package/src/device/striplight.ts +14 -16
  73. package/src/irdevice/airpurifier.ts +1 -1
  74. package/src/platform.ts +61 -0
  75. package/src/settings.ts +3 -3
  76. package/.github/npm-version-script.js +0 -81
@@ -492,12 +492,12 @@ export class CeilingLight {
492
492
  .then(async (device_list: any) => {
493
493
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
494
494
  return await this.retry({
495
- max: await this.maxRetry(),
496
- fn: () => {
495
+ max: this.maxRetry(),
496
+ fn: async () => {
497
497
  if (this.On) {
498
- return device_list[0].turnOn({ id: this.device.bleMac });
498
+ return await device_list[0].turnOn({ id: this.device.bleMac });
499
499
  } else {
500
- return device_list[0].turnOff({ id: this.device.bleMac });
500
+ return await device_list[0].turnOff({ id: this.device.bleMac });
501
501
  }
502
502
  },
503
503
  });
@@ -966,25 +966,23 @@ export class CeilingLight {
966
966
  }
967
967
 
968
968
  async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
969
- return fn().catch(async (err: any) => {
969
+ return fn().catch(async (e: any) => {
970
970
  if (max === 0) {
971
- throw err;
971
+ throw e;
972
972
  }
973
- this.infoLog(err);
973
+ this.infoLog(e);
974
974
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
975
975
  await sleep(1000);
976
976
  return this.retry({ max: max - 1, fn });
977
977
  });
978
978
  }
979
979
 
980
- async maxRetry(): Promise<number> {
981
- let maxRetry: number;
980
+ maxRetry(): number {
982
981
  if (this.device.maxRetry) {
983
- maxRetry = this.device.maxRetry;
982
+ return this.device.maxRetry;
984
983
  } else {
985
- maxRetry = 5;
984
+ return 5;
986
985
  }
987
- return maxRetry;
988
986
  }
989
987
 
990
988
  minStep(device: device & devicesConfig): number {
@@ -527,12 +527,12 @@ export class ColorBulb {
527
527
  .then(async (device_list: any) => {
528
528
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
529
529
  return await this.retry({
530
- max: await this.maxRetry(),
531
- fn: () => {
530
+ max: this.maxRetry(),
531
+ fn: async () => {
532
532
  if (this.On) {
533
- return device_list[0].turnOn({ id: this.device.bleMac });
533
+ return await device_list[0].turnOn({ id: this.device.bleMac });
534
534
  } else {
535
- return device_list[0].turnOff({ id: this.device.bleMac });
535
+ return await device_list[0].turnOff({ id: this.device.bleMac });
536
536
  }
537
537
  },
538
538
  });
@@ -580,9 +580,9 @@ export class ColorBulb {
580
580
  model: 'u',
581
581
  id: this.device.bleMac,
582
582
  })
583
- .then((device_list: any) => {
583
+ .then(async (device_list: any) => {
584
584
  this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
585
- return device_list[0].setBrightness(this.Brightness);
585
+ return await device_list[0].setBrightness(this.Brightness);
586
586
  })
587
587
  .then(() => {
588
588
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
@@ -615,9 +615,9 @@ export class ColorBulb {
615
615
  model: 'u',
616
616
  id: this.device.bleMac,
617
617
  })
618
- .then((device_list: any) => {
618
+ .then(async (device_list: any) => {
619
619
  this.infoLog(`${this.accessory.displayName} Target ColorTemperature: ${this.ColorTemperature}`);
620
- return device_list[0].setColorTemperature(this.ColorTemperature);
620
+ return await device_list[0].setColorTemperature(this.ColorTemperature);
621
621
  })
622
622
  .then(() => {
623
623
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
@@ -657,9 +657,9 @@ export class ColorBulb {
657
657
  model: 'u',
658
658
  id: this.device.bleMac,
659
659
  })
660
- .then((device_list: any) => {
660
+ .then(async (device_list: any) => {
661
661
  this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
662
- return device_list[0].setRGB(this.Brightness, red, green, blue);
662
+ return await device_list[0].setRGB(this.Brightness, red, green, blue);
663
663
  })
664
664
  .then(() => {
665
665
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
@@ -1123,25 +1123,23 @@ export class ColorBulb {
1123
1123
  }
1124
1124
 
1125
1125
  async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
1126
- return fn().catch(async (err: any) => {
1126
+ return fn().catch(async (e: any) => {
1127
1127
  if (max === 0) {
1128
- throw err;
1128
+ throw e;
1129
1129
  }
1130
- this.infoLog(err);
1130
+ this.infoLog(e);
1131
1131
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
1132
1132
  await sleep(1000);
1133
1133
  return this.retry({ max: max - 1, fn });
1134
1134
  });
1135
1135
  }
1136
1136
 
1137
- async maxRetry(): Promise<number> {
1138
- let maxRetry: number;
1137
+ maxRetry(): number {
1139
1138
  if (this.device.maxRetry) {
1140
- maxRetry = this.device.maxRetry;
1139
+ return this.device.maxRetry;
1141
1140
  } else {
1142
- maxRetry = 5;
1141
+ return 5;
1143
1142
  }
1144
- return maxRetry;
1145
1143
  }
1146
1144
 
1147
1145
  minStep(device: device & devicesConfig): number {
@@ -248,16 +248,13 @@ export class Curtain {
248
248
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
249
249
  if (this.setNewTarget) {
250
250
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
251
- }
252
-
253
- if (this.setNewTarget && this.inMotion) {
254
251
  await this.setMinMax();
255
- if (this.TargetPosition > this.CurrentPosition) {
252
+ if (Number(this.TargetPosition) > this.CurrentPosition) {
256
253
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
257
254
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
258
255
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
259
256
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
260
- } else if (this.TargetPosition < this.CurrentPosition) {
257
+ } else if (Number(this.TargetPosition) < this.CurrentPosition) {
261
258
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
262
259
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
263
260
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
@@ -358,12 +355,12 @@ export class Curtain {
358
355
 
359
356
  if (this.setNewTarget && this.moving) {
360
357
  await this.setMinMax();
361
- if (this.TargetPosition > this.CurrentPosition) {
358
+ if (Number(this.TargetPosition) > this.CurrentPosition) {
362
359
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
363
360
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
364
361
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
365
362
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
366
- } else if (this.TargetPosition < this.CurrentPosition) {
363
+ } else if (Number(this.TargetPosition) < this.CurrentPosition) {
367
364
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
368
365
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
369
366
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
@@ -569,26 +566,27 @@ export class Curtain {
569
566
  }
570
567
  this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
571
568
  if (switchbot !== false) {
572
- switchbot
573
- .discover({ model: 'c', quick: true, id: this.device.bleMac })
574
- .then(async (device_list: any) => {
575
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
576
- return await this.retry({
577
- max: await this.maxRetry(),
578
- fn: () => {
579
- return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
580
- },
581
- });
582
- })
583
- .then(() => {
584
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
585
- })
586
- .catch(async (e: any) => {
587
- this.apiError(e);
588
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
589
- + ` Connection, Error Message: ${superStringify(e.message)}`);
590
- await this.BLEPushConnection();
591
- });
569
+ await this.retry({
570
+ max: this.maxRetry(),
571
+ fn: () => {
572
+ return switchbot
573
+ .discover({ model: 'c', quick: true, id: this.device.bleMac })
574
+ .then(async (device_list: any) => {
575
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
576
+ return await device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
577
+ })
578
+ .then(() => {
579
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
580
+ })
581
+ .catch(async (e: any) => {
582
+ this.apiError(e);
583
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
584
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
585
+ await this.BLEPushConnection();
586
+ throw new Error('Connection error');
587
+ });
588
+ },
589
+ });
592
590
  } else {
593
591
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
594
592
  await this.BLEPushConnection();
@@ -601,25 +599,23 @@ export class Curtain {
601
599
  }
602
600
 
603
601
  async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
604
- return fn().catch(async (err: any) => {
602
+ return fn().catch(async (e: any) => {
605
603
  if (max === 0) {
606
- throw err;
604
+ throw e;
607
605
  }
608
- this.infoLog(err);
606
+ this.infoLog(e);
609
607
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
610
608
  await sleep(1000);
611
609
  return this.retry({ max: max - 1, fn });
612
610
  });
613
611
  }
614
612
 
615
- async maxRetry(): Promise<number> {
616
- let maxRetry: number;
613
+ maxRetry(): number {
617
614
  if (this.device.maxRetry) {
618
- maxRetry = this.device.maxRetry;
615
+ return this.device.maxRetry;
619
616
  } else {
620
- maxRetry = 5;
617
+ return 5;
621
618
  }
622
- return maxRetry;
623
619
  }
624
620
 
625
621
  async openAPIpushChanges(): Promise<void> {
@@ -637,7 +633,7 @@ export class Curtain {
637
633
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
638
634
  this.debugLog(`Pushing ${this.TargetPosition}`);
639
635
  const adjustedTargetPosition = 100 - Number(this.TargetPosition);
640
- if (this.TargetPosition > 50) {
636
+ if (Number(this.TargetPosition) > 50) {
641
637
  this.setPositionMode = this.device.curtain?.setOpenMode;
642
638
  } else {
643
639
  this.setPositionMode = this.device.curtain?.setCloseMode;
@@ -889,7 +885,7 @@ export class Curtain {
889
885
  }
890
886
 
891
887
  async SilentPerformance() {
892
- if (this.TargetPosition > 50) {
888
+ if (Number(this.TargetPosition) > 50) {
893
889
  if (this.device.curtain?.setOpenMode === '1') {
894
890
  this.setPositionMode = 1;
895
891
  this.Mode = 'Silent Mode';
@@ -910,12 +906,12 @@ export class Curtain {
910
906
 
911
907
  async setMinMax(): Promise<void> {
912
908
  if (this.device.curtain?.set_min) {
913
- if (this.CurrentPosition <= this.device.curtain?.set_min) {
909
+ if (Number(this.CurrentPosition) <= this.device.curtain?.set_min) {
914
910
  this.CurrentPosition = 0;
915
911
  }
916
912
  }
917
913
  if (this.device.curtain?.set_max) {
918
- if (this.CurrentPosition >= this.device.curtain?.set_max) {
914
+ if (Number(this.CurrentPosition) >= this.device.curtain?.set_max) {
919
915
  this.CurrentPosition = 100;
920
916
  }
921
917
  }
@@ -455,9 +455,9 @@ export class Humidifier {
455
455
  quick: true,
456
456
  id: this.device.bleMac,
457
457
  })
458
- .then((device_list: any) => {
458
+ .then(async (device_list: any) => {
459
459
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
460
- return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
460
+ return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
461
461
  })
462
462
  .then(() => {
463
463
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);