@switchbot/homebridge-switchbot 1.10.2-beta.8 → 1.12.0

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 (99) hide show
  1. package/CHANGELOG.md +27 -3
  2. package/config.schema.json +58 -0
  3. package/dist/device/bot.d.ts +51 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +58 -32
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +176 -140
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +38 -38
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +14 -14
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -11
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +14 -14
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +13 -13
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +17 -17
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/irdevice/airconditioner.d.ts +22 -22
  40. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  41. package/dist/irdevice/airconditioner.js +44 -44
  42. package/dist/irdevice/airconditioner.js.map +1 -1
  43. package/dist/irdevice/airpurifier.d.ts +12 -9
  44. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  45. package/dist/irdevice/airpurifier.js +20 -20
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.d.ts +10 -7
  48. package/dist/irdevice/camera.d.ts.map +1 -1
  49. package/dist/irdevice/camera.js +11 -11
  50. package/dist/irdevice/camera.js.map +1 -1
  51. package/dist/irdevice/fan.d.ts +12 -9
  52. package/dist/irdevice/fan.d.ts.map +1 -1
  53. package/dist/irdevice/fan.js +29 -29
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/light.d.ts +10 -7
  56. package/dist/irdevice/light.d.ts.map +1 -1
  57. package/dist/irdevice/light.js +13 -13
  58. package/dist/irdevice/light.js.map +1 -1
  59. package/dist/irdevice/other.d.ts +12 -9
  60. package/dist/irdevice/other.d.ts.map +1 -1
  61. package/dist/irdevice/other.js +17 -17
  62. package/dist/irdevice/other.js.map +1 -1
  63. package/dist/irdevice/tv.d.ts +13 -10
  64. package/dist/irdevice/tv.d.ts.map +1 -1
  65. package/dist/irdevice/tv.js +25 -25
  66. package/dist/irdevice/tv.js.map +1 -1
  67. package/dist/irdevice/vacuumcleaner.d.ts +10 -7
  68. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  69. package/dist/irdevice/vacuumcleaner.js +13 -13
  70. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  71. package/dist/irdevice/waterheater.d.ts +10 -7
  72. package/dist/irdevice/waterheater.d.ts.map +1 -1
  73. package/dist/irdevice/waterheater.js +16 -16
  74. package/dist/irdevice/waterheater.js.map +1 -1
  75. package/dist/platform.d.ts.map +1 -1
  76. package/dist/settings.d.ts +5 -1
  77. package/dist/settings.d.ts.map +1 -1
  78. package/dist/settings.js.map +1 -1
  79. package/package.json +76 -76
  80. package/src/device/bot.ts +82 -55
  81. package/src/device/colorbulb.ts +206 -157
  82. package/src/device/contact.ts +31 -30
  83. package/src/device/curtain.ts +68 -57
  84. package/src/device/humidifier.ts +65 -53
  85. package/src/device/lock.ts +22 -22
  86. package/src/device/meter.ts +25 -25
  87. package/src/device/motion.ts +27 -27
  88. package/src/device/plug.ts +20 -20
  89. package/src/irdevice/airconditioner.ts +54 -54
  90. package/src/irdevice/airpurifier.ts +30 -30
  91. package/src/irdevice/camera.ts +19 -19
  92. package/src/irdevice/fan.ts +40 -40
  93. package/src/irdevice/light.ts +23 -23
  94. package/src/irdevice/other.ts +25 -25
  95. package/src/irdevice/tv.ts +42 -42
  96. package/src/irdevice/vacuumcleaner.ts +21 -21
  97. package/src/irdevice/waterheater.ts +24 -24
  98. package/src/platform.ts +4 -4
  99. package/src/settings.ts +6 -1
package/CHANGELOG.md CHANGED
@@ -2,10 +2,34 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
4
4
 
5
- ## [Beta - Version 1.10.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.10.1) (2022-01-28)
5
+ ## [Version 1.12.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.0) (2022-01-29)
6
6
 
7
7
  ## What's Changed
8
- * Add Support for SwitchBot Lock
8
+ * Add option `maxRetry` for bots so you can set the number of retries for sending on or off for Bot.
9
+
10
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.2...v1.12.0
11
+
12
+ ## [Version 1.11.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.2) (2022-01-29)
13
+
14
+ ## What's Changed
15
+ * Fix: Use `updateRate` instead of `refreshRate` when overriding `scanDuration`.
16
+
17
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.1...v1.11.2
18
+
19
+ ## [Version 1.11.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.1) (2022-01-29)
20
+
21
+ ## What's Changed
22
+ * Fix: `This plugin generated a warning from the characteristic 'Brightness': characteristic value expected valid finite number and received "undefined" (undefined)`.
23
+ * Fix: `This plugin generated a warning from the characteristic 'Color Temperature': characteristic value expected valid finite number and received "undefined" (undefined)`.
24
+ * Fix: `This plugin generated a warning from the characteristic 'Hue': characteristic value expected valid finite number and received "undefined" (undefined)`.
25
+ * Fix: `This plugin generated a warning from the characteristic 'Saturation': characteristic value expected valid finite number and received "undefined" (undefined)`.
26
+
27
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.0...v1.11.1
28
+
29
+ ## [Version 1.11.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.0) (2022-01-29)
30
+
31
+ ## What's Changed
32
+ * Add Support for SwitchBot Smart Lock
9
33
  * Add Support for SwitchBot Strip Light
10
34
  * Add Support for SwitchBot Meter Plus (US)
11
35
  * Add Support for SwitchBot Meter Plus (JP)
@@ -14,7 +38,7 @@ All notable changes to this project will be documented in this file. This projec
14
38
  * Fixed: Curtain `set_min` and `set_max` options not work correctly with minimum and maximum curtain state. [#123](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/123)
15
39
  * Housekeeping and updated dependencies.
16
40
 
17
- **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.10.1...v1.10.2
41
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.10.1...v1.11.0
18
42
 
19
43
  ## [Version 1.10.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.10.1) (2022-01-26)
20
44
 
@@ -128,6 +128,42 @@
128
128
  "enum": [
129
129
  "Smart Fan"
130
130
  ]
131
+ },
132
+ {
133
+ "title": "Smart Lock",
134
+ "enum": [
135
+ "Smart Lock"
136
+ ]
137
+ },
138
+ {
139
+ "title": "Strip Light",
140
+ "enum": [
141
+ "Strip Light"
142
+ ]
143
+ },
144
+ {
145
+ "title": "Meter Plus (US)",
146
+ "enum": [
147
+ "Meter Plus (US)"
148
+ ]
149
+ },
150
+ {
151
+ "title": "Meter Plus (JP)",
152
+ "enum": [
153
+ "Meter Plus (JP)"
154
+ ]
155
+ },
156
+ {
157
+ "title": "Plug Mini (US)",
158
+ "enum": [
159
+ "Plug Mini (US)"
160
+ ]
161
+ },
162
+ {
163
+ "title": "Plug Mini (JP)",
164
+ "enum": [
165
+ "Plug Mini (JP)"
166
+ ]
131
167
  }
132
168
  ],
133
169
  "condition": {
@@ -258,6 +294,14 @@
258
294
  "condition": {
259
295
  "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);"
260
296
  }
297
+ },
298
+ "maxRetry": {
299
+ "title": "Max Retries",
300
+ "type": "number",
301
+ "placeholder": "5",
302
+ "condition": {
303
+ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);"
304
+ }
261
305
  }
262
306
  }
263
307
  },
@@ -457,6 +501,18 @@
457
501
  }
458
502
  }
459
503
  },
504
+ "lock": {
505
+ "type": "object",
506
+ "properties": {
507
+ "hide_contactsensor": {
508
+ "title": "Hide Lock's Contact Sensor",
509
+ "type": "boolean",
510
+ "condition": {
511
+ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Smart Lock' && model.options.devices[arrayIndices].deviceId);"
512
+ }
513
+ }
514
+ }
515
+ },
460
516
  "refreshRate": {
461
517
  "title": "Device Refresh Rate",
462
518
  "type": "number",
@@ -917,6 +973,7 @@
917
973
  "options.devices[].bot.deviceType",
918
974
  "options.devices[].bot.allowPush",
919
975
  "options.devices[].bot.doublePress",
976
+ "options.devices[].bot.maxRetry",
920
977
  "options.devices[].meter.hide_temperature",
921
978
  "options.devices[].meter.hide_humidity",
922
979
  "options.devices[].humidifier.set_minStep",
@@ -938,6 +995,7 @@
938
995
  "options.devices[].motion.set_maxlux",
939
996
  "options.devices[].colorbulb.set_minStep",
940
997
  "options.devices[].colorbulb.adaptiveLightingShift",
998
+ "options.devices[].lock.hide_contactsensor",
941
999
  "options.devices[].refreshRate",
942
1000
  "options.devices[].logging"
943
1001
  ]
@@ -1,6 +1,7 @@
1
+ import { AxiosResponse } from 'axios';
1
2
  import { Subject } from 'rxjs';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { PlatformAccessory, CharacteristicValue } from 'homebridge';
4
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
4
5
  import { device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
5
6
  /**
6
7
  * Platform Accessory
@@ -11,17 +12,17 @@ export declare class Bot {
11
12
  private readonly platform;
12
13
  private accessory;
13
14
  device: device & devicesConfig;
14
- private fanService?;
15
- private doorService?;
16
- private lockService?;
17
- private faucetService?;
18
- private windowService?;
19
- private switchService?;
20
- private outletService?;
21
- private batteryService?;
22
- private garageDoorService?;
23
- private windowCoveringService?;
24
- private statefulProgrammableSwitchService?;
15
+ fanService?: Service;
16
+ doorService?: Service;
17
+ lockService?: Service;
18
+ faucetService?: Service;
19
+ windowService?: Service;
20
+ switchService?: Service;
21
+ outletService?: Service;
22
+ batteryService?: Service;
23
+ garageDoorService?: Service;
24
+ windowCoveringService?: Service;
25
+ statefulProgrammableSwitchService?: Service;
25
26
  On: CharacteristicValue;
26
27
  OnCached: CharacteristicValue;
27
28
  BatteryLevel: CharacteristicValue;
@@ -48,14 +49,14 @@ export declare class Bot {
48
49
  * Parse the device status from the SwitchBot api
49
50
  */
50
51
  parseStatus(): Promise<void>;
51
- private BLEparseStatus;
52
- private openAPIparseStatus;
52
+ BLEparseStatus(): Promise<void>;
53
+ openAPIparseStatus(): Promise<void>;
53
54
  /**
54
55
  * Asks the SwitchBot API for the latest device information
55
56
  */
56
57
  refreshStatus(): Promise<void>;
57
- private BLERefreshStatus;
58
- private openAPIRefreshStatus;
58
+ BLERefreshStatus(): Promise<void>;
59
+ openAPIRefreshStatus(): Promise<void>;
59
60
  /**
60
61
  * Pushes the requested changes to the SwitchBot API
61
62
  * deviceType commandType Command command parameter Description
@@ -64,36 +65,46 @@ export declare class Bot {
64
65
  * Bot - "command" "press" "default" = trigger press
65
66
  */
66
67
  pushChanges(): Promise<void>;
67
- private BLEpushChanges;
68
- private turnOnOff;
69
- private openAPIpushChanges;
68
+ BLEpushChanges(): Promise<void>;
69
+ turnOnOff(device_list: any): Promise<any>;
70
+ openAPIpushChanges(): Promise<void>;
70
71
  /**
71
72
  * Updates the status for each of the HomeKit Characteristics
72
73
  */
73
- updateHomeKitCharacteristics(): void;
74
- apiError(e: any): void;
75
- private statusCode;
76
- offlineOff(): void;
74
+ updateHomeKitCharacteristics(): Promise<void>;
75
+ apiError(e: any): Promise<void>;
76
+ statusCode(push: AxiosResponse<{
77
+ statusCode: number;
78
+ }>): Promise<void>;
79
+ offlineOff(): Promise<void>;
77
80
  /**
78
81
  * Handle requests to set the "On" characteristic
79
82
  */
80
- handleOnSet(value: CharacteristicValue): void;
81
- config(device: device & devicesConfig): void;
82
- refreshRate(device: device & devicesConfig): void;
83
- scan(device: device & devicesConfig): void;
84
- logs(device: device & devicesConfig): void;
85
- PressOrSwitch(device: device & devicesConfig): void;
86
- allowPushChanges(device: device & devicesConfig): void;
87
- removeOutletService(accessory: PlatformAccessory): void;
88
- removeGarageDoorService(accessory: PlatformAccessory): void;
89
- removeDoorService(accessory: PlatformAccessory): void;
90
- removeLockService(accessory: PlatformAccessory): void;
91
- removeFaucetService(accessory: PlatformAccessory): void;
92
- removeFanService(accessory: PlatformAccessory): void;
93
- removeWindowService(accessory: PlatformAccessory): void;
94
- removeWindowCoveringService(accessory: PlatformAccessory): void;
95
- removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): void;
96
- removeSwitchService(accessory: PlatformAccessory): void;
83
+ handleOnSet(value: CharacteristicValue): Promise<void>;
84
+ retry({ max, fn }: {
85
+ max: number;
86
+ fn: {
87
+ (): any;
88
+ (): Promise<any>;
89
+ };
90
+ }): Promise<null>;
91
+ maxRetry(): Promise<number>;
92
+ config(device: device & devicesConfig): Promise<void>;
93
+ refreshRate(device: device & devicesConfig): Promise<void>;
94
+ scan(device: device & devicesConfig): Promise<void>;
95
+ logs(device: device & devicesConfig): Promise<void>;
96
+ PressOrSwitch(device: device & devicesConfig): Promise<void>;
97
+ allowPushChanges(device: device & devicesConfig): Promise<void>;
98
+ removeOutletService(accessory: PlatformAccessory): Promise<void>;
99
+ removeGarageDoorService(accessory: PlatformAccessory): Promise<void>;
100
+ removeDoorService(accessory: PlatformAccessory): Promise<void>;
101
+ removeLockService(accessory: PlatformAccessory): Promise<void>;
102
+ removeFaucetService(accessory: PlatformAccessory): Promise<void>;
103
+ removeFanService(accessory: PlatformAccessory): Promise<void>;
104
+ removeWindowService(accessory: PlatformAccessory): Promise<void>;
105
+ removeWindowCoveringService(accessory: PlatformAccessory): Promise<void>;
106
+ removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void>;
107
+ removeSwitchService(accessory: PlatformAccessory): Promise<void>;
97
108
  /**
98
109
  * Logging for Device
99
110
  */
@@ -1 +1 @@
1
- {"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../../src/device/bot.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAW,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAa,MAAM,EAAE,aAAa,EAAE,WAAW,EAAM,SAAS,EAAE,oBAAoB,EAAW,Y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,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/D,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,iBAAiB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D,iBAAiB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,2BAA2B,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASxE,uCAAuC,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASpF,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAStE;;OAEG;IACH,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAU7B,qBAAqB,IAAI,OAAO;CAGjC"}
@@ -274,8 +274,8 @@ class Bot {
274
274
  // Start an update interval
275
275
  (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
276
276
  .pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
277
- .subscribe(() => {
278
- this.refreshStatus();
277
+ .subscribe(async () => {
278
+ await this.refreshStatus();
279
279
  });
280
280
  // Watch for Bot change events
281
281
  // We put in a debounce of 100ms so we don't make duplicate calls
@@ -495,8 +495,8 @@ class Bot {
495
495
  (0, rxjs_1.interval)(5000)
496
496
  .pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
497
497
  .pipe((0, operators_1.take)(1))
498
- .subscribe(() => {
499
- this.refreshStatus();
498
+ .subscribe(async () => {
499
+ await this.refreshStatus();
500
500
  });
501
501
  }
502
502
  async BLEpushChanges() {
@@ -591,13 +591,18 @@ class Bot {
591
591
  this.OnCached = this.On;
592
592
  this.accessory.context.On = this.OnCached;
593
593
  }
594
- turnOnOff(device_list) {
595
- if (this.On) {
596
- return device_list[0].turnOn({ id: this.device.bleMac });
597
- }
598
- else {
599
- return device_list[0].turnOff({ id: this.device.bleMac });
600
- }
594
+ async turnOnOff(device_list) {
595
+ return await this.retry({
596
+ max: await this.maxRetry(),
597
+ fn: () => {
598
+ if (this.On) {
599
+ return device_list[0].turnOn({ id: this.device.bleMac });
600
+ }
601
+ else {
602
+ return device_list[0].turnOff({ id: this.device.bleMac });
603
+ }
604
+ },
605
+ });
601
606
  }
602
607
  async openAPIpushChanges() {
603
608
  if (this.platform.config.credentials?.openToken) {
@@ -651,7 +656,7 @@ class Bot {
651
656
  /**
652
657
  * Updates the status for each of the HomeKit Characteristics
653
658
  */
654
- updateHomeKitCharacteristics() {
659
+ async updateHomeKitCharacteristics() {
655
660
  if (this.device.bot?.deviceType === 'garagedoor') {
656
661
  if (this.On === undefined) {
657
662
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
@@ -833,7 +838,7 @@ class Bot {
833
838
  }
834
839
  }
835
840
  }
836
- apiError(e) {
841
+ async apiError(e) {
837
842
  if (this.device.bot?.deviceType === 'garagedoor') {
838
843
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
839
844
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
@@ -880,7 +885,7 @@ class Bot {
880
885
  }
881
886
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
882
887
  }
883
- statusCode(push) {
888
+ async statusCode(push) {
884
889
  switch (push.data.statusCode) {
885
890
  case 151:
886
891
  this.errorLog(`Bot: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -910,7 +915,7 @@ class Bot {
910
915
  this.debugLog(`Bot: ${this.accessory.displayName} Unknown statusCode.`);
911
916
  }
912
917
  }
913
- offlineOff() {
918
+ async offlineOff() {
914
919
  if (this.device.offline) {
915
920
  this.On = false;
916
921
  if (this.device.bot?.deviceType === 'switch') {
@@ -924,7 +929,7 @@ class Bot {
924
929
  /**
925
930
  * Handle requests to set the "On" characteristic
926
931
  */
927
- handleOnSet(value) {
932
+ async handleOnSet(value) {
928
933
  if (this.device.bot?.deviceType === 'garagedoor') {
929
934
  this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
930
935
  if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
@@ -978,7 +983,28 @@ class Bot {
978
983
  }
979
984
  this.doBotUpdate.next();
980
985
  }
981
- config(device) {
986
+ async retry({ max, fn }) {
987
+ return fn().catch(async (err) => {
988
+ if (max === 0) {
989
+ throw err;
990
+ }
991
+ this.infoLog(err);
992
+ this.infoLog('Retrying');
993
+ await this.switchbot.wait(1000);
994
+ return this.retry({ max: max - 1, fn });
995
+ });
996
+ }
997
+ async maxRetry() {
998
+ let maxRetry;
999
+ if (this.device.bot?.maxRetry) {
1000
+ maxRetry = this.device.bot?.maxRetry;
1001
+ }
1002
+ else {
1003
+ maxRetry = 5;
1004
+ }
1005
+ return maxRetry;
1006
+ }
1007
+ async config(device) {
982
1008
  let config = {};
983
1009
  if (device.bot) {
984
1010
  config = device.bot;
@@ -1002,7 +1028,7 @@ class Bot {
1002
1028
  this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1003
1029
  }
1004
1030
  }
1005
- refreshRate(device) {
1031
+ async refreshRate(device) {
1006
1032
  if (device.refreshRate) {
1007
1033
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1008
1034
  this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -1012,7 +1038,7 @@ class Bot {
1012
1038
  this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
1013
1039
  }
1014
1040
  }
1015
- scan(device) {
1041
+ async scan(device) {
1016
1042
  if (device.scanDuration) {
1017
1043
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
1018
1044
  if (device.ble) {
@@ -1026,7 +1052,7 @@ class Bot {
1026
1052
  }
1027
1053
  }
1028
1054
  }
1029
- logs(device) {
1055
+ async logs(device) {
1030
1056
  if (this.platform.debugMode) {
1031
1057
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
1032
1058
  this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1044,7 +1070,7 @@ class Bot {
1044
1070
  this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
1045
1071
  }
1046
1072
  }
1047
- PressOrSwitch(device) {
1073
+ async PressOrSwitch(device) {
1048
1074
  if (!device.bot?.mode) {
1049
1075
  this.botMode = 'switch';
1050
1076
  this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
@@ -1062,7 +1088,7 @@ class Bot {
1062
1088
  throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1063
1089
  }
1064
1090
  }
1065
- allowPushChanges(device) {
1091
+ async allowPushChanges(device) {
1066
1092
  if (device.bot?.allowPush) {
1067
1093
  this.allowPush = true;
1068
1094
  }
@@ -1071,7 +1097,7 @@ class Bot {
1071
1097
  }
1072
1098
  this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1073
1099
  }
1074
- removeOutletService(accessory) {
1100
+ async removeOutletService(accessory) {
1075
1101
  // If outletService still pressent, then remove first
1076
1102
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
1077
1103
  if (this.outletService) {
@@ -1079,7 +1105,7 @@ class Bot {
1079
1105
  }
1080
1106
  accessory.removeService(this.outletService);
1081
1107
  }
1082
- removeGarageDoorService(accessory) {
1108
+ async removeGarageDoorService(accessory) {
1083
1109
  // If garageDoorService still pressent, then remove first
1084
1110
  this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
1085
1111
  if (this.garageDoorService) {
@@ -1087,7 +1113,7 @@ class Bot {
1087
1113
  }
1088
1114
  accessory.removeService(this.garageDoorService);
1089
1115
  }
1090
- removeDoorService(accessory) {
1116
+ async removeDoorService(accessory) {
1091
1117
  // If doorService still pressent, then remove first
1092
1118
  this.doorService = this.accessory.getService(this.platform.Service.Door);
1093
1119
  if (this.doorService) {
@@ -1095,7 +1121,7 @@ class Bot {
1095
1121
  }
1096
1122
  accessory.removeService(this.doorService);
1097
1123
  }
1098
- removeLockService(accessory) {
1124
+ async removeLockService(accessory) {
1099
1125
  // If lockService still pressent, then remove first
1100
1126
  this.lockService = this.accessory.getService(this.platform.Service.LockMechanism);
1101
1127
  if (this.lockService) {
@@ -1103,7 +1129,7 @@ class Bot {
1103
1129
  }
1104
1130
  accessory.removeService(this.lockService);
1105
1131
  }
1106
- removeFaucetService(accessory) {
1132
+ async removeFaucetService(accessory) {
1107
1133
  // If faucetService still pressent, then remove first
1108
1134
  this.faucetService = this.accessory.getService(this.platform.Service.Faucet);
1109
1135
  if (this.faucetService) {
@@ -1111,7 +1137,7 @@ class Bot {
1111
1137
  }
1112
1138
  accessory.removeService(this.faucetService);
1113
1139
  }
1114
- removeFanService(accessory) {
1140
+ async removeFanService(accessory) {
1115
1141
  // If fanService still pressent, then remove first
1116
1142
  this.fanService = this.accessory.getService(this.platform.Service.Fan);
1117
1143
  if (this.fanService) {
@@ -1119,7 +1145,7 @@ class Bot {
1119
1145
  }
1120
1146
  accessory.removeService(this.fanService);
1121
1147
  }
1122
- removeWindowService(accessory) {
1148
+ async removeWindowService(accessory) {
1123
1149
  // If windowService still pressent, then remove first
1124
1150
  this.windowService = this.accessory.getService(this.platform.Service.Window);
1125
1151
  if (this.windowService) {
@@ -1127,7 +1153,7 @@ class Bot {
1127
1153
  }
1128
1154
  accessory.removeService(this.windowService);
1129
1155
  }
1130
- removeWindowCoveringService(accessory) {
1156
+ async removeWindowCoveringService(accessory) {
1131
1157
  // If windowCoveringService still pressent, then remove first
1132
1158
  this.windowCoveringService = this.accessory.getService(this.platform.Service.WindowCovering);
1133
1159
  if (this.windowCoveringService) {
@@ -1135,7 +1161,7 @@ class Bot {
1135
1161
  }
1136
1162
  accessory.removeService(this.windowCoveringService);
1137
1163
  }
1138
- removeStatefulProgrammableSwitchService(accessory) {
1164
+ async removeStatefulProgrammableSwitchService(accessory) {
1139
1165
  // If statefulProgrammableSwitchService still pressent, then remove first
1140
1166
  this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
1141
1167
  if (this.statefulProgrammableSwitchService) {
@@ -1143,7 +1169,7 @@ class Bot {
1143
1169
  }
1144
1170
  accessory.removeService(this.statefulProgrammableSwitchService);
1145
1171
  }
1146
- removeSwitchService(accessory) {
1172
+ async removeSwitchService(accessory) {
1147
1173
  // If switchService still pressent, then remove first
1148
1174
  this.switchService = this.accessory.getService(this.platform.Service.Switch);
1149
1175
  if (this.switchService) {