@switchbot/homebridge-switchbot 2.4.0 → 2.4.1-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 (44) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/CHANGELOG.md +9 -0
  3. package/dist/device/bot.d.ts +1 -2
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +4 -4
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts +1 -2
  8. package/dist/device/ceilinglight.d.ts.map +1 -1
  9. package/dist/device/ceilinglight.js +4 -4
  10. package/dist/device/ceilinglight.js.map +1 -1
  11. package/dist/device/colorbulb.d.ts +1 -2
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +4 -4
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/curtain.d.ts +1 -2
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +4 -4
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/plug.d.ts +1 -2
  20. package/dist/device/plug.d.ts.map +1 -1
  21. package/dist/device/plug.js +4 -4
  22. package/dist/device/plug.js.map +1 -1
  23. package/dist/device/robotvacuumcleaner.d.ts +1 -2
  24. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  25. package/dist/device/robotvacuumcleaner.js +4 -4
  26. package/dist/device/robotvacuumcleaner.js.map +1 -1
  27. package/dist/device/striplight.d.ts +1 -2
  28. package/dist/device/striplight.d.ts.map +1 -1
  29. package/dist/device/striplight.js +4 -4
  30. package/dist/device/striplight.js.map +1 -1
  31. package/dist/utils.d.ts +2 -0
  32. package/dist/utils.d.ts.map +1 -0
  33. package/dist/utils.js +8 -0
  34. package/dist/utils.js.map +1 -0
  35. package/homebridge-ui/public/index.html +1 -1
  36. package/package.json +2 -2
  37. package/src/device/bot.ts +4 -4
  38. package/src/device/ceilinglight.ts +4 -4
  39. package/src/device/colorbulb.ts +4 -4
  40. package/src/device/curtain.ts +4 -4
  41. package/src/device/plug.ts +4 -4
  42. package/src/device/robotvacuumcleaner.ts +4 -4
  43. package/src/device/striplight.ts +4 -4
  44. package/src/utils.ts +3 -0
@@ -10,6 +10,7 @@ import { SwitchBotPlatform } from '../platform';
10
10
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
11
11
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
12
12
  import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
13
+ import { sleep } from '../utils';
13
14
 
14
15
  export class Curtain {
15
16
  // Services
@@ -572,7 +573,6 @@ export class Curtain {
572
573
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
573
574
  return await this.retry({
574
575
  max: await this.maxRetry(),
575
- switchbot,
576
576
  fn: () => {
577
577
  return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
578
578
  },
@@ -598,15 +598,15 @@ export class Curtain {
598
598
  }
599
599
  }
600
600
 
601
- async retry({ max, switchbot, fn }: { max: number; switchbot: any, fn: { (): any; (): Promise<any> } }): Promise<null> {
601
+ async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
602
602
  return fn().catch(async (err: any) => {
603
603
  if (max === 0) {
604
604
  throw err;
605
605
  }
606
606
  this.infoLog(err);
607
607
  this.infoLog('Retrying');
608
- await switchbot.wait(1000);
609
- return this.retry({ max: max - 1, switchbot, fn });
608
+ await sleep(1000);
609
+ return this.retry({ max: max - 1, fn });
610
610
  });
611
611
  }
612
612
 
@@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
8
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
9
9
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
10
10
  import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot, HostDomain, DevicePath } from '../settings';
11
+ import { sleep } from '../utils';
11
12
 
12
13
  export class Plug {
13
14
  // Services
@@ -351,7 +352,6 @@ export class Plug {
351
352
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
352
353
  return await this.retry({
353
354
  max: await this.maxRetry(),
354
- switchbot,
355
355
  fn: () => {
356
356
  if (this.On) {
357
357
  return device_list[0].turnOn({ id: this.device.bleMac });
@@ -521,15 +521,15 @@ export class Plug {
521
521
  }
522
522
  }
523
523
 
524
- async retry({ max, switchbot, fn }: { max: number; switchbot: any, fn: { (): any; (): Promise<any> } }): Promise<null> {
524
+ async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
525
525
  return fn().catch(async (err: any) => {
526
526
  if (max === 0) {
527
527
  throw err;
528
528
  }
529
529
  this.infoLog(err);
530
530
  this.infoLog('Retrying');
531
- await switchbot.wait(1000);
532
- return this.retry({ max: max - 1, switchbot, fn });
531
+ await sleep(1000);
532
+ return this.retry({ max: max - 1, fn });
533
533
  });
534
534
  }
535
535
 
@@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
8
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
9
9
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
10
10
  import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot, HostDomain, DevicePath } from '../settings';
11
+ import { sleep } from '../utils';
11
12
 
12
13
  export class RobotVacuumCleaner {
13
14
  // Services
@@ -362,7 +363,6 @@ export class RobotVacuumCleaner {
362
363
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
363
364
  return await this.retry({
364
365
  max: await this.maxRetry(),
365
- switchbot,
366
366
  fn: () => {
367
367
  if (this.On) {
368
368
  return device_list[0].turnOn({ id: this.device.bleMac });
@@ -645,15 +645,15 @@ export class RobotVacuumCleaner {
645
645
  }
646
646
  }
647
647
 
648
- async retry({ max, switchbot, fn }: { max: number; switchbot: any, fn: { (): any; (): Promise<any> } }): Promise<null> {
648
+ async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
649
649
  return fn().catch(async (err: any) => {
650
650
  if (max === 0) {
651
651
  throw err;
652
652
  }
653
653
  this.infoLog(err);
654
654
  this.infoLog('Retrying');
655
- await switchbot.wait(1000);
656
- return this.retry({ max: max - 1, switchbot, fn });
655
+ await sleep(1000);
656
+ return this.retry({ max: max - 1, fn });
657
657
  });
658
658
  }
659
659
 
@@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
8
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
9
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
10
  import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData, m2hs } from '../settings';
11
+ import { sleep } from '../utils';
11
12
 
12
13
  /**
13
14
  * Platform Accessory
@@ -467,7 +468,6 @@ export class StripLight {
467
468
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
468
469
  return await this.retry({
469
470
  max: await this.maxRetry(),
470
- switchbot,
471
471
  fn: () => {
472
472
  if (this.On) {
473
473
  return device_list[0].turnOn({ id: this.device.bleMac });
@@ -886,15 +886,15 @@ export class StripLight {
886
886
  }
887
887
  }
888
888
 
889
- async retry({ max, switchbot, fn }: { max: number; switchbot: any, fn: { (): any; (): Promise<any> } }): Promise<null> {
889
+ async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
890
890
  return fn().catch(async (err: any) => {
891
891
  if (max === 0) {
892
892
  throw err;
893
893
  }
894
894
  this.infoLog(err);
895
895
  this.infoLog('Retrying');
896
- await switchbot.wait(1000);
897
- return this.retry({ max: max - 1, switchbot, fn });
896
+ await sleep(1000);
897
+ return this.retry({ max: max - 1, fn });
898
898
  });
899
899
  }
900
900
 
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function sleep(ms: number): Promise<void> {
2
+ return new Promise(resolve => setTimeout(resolve, ms));
3
+ }