@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.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 (105) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/config.schema.json +9 -0
  5. package/dist/devices/bots.d.ts +37 -34
  6. package/dist/devices/bots.d.ts.map +1 -1
  7. package/dist/devices/bots.js +196 -243
  8. package/dist/devices/bots.js.map +1 -1
  9. package/dist/devices/colorbulb.d.ts +50 -50
  10. package/dist/devices/colorbulb.d.ts.map +1 -1
  11. package/dist/devices/colorbulb.js +131 -145
  12. package/dist/devices/colorbulb.js.map +1 -1
  13. package/dist/devices/contact.d.ts +29 -27
  14. package/dist/devices/contact.d.ts.map +1 -1
  15. package/dist/devices/contact.js +115 -138
  16. package/dist/devices/contact.js.map +1 -1
  17. package/dist/devices/curtains.d.ts +31 -29
  18. package/dist/devices/curtains.d.ts.map +1 -1
  19. package/dist/devices/curtains.js +176 -211
  20. package/dist/devices/curtains.js.map +1 -1
  21. package/dist/devices/humidifiers.d.ts +33 -33
  22. package/dist/devices/humidifiers.d.ts.map +1 -1
  23. package/dist/devices/humidifiers.js +189 -214
  24. package/dist/devices/humidifiers.js.map +1 -1
  25. package/dist/devices/meters.d.ts +31 -30
  26. package/dist/devices/meters.d.ts.map +1 -1
  27. package/dist/devices/meters.js +100 -124
  28. package/dist/devices/meters.js.map +1 -1
  29. package/dist/devices/motion.d.ts +26 -25
  30. package/dist/devices/motion.d.ts.map +1 -1
  31. package/dist/devices/motion.js +102 -120
  32. package/dist/devices/motion.js.map +1 -1
  33. package/dist/devices/plugs.d.ts +23 -23
  34. package/dist/devices/plugs.d.ts.map +1 -1
  35. package/dist/devices/plugs.js +63 -81
  36. package/dist/devices/plugs.js.map +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -22
  40. package/dist/index.js.map +1 -1
  41. package/dist/irdevices/airconditioners.d.ts +6 -6
  42. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  43. package/dist/irdevices/airconditioners.js +79 -105
  44. package/dist/irdevices/airconditioners.js.map +1 -1
  45. package/dist/irdevices/airpurifiers.d.ts +5 -5
  46. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  47. package/dist/irdevices/airpurifiers.js +42 -56
  48. package/dist/irdevices/airpurifiers.js.map +1 -1
  49. package/dist/irdevices/cameras.d.ts +5 -5
  50. package/dist/irdevices/cameras.d.ts.map +1 -1
  51. package/dist/irdevices/cameras.js +27 -31
  52. package/dist/irdevices/cameras.js.map +1 -1
  53. package/dist/irdevices/fans.d.ts +5 -5
  54. package/dist/irdevices/fans.d.ts.map +1 -1
  55. package/dist/irdevices/fans.js +38 -45
  56. package/dist/irdevices/fans.js.map +1 -1
  57. package/dist/irdevices/lights.d.ts +5 -5
  58. package/dist/irdevices/lights.d.ts.map +1 -1
  59. package/dist/irdevices/lights.js +33 -37
  60. package/dist/irdevices/lights.js.map +1 -1
  61. package/dist/irdevices/others.d.ts +5 -5
  62. package/dist/irdevices/others.d.ts.map +1 -1
  63. package/dist/irdevices/others.js +29 -34
  64. package/dist/irdevices/others.js.map +1 -1
  65. package/dist/irdevices/tvs.d.ts +5 -5
  66. package/dist/irdevices/tvs.d.ts.map +1 -1
  67. package/dist/irdevices/tvs.js +76 -91
  68. package/dist/irdevices/tvs.js.map +1 -1
  69. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  70. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  71. package/dist/irdevices/vacuumcleaners.js +27 -31
  72. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  73. package/dist/irdevices/waterheaters.d.ts +5 -5
  74. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  75. package/dist/irdevices/waterheaters.js +27 -31
  76. package/dist/irdevices/waterheaters.js.map +1 -1
  77. package/dist/platform.d.ts +12 -12
  78. package/dist/platform.d.ts.map +1 -1
  79. package/dist/platform.js +172 -241
  80. package/dist/platform.js.map +1 -1
  81. package/dist/settings.d.ts +2 -1
  82. package/dist/settings.d.ts.map +1 -1
  83. package/dist/settings.js +4 -4
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +71 -72
  86. package/src/devices/bots.ts +455 -929
  87. package/src/devices/colorbulb.ts +246 -473
  88. package/src/devices/contact.ts +208 -381
  89. package/src/devices/curtains.ts +321 -613
  90. package/src/devices/humidifiers.ts +323 -594
  91. package/src/devices/meters.ts +186 -331
  92. package/src/devices/motion.ts +184 -327
  93. package/src/devices/plugs.ts +107 -175
  94. package/src/index.ts +5 -5
  95. package/src/irdevices/airconditioners.ts +149 -360
  96. package/src/irdevices/airpurifiers.ts +80 -178
  97. package/src/irdevices/cameras.ts +51 -109
  98. package/src/irdevices/fans.ts +77 -174
  99. package/src/irdevices/lights.ts +57 -110
  100. package/src/irdevices/others.ts +62 -137
  101. package/src/irdevices/tvs.ts +124 -249
  102. package/src/irdevices/vacuumcleaners.ts +52 -112
  103. package/src/irdevices/waterheaters.ts +53 -115
  104. package/src/platform.ts +357 -768
  105. package/src/settings.ts +24 -17
@@ -1,9 +1,10 @@
1
- import * as axios from "axios";
2
- import * as homebridge from "homebridge";
3
- import * as rxjs from "rxjs";
4
- import * as operators from "rxjs/operators";
5
- import * as platform from "../platform";
6
- import * as settings from "../settings";
1
+
2
+ import { AxiosResponse } from 'axios';
3
+ import { interval, Subject } from 'rxjs';
4
+ import { SwitchBotPlatform } from '../platform';
5
+ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
+ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
7
8
 
8
9
  /**
9
10
  * Platform Accessory
@@ -12,38 +13,41 @@ import * as settings from "../settings";
12
13
  */
13
14
  export class Bot {
14
15
  // Services
15
- private fanService?: homebridge.Service;
16
- private doorService?: homebridge.Service;
17
- private lockService?: homebridge.Service;
18
- private faucetService?: homebridge.Service;
19
- private windowService?: homebridge.Service;
20
- private switchService?: homebridge.Service;
21
- private outletService?: homebridge.Service;
22
- private batteryService?: homebridge.Service;
23
- private garageDoorService?: homebridge.Service;
24
- private windowCoveringService?: homebridge.Service;
25
- private statefulProgrammableSwitchService?: homebridge.Service;
16
+ private fanService?: Service;
17
+ private doorService?: Service;
18
+ private lockService?: Service;
19
+ private faucetService?: Service;
20
+ private windowService?: Service;
21
+ private switchService?: Service;
22
+ private outletService?: Service;
23
+ private batteryService?: Service;
24
+ private garageDoorService?: Service;
25
+ private windowCoveringService?: Service;
26
+ private statefulProgrammableSwitchService?: Service;
27
+
26
28
 
27
29
  // Characteristic Values
28
- On!: homebridge.CharacteristicValue;
29
- OnCached!: homebridge.CharacteristicValue;
30
- BatteryLevel!: homebridge.CharacteristicValue;
31
- StatusLowBattery!: homebridge.CharacteristicValue;
30
+ On!: CharacteristicValue;
31
+ OnCached!: CharacteristicValue;
32
+ BatteryLevel!: CharacteristicValue;
33
+ StatusLowBattery!: CharacteristicValue;
32
34
 
33
35
  // OpenAPI Others
34
- power: settings.deviceStatus["power"];
35
- deviceStatus!: settings.deviceStatusResponse;
36
+ power: deviceStatus['power'];
37
+ deviceStatus!: deviceStatusResponse;
36
38
 
37
39
  // BLE Others
38
40
  connected?: boolean;
41
+ switchbot!: switchbot;
39
42
  SwitchToOpenAPI?: boolean;
40
- serviceData!: settings.serviceData;
41
- mode!: settings.serviceData["mode"];
42
- state!: settings.serviceData["state"];
43
- battery!: settings.serviceData["battery"];
43
+ serviceData!: serviceData;
44
+ mode!: serviceData['mode'];
45
+ state!: serviceData['state'];
46
+ battery!: serviceData['battery'];
44
47
 
45
48
  // Config
46
49
  botMode!: string;
50
+ allowPush?: boolean;
47
51
  scanDuration!: number;
48
52
  deviceLogging!: string;
49
53
  deviceRefreshRate!: number;
@@ -53,18 +57,19 @@ export class Bot {
53
57
 
54
58
  // Updates
55
59
  botUpdateInProgress!: boolean;
56
- doBotUpdate!: rxjs.Subject<void>;
60
+ doBotUpdate!: Subject<void>;
57
61
 
58
62
  constructor(
59
- private readonly platform: platform.SwitchBotPlatform,
60
- private accessory: homebridge.PlatformAccessory,
61
- public device: settings.device & settings.devicesConfig,
63
+ private readonly platform: SwitchBotPlatform,
64
+ private accessory: PlatformAccessory,
65
+ public device: device & devicesConfig,
62
66
  ) {
63
67
  // default placeholders
64
68
  this.logs(device);
65
69
  this.scan(device);
66
70
  this.refreshRate(device);
67
71
  this.PressOrSwitch(device);
72
+ this.allowPushChanges(device);
68
73
  this.config(device);
69
74
  if (this.On === undefined) {
70
75
  this.On = false;
@@ -82,7 +87,7 @@ export class Bot {
82
87
  this.StatusLowBattery = 0;
83
88
 
84
89
  // this is subject we use to track when we need to POST changes to the SwitchBot API
85
- this.doBotUpdate = new rxjs.Subject();
90
+ this.doBotUpdate = new Subject();
86
91
  this.botUpdateInProgress = false;
87
92
 
88
93
  // Retrieve initial values and updateHomekit
@@ -91,16 +96,13 @@ export class Bot {
91
96
  // set accessory information
92
97
  accessory
93
98
  .getService(this.platform.Service.AccessoryInformation)!
94
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
95
- .setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-BOT-S1")
96
- .setCharacteristic(
97
- this.platform.Characteristic.SerialNumber,
98
- device.deviceId!,
99
- );
99
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
100
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
101
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
100
102
 
101
103
  // get the LightBulb service if it exists, otherwise create a new LightBulb service
102
104
  // you can create multiple services for each accessory
103
- if (device.bot?.deviceType === "switch") {
105
+ if (device.bot?.deviceType === 'switch') {
104
106
  this.removeFanService(accessory);
105
107
  this.removeLockService(accessory);
106
108
  this.removeDoorService(accessory);
@@ -114,18 +116,12 @@ export class Bot {
114
116
  // Add switchService
115
117
  (this.switchService =
116
118
  accessory.getService(this.platform.Service.Switch) ||
117
- accessory.addService(this.platform.Service.Switch)),
118
- `${accessory.displayName} Switch`;
119
+ accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
119
120
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
120
121
 
121
- this.switchService.setCharacteristic(
122
- this.platform.Characteristic.Name,
123
- accessory.displayName,
124
- );
125
- this.switchService
126
- .getCharacteristic(this.platform.Characteristic.On)
127
- .onSet(this.handleOnSet.bind(this));
128
- } else if (device.bot?.deviceType === "garagedoor") {
122
+ this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
123
+ this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
124
+ } else if (device.bot?.deviceType === 'garagedoor') {
129
125
  this.removeFanService(accessory);
130
126
  this.removeLockService(accessory);
131
127
  this.removeDoorService(accessory);
@@ -139,24 +135,13 @@ export class Bot {
139
135
  // Add switchService
140
136
  (this.garageDoorService =
141
137
  accessory.getService(this.platform.Service.GarageDoorOpener) ||
142
- accessory.addService(this.platform.Service.GarageDoorOpener)),
143
- `${accessory.displayName} Garage Door Opener`;
144
- this.infoLog(
145
- `Bot: ${accessory.displayName} Displaying as Garage Door Opener`,
146
- );
147
-
148
- this.garageDoorService.setCharacteristic(
149
- this.platform.Characteristic.Name,
150
- accessory.displayName,
151
- );
152
- this.garageDoorService
153
- .getCharacteristic(this.platform.Characteristic.TargetDoorState)
154
- .onSet(this.handleOnSet.bind(this));
155
- this.garageDoorService.setCharacteristic(
156
- this.platform.Characteristic.ObstructionDetected,
157
- false,
158
- );
159
- } else if (device.bot?.deviceType === "door") {
138
+ accessory.addService(this.platform.Service.GarageDoorOpener)), `${accessory.displayName} Garage Door Opener`;
139
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
140
+
141
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
142
+ this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
143
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
144
+ } else if (device.bot?.deviceType === 'door') {
160
145
  this.removeFanService(accessory);
161
146
  this.removeLockService(accessory);
162
147
  this.removeOutletService(accessory);
@@ -170,28 +155,19 @@ export class Bot {
170
155
  // Add switchService
171
156
  (this.doorService =
172
157
  accessory.getService(this.platform.Service.Door) ||
173
- accessory.addService(this.platform.Service.Door)),
174
- `${accessory.displayName} Door`;
158
+ accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
175
159
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
176
160
 
177
- this.doorService.setCharacteristic(
178
- this.platform.Characteristic.Name,
179
- accessory.displayName,
180
- );
181
- this.doorService
182
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
161
+ this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
162
+ this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
183
163
  .setProps({
184
164
  validValues: [0, 100],
185
165
  minValue: 0,
186
166
  maxValue: 100,
187
167
  minStep: 100,
188
- })
189
- .onSet(this.handleOnSet.bind(this));
190
- this.doorService.setCharacteristic(
191
- this.platform.Characteristic.PositionState,
192
- this.platform.Characteristic.PositionState.STOPPED,
193
- );
194
- } else if (device.bot?.deviceType === "window") {
168
+ }).onSet(this.handleOnSet.bind(this));
169
+ this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
170
+ } else if (device.bot?.deviceType === 'window') {
195
171
  this.removeFanService(accessory);
196
172
  this.removeLockService(accessory);
197
173
  this.removeDoorService(accessory);
@@ -205,28 +181,19 @@ export class Bot {
205
181
  // Add switchService
206
182
  (this.windowService =
207
183
  accessory.getService(this.platform.Service.Window) ||
208
- accessory.addService(this.platform.Service.Window)),
209
- `${accessory.displayName} Window`;
184
+ accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
210
185
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
211
186
 
212
- this.windowService.setCharacteristic(
213
- this.platform.Characteristic.Name,
214
- accessory.displayName,
215
- );
216
- this.windowService
217
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
187
+ this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
188
+ this.windowService.getCharacteristic(this.platform.Characteristic.TargetPosition)
218
189
  .setProps({
219
190
  validValues: [0, 100],
220
191
  minValue: 0,
221
192
  maxValue: 100,
222
193
  minStep: 100,
223
- })
224
- .onSet(this.handleOnSet.bind(this));
225
- this.windowService.setCharacteristic(
226
- this.platform.Characteristic.PositionState,
227
- this.platform.Characteristic.PositionState.STOPPED,
228
- );
229
- } else if (device.bot?.deviceType === "windowcovering") {
194
+ }).onSet(this.handleOnSet.bind(this));
195
+ this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
196
+ } else if (device.bot?.deviceType === 'windowcovering') {
230
197
  this.removeFanService(accessory);
231
198
  this.removeLockService(accessory);
232
199
  this.removeDoorService(accessory);
@@ -240,30 +207,19 @@ export class Bot {
240
207
  // Add switchService
241
208
  (this.windowCoveringService =
242
209
  accessory.getService(this.platform.Service.WindowCovering) ||
243
- accessory.addService(this.platform.Service.WindowCovering)),
244
- `${accessory.displayName} Window Covering`;
245
- this.infoLog(
246
- `Bot: ${accessory.displayName} Displaying as Window Covering`,
247
- );
248
-
249
- this.windowCoveringService.setCharacteristic(
250
- this.platform.Characteristic.Name,
251
- accessory.displayName,
252
- );
253
- this.windowCoveringService
254
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
210
+ accessory.addService(this.platform.Service.WindowCovering)), `${accessory.displayName} Window Covering`;
211
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
212
+
213
+ this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
214
+ this.windowCoveringService.getCharacteristic(this.platform.Characteristic.TargetPosition)
255
215
  .setProps({
256
216
  validValues: [0, 100],
257
217
  minValue: 0,
258
218
  maxValue: 100,
259
219
  minStep: 100,
260
- })
261
- .onSet(this.handleOnSet.bind(this));
262
- this.windowCoveringService.setCharacteristic(
263
- this.platform.Characteristic.PositionState,
264
- this.platform.Characteristic.PositionState.STOPPED,
265
- );
266
- } else if (device.bot?.deviceType === "lock") {
220
+ }).onSet(this.handleOnSet.bind(this));
221
+ this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
222
+ } else if (device.bot?.deviceType === 'lock') {
267
223
  this.removeFanService(accessory);
268
224
  this.removeDoorService(accessory);
269
225
  this.removeOutletService(accessory);
@@ -277,18 +233,12 @@ export class Bot {
277
233
  // Add switchService
278
234
  (this.lockService =
279
235
  accessory.getService(this.platform.Service.LockMechanism) ||
280
- accessory.addService(this.platform.Service.LockMechanism)),
281
- `${accessory.displayName} Lock`;
236
+ accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
282
237
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
283
238
 
284
- this.lockService.setCharacteristic(
285
- this.platform.Characteristic.Name,
286
- accessory.displayName,
287
- );
288
- this.lockService
289
- .getCharacteristic(this.platform.Characteristic.LockTargetState)
290
- .onSet(this.handleOnSet.bind(this));
291
- } else if (device.bot?.deviceType === "faucet") {
239
+ this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
240
+ this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
241
+ } else if (device.bot?.deviceType === 'faucet') {
292
242
  this.removeFanService(accessory);
293
243
  this.removeLockService(accessory);
294
244
  this.removeDoorService(accessory);
@@ -302,18 +252,12 @@ export class Bot {
302
252
  // Add switchService
303
253
  (this.faucetService =
304
254
  accessory.getService(this.platform.Service.Faucet) ||
305
- accessory.addService(this.platform.Service.Faucet)),
306
- `${accessory.displayName} Faucet`;
255
+ accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
307
256
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
308
257
 
309
- this.faucetService.setCharacteristic(
310
- this.platform.Characteristic.Name,
311
- accessory.displayName,
312
- );
313
- this.faucetService
314
- .getCharacteristic(this.platform.Characteristic.Active)
315
- .onSet(this.handleOnSet.bind(this));
316
- } else if (device.bot?.deviceType === "fan") {
258
+ this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
259
+ this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
260
+ } else if (device.bot?.deviceType === 'fan') {
317
261
  this.removeLockService(accessory);
318
262
  this.removeDoorService(accessory);
319
263
  this.removeFaucetService(accessory);
@@ -327,18 +271,12 @@ export class Bot {
327
271
  // Add switchService
328
272
  (this.fanService =
329
273
  accessory.getService(this.platform.Service.Fan) ||
330
- accessory.addService(this.platform.Service.Fan)),
331
- `${accessory.displayName} Fan`;
274
+ accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
332
275
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
333
276
 
334
- this.fanService.setCharacteristic(
335
- this.platform.Characteristic.Name,
336
- accessory.displayName,
337
- );
338
- this.fanService
339
- .getCharacteristic(this.platform.Characteristic.On)
340
- .onSet(this.handleOnSet.bind(this));
341
- } else if (device.bot?.deviceType === "stateful") {
277
+ this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
278
+ this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
279
+ } else if (device.bot?.deviceType === 'stateful') {
342
280
  this.removeFanService(accessory);
343
281
  this.removeLockService(accessory);
344
282
  this.removeDoorService(accessory);
@@ -351,23 +289,12 @@ export class Bot {
351
289
 
352
290
  // Add switchService
353
291
  (this.statefulProgrammableSwitchService =
354
- accessory.getService(
355
- this.platform.Service.StatefulProgrammableSwitch,
356
- ) ||
357
- accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
358
- `${accessory.displayName} Stateful Programmable Switch`;
359
- this.infoLog(
360
- `Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`,
361
- );
362
-
363
- this.statefulProgrammableSwitchService.setCharacteristic(
364
- this.platform.Characteristic.Name,
365
- accessory.displayName,
366
- );
367
- this.statefulProgrammableSwitchService
368
- .getCharacteristic(
369
- this.platform.Characteristic.ProgrammableSwitchOutputState,
370
- )
292
+ accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
293
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
294
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
295
+
296
+ this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
297
+ this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
371
298
  .onSet(this.handleOnSet.bind(this));
372
299
  } else {
373
300
  this.removeFanService(accessory);
@@ -383,37 +310,26 @@ export class Bot {
383
310
  // Add outletService
384
311
  (this.outletService =
385
312
  accessory.getService(this.platform.Service.Outlet) ||
386
- accessory.addService(this.platform.Service.Outlet)),
387
- `${accessory.displayName} Outlet`;
313
+ accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
388
314
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
389
315
 
390
- this.outletService.setCharacteristic(
391
- this.platform.Characteristic.Name,
392
- accessory.displayName,
393
- );
394
- this.outletService
395
- .getCharacteristic(this.platform.Characteristic.On)
396
- .onSet(this.handleOnSet.bind(this));
316
+ this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
317
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
397
318
  }
398
319
 
399
320
  // Battery Service
400
321
  if (!device.ble) {
401
322
  this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
402
- this.batteryService = this.accessory.getService(
403
- this.platform.Service.Battery,
404
- );
323
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
405
324
  accessory.removeService(this.batteryService!);
406
325
  } else if (device.ble && !this.batteryService) {
407
326
  this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
408
327
  (this.batteryService =
409
328
  this.accessory.getService(this.platform.Service.Battery) ||
410
- this.accessory.addService(this.platform.Service.Battery)),
411
- `${accessory.displayName} Battery`;
329
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
330
+
331
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
412
332
 
413
- this.batteryService.setCharacteristic(
414
- this.platform.Characteristic.Name,
415
- `${accessory.displayName} Battery`,
416
- );
417
333
  } else {
418
334
  this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
419
335
  }
@@ -422,9 +338,8 @@ export class Bot {
422
338
  this.updateHomeKitCharacteristics();
423
339
 
424
340
  // Start an update interval
425
- rxjs
426
- .interval(this.deviceRefreshRate * 1000)
427
- .pipe(operators.skipWhile(() => this.botUpdateInProgress))
341
+ interval(this.deviceRefreshRate * 1000)
342
+ .pipe(skipWhile(() => this.botUpdateInProgress))
428
343
  .subscribe(() => {
429
344
  this.refreshStatus();
430
345
  });
@@ -433,28 +348,27 @@ export class Bot {
433
348
  // We put in a debounce of 100ms so we don't make duplicate calls
434
349
  this.doBotUpdate
435
350
  .pipe(
436
- operators.tap(() => {
351
+ tap(() => {
437
352
  this.botUpdateInProgress = true;
438
353
  }),
439
- operators.debounceTime(100),
354
+ debounceTime(100),
440
355
  )
441
356
  .subscribe(async () => {
442
357
  try {
443
- rxjs
444
- .interval(100)
445
- .pipe(operators.take(this.doublePress!))
358
+ interval(100)
359
+ .pipe(take(this.doublePress!))
446
360
  .subscribe(async () => {
447
361
  await this.pushChanges();
448
362
  });
449
363
  } catch (e: any) {
450
- this.errorLog(
451
- `Bot: ${this.accessory.displayName} failed pushChanges`,
452
- );
453
- if (this.deviceLogging.includes("debug")) {
454
- this.errorLog(
455
- `Bot: ${this.accessory.displayName} failed pushChanges,` +
456
- ` Error Message: ${JSON.stringify(e.message)}`,
457
- );
364
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
365
+ if (this.deviceLogging === 'debug') {
366
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
367
+ + ` Error Message: ${JSON.stringify(e.message)}`);
368
+ }
369
+ if (this.platform.debugMode) {
370
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
371
+ + ` Error: ${JSON.stringify(e)}`);
458
372
  }
459
373
  }
460
374
  this.botUpdateInProgress = false;
@@ -481,32 +395,24 @@ export class Bot {
481
395
  if (this.On === undefined) {
482
396
  this.On = Boolean(this.state);
483
397
  }
484
- this.debugLog(
485
- `Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`,
486
- );
398
+ this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`);
487
399
  } else {
488
400
  this.On = false;
489
401
  this.OnCached = this.On;
490
402
  this.accessory.context.On = this.OnCached;
491
- this.debugLog(
492
- `Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`,
493
- );
403
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`);
494
404
  }
495
405
 
496
406
  this.BatteryLevel = Number(this.battery);
497
407
  if (this.BatteryLevel < 10) {
498
- this.StatusLowBattery =
499
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
408
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
500
409
  } else {
501
- this.StatusLowBattery =
502
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
410
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
503
411
  }
504
412
  if (Number.isNaN(this.BatteryLevel)) {
505
413
  this.BatteryLevel = 100;
506
414
  }
507
- this.debugLog(
508
- `Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
509
- );
415
+ this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
510
416
  }
511
417
 
512
418
  private async openAPIparseStatus() {
@@ -515,7 +421,7 @@ export class Bot {
515
421
  }
516
422
  if (this.platform.config.credentials?.openToken) {
517
423
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
518
- if (this.botMode === "press") {
424
+ if (this.botMode === 'press') {
519
425
  this.On = false;
520
426
  this.OnCached = this.On;
521
427
  this.accessory.context.On = this.OnCached;
@@ -554,117 +460,87 @@ export class Bot {
554
460
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
555
461
  const switchbot = await this.platform.connectBLE();
556
462
  // Convert to BLE Address
557
- this.device.bleMac = this.device
558
- .deviceId!.match(/.{1,2}/g)!
559
- .join(":")
560
- .toLowerCase();
561
- this.debugLog(
562
- `Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
563
- );
564
- try {
565
- await switchbot.discover({
566
- model: "H",
567
- quick: false,
568
- });
569
- // Start to monitor advertisement packets
570
- await switchbot.startScan({
571
- model: "H",
572
- id: this.device.bleMac,
573
- });
463
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
464
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
465
+ // Start to monitor advertisement packets
466
+ if (switchbot === false) {
467
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
468
+ }
469
+ switchbot.startScan({
470
+ model: 'H',
471
+ id: this.device.bleMac,
472
+ }).then(() => {
574
473
  // Set an event hander
575
- switchbot.onadvertisement = (ad: settings.ad) => {
474
+ switchbot.onadvertisement = (ad: ad) => {
576
475
  this.serviceData = ad.serviceData;
577
476
  this.mode = ad.serviceData.mode;
578
477
  this.state = ad.serviceData.state;
579
478
  this.battery = ad.serviceData.battery;
580
- this.debugLog(
581
- `Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(
582
- ad.serviceData,
583
- )}`,
584
- );
585
- this.debugLog(
586
- `Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
587
- ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
588
- );
479
+ this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
480
+ this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
481
+ + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
589
482
 
590
483
  if (this.serviceData) {
591
484
  this.connected = true;
592
- this.debugLog(
593
- `Bot: ${this.accessory.displayName} connected: ${this.connected}`,
594
- );
485
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
595
486
  } else {
596
487
  this.connected = false;
597
- this.debugLog(
598
- `Bot: ${this.accessory.displayName} connected: ${this.connected}`,
599
- );
488
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
600
489
  }
601
490
  };
602
491
  // Wait 2 seconds
603
- await switchbot.wait(this.scanDuration * 1000);
492
+ return switchbot.wait(this.scanDuration * 1000);
493
+ }).then(async () => {
604
494
  // Stop to monitor
605
495
  switchbot.stopScan();
606
496
  if (this.connected) {
607
497
  this.parseStatus();
608
498
  this.updateHomeKitCharacteristics();
609
499
  } else {
610
- this.errorLog(
611
- `Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
612
- );
500
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
613
501
  if (this.platform.config.credentials?.openToken) {
614
- this.warnLog(
615
- `Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
616
- );
502
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
617
503
  this.SwitchToOpenAPI = true;
618
504
  await this.openAPIRefreshStatus();
619
505
  }
620
506
  }
621
- } catch (e: any) {
622
- this.errorLog(
623
- `Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`,
624
- );
625
- if (this.deviceLogging.includes("debug")) {
626
- this.errorLog(
627
- `Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
628
- ` Error Message: ${JSON.stringify(e.message)}`,
629
- );
507
+ }).catch(async (e: any) => {
508
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
509
+ if (this.deviceLogging === 'debug') {
510
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
511
+ + ` Error Message: ${JSON.stringify(e.message)}`);
512
+ }
513
+ if (this.platform.debugMode) {
514
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
515
+ + ` Error: ${JSON.stringify(e)}`);
630
516
  }
631
517
  if (this.platform.config.credentials?.openToken) {
632
- this.warnLog(
633
- `Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
634
- );
518
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
635
519
  this.SwitchToOpenAPI = true;
636
520
  await this.openAPIRefreshStatus();
637
521
  }
638
522
  this.apiError(e);
639
- }
523
+ });
640
524
  }
641
525
 
642
526
  private async openAPIRefreshStatus() {
643
527
  if (this.platform.config.credentials?.openToken) {
644
528
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
645
529
  try {
646
- this.deviceStatus = (
647
- await this.platform.axios.get(
648
- `${settings.DeviceURL}/${this.device.deviceId}/status`,
649
- )
650
- ).data;
651
- this.debugLog(
652
- `Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(
653
- this.deviceStatus,
654
- )}`,
655
- );
530
+ this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
531
+ this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
656
532
  this.power = this.deviceStatus.body.power;
657
533
  this.parseStatus();
658
534
  this.updateHomeKitCharacteristics();
659
535
  } catch (e: any) {
660
- this.errorLog(
661
- `Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
662
- );
663
- if (this.deviceLogging.includes("debug")) {
664
- this.errorLog(
665
- `Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
666
- ` Error Message: ${JSON.stringify(e.message)}`,
667
- );
536
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
537
+ if (this.deviceLogging === 'debug') {
538
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
539
+ + ` Error Message: ${JSON.stringify(e.message)}`);
540
+ }
541
+ if (this.platform.debugMode) {
542
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
543
+ + ` Error: ${JSON.stringify(e)}`);
668
544
  }
669
545
  this.apiError(e);
670
546
  }
@@ -684,122 +560,85 @@ export class Bot {
684
560
  } else {
685
561
  await this.openAPIpushChanges();
686
562
  }
687
- rxjs
688
- .interval(5000)
689
- .pipe(operators.skipWhile(() => this.botUpdateInProgress))
690
- .pipe(operators.take(1))
563
+ interval(5000)
564
+ .pipe(skipWhile(() => this.botUpdateInProgress))
565
+ .pipe(take(1))
691
566
  .subscribe(() => {
692
567
  this.refreshStatus();
693
568
  });
694
569
  }
695
570
 
696
571
  private async BLEpushChanges() {
697
- this.debugLog(
698
- `Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`,
699
- );
700
- if (this.On !== this.OnCached) {
572
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
573
+ if ((this.On !== this.OnCached) || this.allowPush) {
701
574
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
702
575
  const switchbot = await this.platform.connectBLE();
703
576
  // Convert to BLE Address
704
- this.device.bleMac = this.device
705
- .deviceId!.match(/.{1,2}/g)!
706
- .join(":")
707
- .toLowerCase();
708
- this.debugLog(
709
- `Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
710
- );
577
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
578
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
711
579
  //if (switchbot !== false) {
712
- if (this.botMode === "press") {
713
- this.debugLog(
714
- `Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
715
- );
716
- switchbot
717
- .discover({ model: "H", quick: true, id: this.device.bleMac })
718
- .then(
719
- (
720
- device_list: {
721
- press: (arg0: { id: string | undefined }) => any;
722
- }[],
723
- ) => {
724
- this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
725
- return device_list[0].press({ id: this.device.bleMac });
726
- },
727
- )
728
- .then(() => {
580
+ if (this.botMode === 'press') {
581
+ this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
582
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
583
+ .then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => {
584
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
585
+ return device_list[0].press({ id: this.device.bleMac });
586
+ }).then(() => {
729
587
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
730
588
  this.On = false;
731
589
  this.OnCached = this.On;
732
590
  this.accessory.context.On = this.OnCached;
733
591
  setTimeout(() => {
734
- if (this.device.bot?.deviceType === "switch") {
735
- this.switchService
736
- ?.getCharacteristic(this.platform.Characteristic.On)
737
- .updateValue(this.On);
592
+ if (this.device.bot?.deviceType === 'switch') {
593
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
738
594
  } else {
739
- this.outletService
740
- ?.getCharacteristic(this.platform.Characteristic.On)
741
- .updateValue(this.On);
595
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
742
596
  }
743
- this.debugLog(
744
- `Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`,
745
- );
597
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
746
598
  }, 500);
747
- })
748
- .catch(async (e: any) => {
749
- this.errorLog(
750
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
751
- );
752
- if (this.deviceLogging.includes("debug")) {
753
- this.errorLog(
754
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
755
- ` Error Message: ${JSON.stringify(e.message)}`,
756
- );
599
+ }).catch(async (e: any) => {
600
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
601
+ if (this.deviceLogging === 'debug') {
602
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
603
+ + ` Error Message: ${JSON.stringify(e.message)}`);
757
604
  }
758
- if (this.platform.config.credentials?.openToken) {
759
- this.warnLog(
760
- `Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
761
- );
762
- await this.openAPIpushChanges();
763
- }
764
- this.apiError(e);
765
- });
766
- } else if (this.botMode === "switch") {
767
- this.debugLog(
768
- `Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`,
769
- );
770
- switchbot
771
- .discover({ model: "H", quick: true, id: this.device.bleMac })
772
- .then((device_list: any) => {
773
- this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
774
- return this.turnOnOff(device_list);
775
- })
776
- .then(() => {
777
- this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
778
- this.OnCached = this.On;
779
- this.accessory.context.On = this.OnCached;
780
- })
781
- .catch(async (e: any) => {
782
- this.errorLog(
783
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
784
- );
785
- if (this.deviceLogging.includes("debug")) {
786
- this.errorLog(
787
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
788
- ` Error Message: ${JSON.stringify(e.message)}`,
789
- );
605
+ if (this.platform.debugMode) {
606
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
607
+ + ` Error: ${JSON.stringify(e)}`);
790
608
  }
791
609
  if (this.platform.config.credentials?.openToken) {
792
- this.warnLog(
793
- `Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
794
- );
610
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
795
611
  await this.openAPIpushChanges();
796
612
  }
797
613
  this.apiError(e);
798
614
  });
615
+ } else if (this.botMode === 'switch') {
616
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
617
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
618
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
619
+ return this.turnOnOff(device_list);
620
+ }).then(() => {
621
+ this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
622
+ this.OnCached = this.On;
623
+ this.accessory.context.On = this.OnCached;
624
+ }).catch(async (e: any) => {
625
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
626
+ if (this.deviceLogging === 'debug') {
627
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
628
+ + ` Error Message: ${JSON.stringify(e.message)}`);
629
+ }
630
+ if (this.platform.debugMode) {
631
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
632
+ + ` Error: ${JSON.stringify(e)}`);
633
+ }
634
+ if (this.platform.config.credentials?.openToken) {
635
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
636
+ await this.openAPIpushChanges();
637
+ }
638
+ this.apiError(e);
639
+ });
799
640
  } else {
800
- throw new Error(
801
- `Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
802
- );
641
+ throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
803
642
  }
804
643
  /* } else {
805
644
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
@@ -824,65 +663,48 @@ export class Bot {
824
663
  private async openAPIpushChanges() {
825
664
  if (this.platform.config.credentials?.openToken) {
826
665
  try {
827
- if (this.On !== this.OnCached) {
828
- this.debugLog(
829
- `Bot: ${this.accessory.displayName} OpenAPI pushChanges`,
830
- );
666
+ if ((this.On !== this.OnCached) || this.allowPush) {
667
+ this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
831
668
  const payload = {
832
- commandType: "command",
833
- parameter: "default",
834
- } as settings.payload;
669
+ commandType: 'command',
670
+ parameter: 'default',
671
+ } as payload;
835
672
 
836
- if (this.botMode === "switch" && this.On) {
837
- payload.command = "turnOn";
673
+ if (this.botMode === 'switch' && this.On) {
674
+ payload.command = 'turnOn';
838
675
  this.On = true;
839
- this.debugLog(
840
- `Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`,
841
- );
842
- } else if (this.botMode === "switch" && !this.On) {
843
- payload.command = "turnOff";
676
+ this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
677
+ } else if (this.botMode === 'switch' && !this.On) {
678
+ payload.command = 'turnOff';
844
679
  this.On = false;
845
- this.debugLog(
846
- `Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`,
847
- );
848
- } else if (this.botMode === "press") {
849
- payload.command = "press";
680
+ this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
681
+ } else if (this.botMode === 'press') {
682
+ payload.command = 'press';
850
683
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
851
684
  this.On = false;
852
685
  } else {
853
- throw new Error(
854
- `Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`,
855
- );
686
+ throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
856
687
  }
857
688
 
858
- this.infoLog(
859
- `Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
860
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
861
- );
689
+ this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
690
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
862
691
 
863
692
  // Make the API request
864
- const push: any = await this.platform.axios.post(
865
- `${settings.DeviceURL}/${this.device.deviceId}/commands`,
866
- payload,
867
- );
868
- this.debugLog(
869
- `Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(
870
- push.data,
871
- )}`,
872
- );
693
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
694
+ this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
873
695
  this.statusCode(push);
874
696
  this.OnCached = this.On;
875
697
  this.accessory.context.On = this.OnCached;
876
698
  }
877
699
  } catch (e: any) {
878
- this.errorLog(
879
- `Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
880
- );
881
- if (this.deviceLogging.includes("debug")) {
882
- this.errorLog(
883
- `Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
884
- ` Error Message: ${JSON.stringify(e.message)}`,
885
- );
700
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
701
+ if (this.deviceLogging === 'debug') {
702
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
703
+ + ` Error Message: ${JSON.stringify(e.message)}`);
704
+ }
705
+ if (this.platform.debugMode) {
706
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
707
+ + ` Error: ${JSON.stringify(e)}`);
886
708
  }
887
709
  this.apiError(e);
888
710
  }
@@ -893,460 +715,241 @@ export class Bot {
893
715
  * Updates the status for each of the HomeKit Characteristics
894
716
  */
895
717
  updateHomeKitCharacteristics() {
896
- if (this.device.bot?.deviceType === "garagedoor") {
718
+ if (this.device.bot?.deviceType === 'garagedoor') {
897
719
  if (this.On === undefined) {
898
720
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
899
721
  } else {
900
722
  if (this.On) {
901
- this.garageDoorService?.updateCharacteristic(
902
- this.platform.Characteristic.TargetDoorState,
903
- this.platform.Characteristic.TargetDoorState.OPEN,
904
- );
905
- this.garageDoorService?.updateCharacteristic(
906
- this.platform.Characteristic.CurrentDoorState,
907
- this.platform.Characteristic.CurrentDoorState.OPEN,
908
- );
909
- this.debugLog(
910
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
911
- );
723
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState,
724
+ this.platform.Characteristic.TargetDoorState.OPEN);
725
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState,
726
+ this.platform.Characteristic.CurrentDoorState.OPEN);
727
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
912
728
  } else {
913
- this.garageDoorService?.updateCharacteristic(
914
- this.platform.Characteristic.TargetDoorState,
915
- this.platform.Characteristic.TargetDoorState.CLOSED,
916
- );
917
- this.garageDoorService?.updateCharacteristic(
918
- this.platform.Characteristic.CurrentDoorState,
919
- this.platform.Characteristic.CurrentDoorState.CLOSED,
920
- );
921
- this.debugLog(
922
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
923
- );
729
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState,
730
+ this.platform.Characteristic.TargetDoorState.CLOSED);
731
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState,
732
+ this.platform.Characteristic.CurrentDoorState.CLOSED);
733
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
924
734
  }
925
735
  }
926
- this.debugLog(
927
- `Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`,
928
- );
929
- } else if (this.device.bot?.deviceType === "door") {
736
+ this.debugLog(`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`);
737
+ } else if (this.device.bot?.deviceType === 'door') {
930
738
  if (this.On === undefined) {
931
739
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
932
740
  } else {
933
741
  if (this.On) {
934
- this.doorService?.updateCharacteristic(
935
- this.platform.Characteristic.TargetPosition,
936
- 100,
937
- );
938
- this.doorService?.updateCharacteristic(
939
- this.platform.Characteristic.CurrentPosition,
940
- 100,
941
- );
942
- this.doorService?.updateCharacteristic(
943
- this.platform.Characteristic.PositionState,
944
- this.platform.Characteristic.PositionState.STOPPED,
945
- );
946
- this.debugLog(
947
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
948
- );
742
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
743
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
744
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState,
745
+ this.platform.Characteristic.PositionState.STOPPED);
746
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
949
747
  } else {
950
- this.doorService?.updateCharacteristic(
951
- this.platform.Characteristic.TargetPosition,
952
- 0,
953
- );
954
- this.doorService?.updateCharacteristic(
955
- this.platform.Characteristic.CurrentPosition,
956
- 0,
957
- );
958
- this.doorService?.updateCharacteristic(
959
- this.platform.Characteristic.PositionState,
960
- this.platform.Characteristic.PositionState.STOPPED,
961
- );
962
- this.debugLog(
963
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
964
- );
748
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
749
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
750
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState,
751
+ this.platform.Characteristic.PositionState.STOPPED);
752
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
965
753
  }
966
754
  }
967
755
  this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
968
- } else if (this.device.bot?.deviceType === "window") {
756
+ } else if (this.device.bot?.deviceType === 'window') {
969
757
  if (this.On === undefined) {
970
758
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
971
759
  } else {
972
760
  if (this.On) {
973
- this.windowService?.updateCharacteristic(
974
- this.platform.Characteristic.TargetPosition,
975
- 100,
976
- );
977
- this.windowService?.updateCharacteristic(
978
- this.platform.Characteristic.CurrentPosition,
979
- 100,
980
- );
981
- this.windowService?.updateCharacteristic(
982
- this.platform.Characteristic.PositionState,
983
- this.platform.Characteristic.PositionState.STOPPED,
984
- );
985
- this.debugLog(
986
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
987
- );
761
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
762
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
763
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState,
764
+ this.platform.Characteristic.PositionState.STOPPED);
765
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
988
766
  } else {
989
- this.windowService?.updateCharacteristic(
990
- this.platform.Characteristic.TargetPosition,
991
- 0,
992
- );
993
- this.windowService?.updateCharacteristic(
994
- this.platform.Characteristic.CurrentPosition,
995
- 0,
996
- );
997
- this.windowService?.updateCharacteristic(
998
- this.platform.Characteristic.PositionState,
999
- this.platform.Characteristic.PositionState.STOPPED,
1000
- );
1001
- this.debugLog(
1002
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
1003
- );
767
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
768
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
769
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState,
770
+ this.platform.Characteristic.PositionState.STOPPED);
771
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
1004
772
  }
1005
773
  }
1006
774
  this.debugLog(`Bot: ${this.accessory.displayName} Window On: ${this.On}`);
1007
- } else if (this.device.bot?.deviceType === "windowcovering") {
775
+ } else if (this.device.bot?.deviceType === 'windowcovering') {
1008
776
  if (this.On === undefined) {
1009
777
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1010
778
  } else {
1011
779
  if (this.On) {
1012
- this.windowCoveringService?.updateCharacteristic(
1013
- this.platform.Characteristic.TargetPosition,
1014
- 100,
1015
- );
1016
- this.windowCoveringService?.updateCharacteristic(
1017
- this.platform.Characteristic.CurrentPosition,
1018
- 100,
1019
- );
1020
- this.windowCoveringService?.updateCharacteristic(
1021
- this.platform.Characteristic.PositionState,
1022
- this.platform.Characteristic.PositionState.STOPPED,
1023
- );
1024
- this.debugLog(
1025
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
1026
- );
780
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
781
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
782
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState,
783
+ this.platform.Characteristic.PositionState.STOPPED);
784
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
1027
785
  } else {
1028
- this.windowCoveringService?.updateCharacteristic(
1029
- this.platform.Characteristic.TargetPosition,
1030
- 0,
1031
- );
1032
- this.windowCoveringService?.updateCharacteristic(
1033
- this.platform.Characteristic.CurrentPosition,
1034
- 0,
1035
- );
1036
- this.windowCoveringService?.updateCharacteristic(
1037
- this.platform.Characteristic.PositionState,
1038
- this.platform.Characteristic.PositionState.STOPPED,
1039
- );
1040
- this.debugLog(
1041
- `Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
1042
- );
786
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
787
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
788
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState,
789
+ this.platform.Characteristic.PositionState.STOPPED);
790
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
1043
791
  }
1044
792
  }
1045
- this.debugLog(
1046
- `Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`,
1047
- );
1048
- } else if (this.device.bot?.deviceType === "lock") {
793
+ this.debugLog(`Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`);
794
+ } else if (this.device.bot?.deviceType === 'lock') {
1049
795
  if (this.On === undefined) {
1050
796
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1051
797
  } else {
1052
798
  if (this.On) {
1053
- this.lockService?.updateCharacteristic(
1054
- this.platform.Characteristic.LockTargetState,
1055
- this.platform.Characteristic.LockTargetState.UNSECURED,
1056
- );
1057
- this.lockService?.updateCharacteristic(
1058
- this.platform.Characteristic.LockCurrentState,
1059
- this.platform.Characteristic.LockCurrentState.UNSECURED,
1060
- );
1061
- this.debugLog(
1062
- `Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`,
1063
- );
799
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState,
800
+ this.platform.Characteristic.LockTargetState.UNSECURED);
801
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState,
802
+ this.platform.Characteristic.LockCurrentState.UNSECURED);
803
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
1064
804
  } else {
1065
- this.lockService?.updateCharacteristic(
1066
- this.platform.Characteristic.LockTargetState,
1067
- this.platform.Characteristic.LockTargetState.SECURED,
1068
- );
1069
- this.lockService?.updateCharacteristic(
1070
- this.platform.Characteristic.LockCurrentState,
1071
- this.platform.Characteristic.LockCurrentState.SECURED,
1072
- );
1073
- this.debugLog(
1074
- `Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`,
1075
- );
805
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState,
806
+ this.platform.Characteristic.LockTargetState.SECURED);
807
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState,
808
+ this.platform.Characteristic.LockCurrentState.SECURED);
809
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
1076
810
  }
1077
811
  }
1078
812
  this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
1079
- } else if (this.device.bot?.deviceType === "faucet") {
813
+ } else if (this.device.bot?.deviceType === 'faucet') {
1080
814
  if (this.On === undefined) {
1081
815
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1082
816
  } else {
1083
817
  if (this.On) {
1084
- this.faucetService?.updateCharacteristic(
1085
- this.platform.Characteristic.Active,
1086
- this.platform.Characteristic.Active.ACTIVE,
1087
- );
1088
- this.debugLog(
1089
- `Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`,
1090
- );
818
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active,
819
+ this.platform.Characteristic.Active.ACTIVE);
820
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
1091
821
  } else {
1092
- this.faucetService?.updateCharacteristic(
1093
- this.platform.Characteristic.Active,
1094
- this.platform.Characteristic.Active.INACTIVE,
1095
- );
1096
- this.debugLog(
1097
- `Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`,
1098
- );
822
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active,
823
+ this.platform.Characteristic.Active.INACTIVE);
824
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
1099
825
  }
1100
826
  }
1101
827
  this.debugLog(`Bot: ${this.accessory.displayName} Faucet On: ${this.On}`);
1102
- } else if (this.device.bot?.deviceType === "fan") {
828
+ } else if (this.device.bot?.deviceType === 'fan') {
1103
829
  if (this.On === undefined) {
1104
830
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1105
831
  } else {
1106
832
  if (this.On) {
1107
- this.fanService?.updateCharacteristic(
1108
- this.platform.Characteristic.On,
1109
- this.On,
1110
- );
1111
- this.debugLog(
1112
- `Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
1113
- );
833
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
834
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
1114
835
  } else {
1115
- this.fanService?.updateCharacteristic(
1116
- this.platform.Characteristic.On,
1117
- this.On,
1118
- );
1119
- this.debugLog(
1120
- `Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
1121
- );
836
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
837
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
1122
838
  }
1123
839
  }
1124
840
  this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
1125
- } else if (this.device.bot?.deviceType === "stateful") {
841
+ } else if (this.device.bot?.deviceType === 'stateful') {
1126
842
  if (this.On === undefined) {
1127
843
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1128
844
  } else {
1129
845
  if (this.On) {
1130
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1131
- this.platform.Characteristic.ProgrammableSwitchEvent,
1132
- this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
1133
- );
1134
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1135
- this.platform.Characteristic.ProgrammableSwitchOutputState,
1136
- 1,
1137
- );
1138
- this.debugLog(
1139
- `Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`,
1140
- );
846
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent,
847
+ this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
848
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
849
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
1141
850
  } else {
1142
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1143
- this.platform.Characteristic.ProgrammableSwitchEvent,
1144
- this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
1145
- );
1146
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1147
- this.platform.Characteristic.ProgrammableSwitchOutputState,
1148
- 0,
1149
- );
1150
- this.debugLog(
1151
- `Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`,
1152
- );
851
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent,
852
+ this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
853
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
854
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
1153
855
  }
1154
856
  }
1155
- this.debugLog(
1156
- `Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`,
1157
- );
1158
- } else if (this.device.bot?.deviceType === "switch") {
857
+ this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
858
+ } else if (this.device.bot?.deviceType === 'switch') {
1159
859
  if (this.On === undefined) {
1160
860
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1161
861
  } else {
1162
- this.switchService?.updateCharacteristic(
1163
- this.platform.Characteristic.On,
1164
- this.On,
1165
- );
1166
- this.debugLog(
1167
- `Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
1168
- );
862
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
863
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
1169
864
  }
1170
865
  } else {
1171
866
  if (this.On === undefined) {
1172
867
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
1173
868
  } else {
1174
- this.outletService?.updateCharacteristic(
1175
- this.platform.Characteristic.On,
1176
- this.On,
1177
- );
1178
- this.debugLog(
1179
- `Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
1180
- );
869
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
870
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
1181
871
  }
1182
872
  }
1183
873
  if (this.device.ble) {
1184
874
  if (this.BatteryLevel === undefined) {
1185
- this.debugLog(
1186
- `Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
1187
- );
875
+ this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
1188
876
  } else {
1189
- this.batteryService?.updateCharacteristic(
1190
- this.platform.Characteristic.BatteryLevel,
1191
- this.BatteryLevel,
1192
- );
1193
- this.debugLog(
1194
- `Bot: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`,
1195
- );
877
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
878
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
1196
879
  }
1197
880
  if (this.StatusLowBattery === undefined) {
1198
- this.debugLog(
1199
- `Bot: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`,
1200
- );
881
+ this.debugLog(`Bot: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
1201
882
  } else {
1202
- this.batteryService?.updateCharacteristic(
1203
- this.platform.Characteristic.StatusLowBattery,
1204
- this.StatusLowBattery,
1205
- );
1206
- this.debugLog(
1207
- `Bot: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`,
1208
- );
883
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
884
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
1209
885
  }
1210
886
  }
1211
887
  }
1212
888
 
1213
889
  public apiError(e: any) {
1214
- if (this.device.bot?.deviceType === "garagedoor") {
1215
- this.garageDoorService?.updateCharacteristic(
1216
- this.platform.Characteristic.TargetDoorState,
1217
- e,
1218
- );
1219
- this.garageDoorService?.updateCharacteristic(
1220
- this.platform.Characteristic.CurrentDoorState,
1221
- e,
1222
- );
1223
- this.garageDoorService?.updateCharacteristic(
1224
- this.platform.Characteristic.ObstructionDetected,
1225
- e,
1226
- );
1227
- } else if (this.device.bot?.deviceType === "door") {
1228
- this.doorService?.updateCharacteristic(
1229
- this.platform.Characteristic.TargetPosition,
1230
- e,
1231
- );
1232
- this.doorService?.updateCharacteristic(
1233
- this.platform.Characteristic.CurrentPosition,
1234
- e,
1235
- );
1236
- this.doorService?.updateCharacteristic(
1237
- this.platform.Characteristic.PositionState,
1238
- e,
1239
- );
1240
- } else if (this.device.bot?.deviceType === "window") {
1241
- this.windowService?.updateCharacteristic(
1242
- this.platform.Characteristic.TargetPosition,
1243
- e,
1244
- );
1245
- this.windowService?.updateCharacteristic(
1246
- this.platform.Characteristic.CurrentPosition,
1247
- e,
1248
- );
1249
- this.windowService?.updateCharacteristic(
1250
- this.platform.Characteristic.PositionState,
1251
- e,
1252
- );
1253
- } else if (this.device.bot?.deviceType === "windowcovering") {
1254
- this.windowCoveringService?.updateCharacteristic(
1255
- this.platform.Characteristic.TargetPosition,
1256
- e,
1257
- );
1258
- this.windowCoveringService?.updateCharacteristic(
1259
- this.platform.Characteristic.CurrentPosition,
1260
- e,
1261
- );
1262
- this.windowCoveringService?.updateCharacteristic(
1263
- this.platform.Characteristic.PositionState,
1264
- e,
1265
- );
1266
- } else if (this.device.bot?.deviceType === "lock") {
1267
- this.doorService?.updateCharacteristic(
1268
- this.platform.Characteristic.LockTargetState,
1269
- e,
1270
- );
1271
- this.doorService?.updateCharacteristic(
1272
- this.platform.Characteristic.LockCurrentState,
1273
- e,
1274
- );
1275
- } else if (this.device.bot?.deviceType === "faucet") {
1276
- this.faucetService?.updateCharacteristic(
1277
- this.platform.Characteristic.Active,
1278
- e,
1279
- );
1280
- } else if (this.device.bot?.deviceType === "fan") {
890
+ if (this.device.bot?.deviceType === 'garagedoor') {
891
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
892
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
893
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, e);
894
+ } else if (this.device.bot?.deviceType === 'door') {
895
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
896
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
897
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
898
+ } else if (this.device.bot?.deviceType === 'window') {
899
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
900
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
901
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
902
+ } else if (this.device.bot?.deviceType === 'windowcovering') {
903
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
904
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
905
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
906
+ } else if (this.device.bot?.deviceType === 'lock') {
907
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
908
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
909
+ } else if (this.device.bot?.deviceType === 'faucet') {
910
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, e);
911
+ } else if (this.device.bot?.deviceType === 'fan') {
1281
912
  this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
1282
- } else if (this.device.bot?.deviceType === "stateful") {
1283
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1284
- this.platform.Characteristic.ProgrammableSwitchEvent,
1285
- e,
1286
- );
1287
- this.statefulProgrammableSwitchService?.updateCharacteristic(
1288
- this.platform.Characteristic.ProgrammableSwitchOutputState,
1289
- e,
1290
- );
1291
- } else if (this.device.bot?.deviceType === "switch") {
1292
- this.switchService?.updateCharacteristic(
1293
- this.platform.Characteristic.On,
1294
- e,
1295
- );
913
+ } else if (this.device.bot?.deviceType === 'stateful') {
914
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
915
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
916
+ } else if (this.device.bot?.deviceType === 'switch') {
917
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
1296
918
  } else {
1297
- this.outletService?.updateCharacteristic(
1298
- this.platform.Characteristic.On,
1299
- e,
1300
- );
919
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
1301
920
  }
1302
921
  if (this.device.ble) {
1303
- this.batteryService?.updateCharacteristic(
1304
- this.platform.Characteristic.BatteryLevel,
1305
- e,
1306
- );
1307
- this.batteryService?.updateCharacteristic(
1308
- this.platform.Characteristic.StatusLowBattery,
1309
- e,
1310
- );
922
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
923
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1311
924
  }
1312
925
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1313
926
  }
1314
927
 
1315
- private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
928
+ private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
1316
929
  switch (push.data.statusCode) {
1317
930
  case 151:
1318
- this.errorLog(
1319
- `Bot: ${this.accessory.displayName} Command not supported by this device type.`,
1320
- );
931
+ this.errorLog(`Bot: ${this.accessory.displayName} Command not supported by this device type.`);
1321
932
  break;
1322
933
  case 152:
1323
934
  this.errorLog(`Bot: ${this.accessory.displayName} Device not found.`);
1324
935
  break;
1325
936
  case 160:
1326
- this.errorLog(
1327
- `Bot: ${this.accessory.displayName} Command is not supported.`,
1328
- );
937
+ this.errorLog(`Bot: ${this.accessory.displayName} Command is not supported.`);
1329
938
  break;
1330
939
  case 161:
1331
940
  this.errorLog(`Bot: ${this.accessory.displayName} Device is offline.`);
1332
941
  this.offlineOff();
1333
942
  break;
1334
943
  case 171:
1335
- this.errorLog(
1336
- `Bot: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
1337
- );
944
+ this.errorLog(`Bot: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
1338
945
  this.offlineOff();
1339
946
  break;
1340
947
  case 190:
1341
- this.errorLog(
1342
- `Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
1343
- ` Or command: ${JSON.stringify(push.data)} format is invalid`,
1344
- );
948
+ this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
949
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
1345
950
  break;
1346
951
  case 100:
1347
- this.debugLog(
1348
- `Bot: ${this.accessory.displayName} Command successfully sent.`,
1349
- );
952
+ this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
1350
953
  break;
1351
954
  default:
1352
955
  this.debugLog(`Bot: ${this.accessory.displayName} Unknown statusCode.`);
@@ -1356,14 +959,10 @@ export class Bot {
1356
959
  private offlineOff() {
1357
960
  if (this.device.offline) {
1358
961
  this.On = false;
1359
- if (this.device.bot?.deviceType === "switch") {
1360
- this.switchService
1361
- ?.getCharacteristic(this.platform.Characteristic.On)
1362
- .updateValue(this.On);
962
+ if (this.device.bot?.deviceType === 'switch') {
963
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
1363
964
  } else {
1364
- this.outletService
1365
- ?.getCharacteristic(this.platform.Characteristic.On)
1366
- .updateValue(this.On);
965
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
1367
966
  }
1368
967
  }
1369
968
  }
@@ -1371,49 +970,39 @@ export class Bot {
1371
970
  /**
1372
971
  * Handle requests to set the "On" characteristic
1373
972
  */
1374
- private handleOnSet(value: homebridge.CharacteristicValue) {
1375
- if (this.device.bot?.deviceType === "garagedoor") {
1376
- this.debugLog(
1377
- `Bot: ${this.accessory.displayName} TargetDoorState: ${value}`,
1378
- );
973
+ private handleOnSet(value: CharacteristicValue) {
974
+ if (this.device.bot?.deviceType === 'garagedoor') {
975
+ this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
1379
976
  if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
1380
977
  this.On = false;
1381
978
  } else {
1382
979
  this.On = true;
1383
980
  }
1384
- } else if (
1385
- this.device.bot?.deviceType === "door" ||
1386
- this.device.bot?.deviceType === "window" ||
1387
- this.device.bot?.deviceType === "windowcovering"
1388
- ) {
1389
- this.debugLog(
1390
- `Bot: ${this.accessory.displayName} TargetPosition: ${value}`,
1391
- );
981
+ } else if (this.device.bot?.deviceType === 'door'
982
+ || this.device.bot?.deviceType === 'window'
983
+ || this.device.bot?.deviceType === 'windowcovering') {
984
+ this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
1392
985
  if (value === 0) {
1393
986
  this.On = false;
1394
987
  } else {
1395
988
  this.On = true;
1396
989
  }
1397
- } else if (this.device.bot?.deviceType === "lock") {
1398
- this.debugLog(
1399
- `Bot: ${this.accessory.displayName} LockTargetState: ${value}`,
1400
- );
990
+ } else if (this.device.bot?.deviceType === 'lock') {
991
+ this.debugLog(`Bot: ${this.accessory.displayName} LockTargetState: ${value}`);
1401
992
  if (value === this.platform.Characteristic.LockTargetState.SECURED) {
1402
993
  this.On = false;
1403
994
  } else {
1404
995
  this.On = true;
1405
996
  }
1406
- } else if (this.device.bot?.deviceType === "faucet") {
997
+ } else if (this.device.bot?.deviceType === 'faucet') {
1407
998
  this.debugLog(`Bot: ${this.accessory.displayName} Active: ${value}`);
1408
999
  if (value === this.platform.Characteristic.Active.INACTIVE) {
1409
1000
  this.On = false;
1410
1001
  } else {
1411
1002
  this.On = true;
1412
1003
  }
1413
- } else if (this.device.bot?.deviceType === "stateful") {
1414
- this.debugLog(
1415
- `Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`,
1416
- );
1004
+ } else if (this.device.bot?.deviceType === 'stateful') {
1005
+ this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
1417
1006
  if (value === 0) {
1418
1007
  this.On = false;
1419
1008
  } else {
@@ -1426,247 +1015,186 @@ export class Bot {
1426
1015
  this.doBotUpdate.next();
1427
1016
  }
1428
1017
 
1429
- config(device: settings.device & settings.devicesConfig) {
1018
+ config(device: device & devicesConfig) {
1430
1019
  let config = {};
1431
1020
  if (device.bot) {
1432
1021
  config = device.bot;
1433
1022
  }
1434
1023
  if (device.ble) {
1435
- config["ble"] = device.ble;
1024
+ config['ble'] = device.ble;
1436
1025
  }
1437
1026
  if (device.logging !== undefined) {
1438
- config["logging"] = device.logging;
1027
+ config['logging'] = device.logging;
1439
1028
  }
1440
1029
  if (device.refreshRate !== undefined) {
1441
- config["refreshRate"] = device.refreshRate;
1030
+ config['refreshRate'] = device.refreshRate;
1442
1031
  }
1443
1032
  if (device.scanDuration !== undefined) {
1444
- config["scanDuration"] = device.scanDuration;
1033
+ config['scanDuration'] = device.scanDuration;
1445
1034
  }
1446
1035
  if (Object.entries(config).length !== 0) {
1447
- this.warnLog(
1448
- `Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
1449
- );
1036
+ this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1450
1037
  }
1451
1038
  }
1452
1039
 
1453
- refreshRate(device: settings.device & settings.devicesConfig) {
1040
+ refreshRate(device: device & devicesConfig) {
1454
1041
  if (device.refreshRate) {
1455
- this.deviceRefreshRate = this.accessory.context.refreshRate =
1456
- device.refreshRate;
1457
- this.debugLog(
1458
- `Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
1459
- );
1042
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1043
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
1460
1044
  } else if (this.platform.config.options!.refreshRate) {
1461
- this.deviceRefreshRate = this.accessory.context.refreshRate =
1462
- this.platform.config.options!.refreshRate;
1463
- this.debugLog(
1464
- `Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
1465
- );
1045
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
1046
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
1466
1047
  }
1467
1048
  }
1468
1049
 
1469
- scan(device: settings.device & settings.devicesConfig) {
1050
+ scan(device: device & devicesConfig) {
1470
1051
  if (device.scanDuration) {
1471
- this.scanDuration = this.accessory.context.scanDuration =
1472
- device.scanDuration;
1052
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
1473
1053
  if (device.ble) {
1474
- this.debugLog(
1475
- `Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
1476
- );
1054
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
1477
1055
  }
1478
1056
  } else {
1479
1057
  this.scanDuration = this.accessory.context.scanDuration = 1;
1480
1058
  if (this.device.ble) {
1481
- this.debugLog(
1482
- `Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
1483
- );
1059
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
1484
1060
  }
1485
1061
  }
1486
1062
  }
1487
1063
 
1488
- logs(device: settings.device & settings.devicesConfig) {
1064
+ logs(device: device & devicesConfig) {
1489
1065
  if (this.platform.debugMode) {
1490
- this.deviceLogging = this.accessory.context.logging = "debugMode";
1491
- this.debugLog(
1492
- `Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
1493
- );
1066
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
1067
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
1494
1068
  } else if (device.logging) {
1495
1069
  this.deviceLogging = this.accessory.context.logging = device.logging;
1496
- this.debugLog(
1497
- `Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
1498
- );
1070
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
1499
1071
  } else if (this.platform.config.options?.logging) {
1500
- this.deviceLogging = this.accessory.context.logging =
1501
- this.platform.config.options?.logging;
1502
- this.debugLog(
1503
- `Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
1504
- );
1072
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
1073
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
1505
1074
  } else {
1506
- this.deviceLogging = this.accessory.context.logging = "standard";
1507
- this.debugLog(
1508
- `Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
1509
- );
1075
+ this.deviceLogging = this.accessory.context.logging = 'standard';
1076
+ this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
1510
1077
  }
1511
1078
  }
1512
1079
 
1513
- PressOrSwitch(device: settings.device & settings.devicesConfig) {
1080
+ PressOrSwitch(device: device & devicesConfig) {
1514
1081
  if (!device.bot?.mode) {
1515
- this.botMode = "switch";
1516
- this.warnLog(
1517
- `Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`,
1518
- );
1519
- this.warnLog(
1520
- `Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`,
1521
- );
1522
- } else if (device.bot?.mode === "switch") {
1523
- this.botMode = "switch";
1524
- this.debugLog(
1525
- `Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`,
1526
- );
1527
- } else if (device.bot?.mode === "press") {
1528
- this.botMode = "press";
1529
- this.debugLog(
1530
- `Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`,
1531
- );
1082
+ this.botMode = 'switch';
1083
+ this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
1084
+ this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
1085
+ } else if (device.bot?.mode === 'switch') {
1086
+ this.botMode = 'switch';
1087
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1088
+ } else if (device.bot?.mode === 'press') {
1089
+ this.botMode = 'press';
1090
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1532
1091
  } else {
1533
- throw new Error(
1534
- `Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
1535
- );
1092
+ throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1536
1093
  }
1537
1094
  }
1538
1095
 
1539
- public removeOutletService(accessory: homebridge.PlatformAccessory) {
1096
+ allowPushChanges(device: device & devicesConfig) {
1097
+ if (device.bot?.allowPush) {
1098
+ this.allowPush = true;
1099
+ } else {
1100
+ this.allowPush = false;
1101
+ }
1102
+ this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1103
+ }
1104
+
1105
+ public removeOutletService(accessory: PlatformAccessory) {
1540
1106
  // If outletService still pressent, then remove first
1541
- this.outletService = this.accessory.getService(
1542
- this.platform.Service.Outlet,
1543
- );
1107
+ this.outletService = this.accessory.getService(this.platform.Service.Outlet);
1544
1108
  if (this.outletService) {
1545
- this.warnLog(
1546
- `Bot: ${accessory.displayName} Removing Leftover Outlet Service`,
1547
- );
1109
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Outlet Service`);
1548
1110
  }
1549
1111
  accessory.removeService(this.outletService!);
1550
1112
  }
1551
1113
 
1552
- public removeGarageDoorService(accessory: homebridge.PlatformAccessory) {
1114
+ public removeGarageDoorService(accessory: PlatformAccessory) {
1553
1115
  // If garageDoorService still pressent, then remove first
1554
- this.garageDoorService = this.accessory.getService(
1555
- this.platform.Service.GarageDoorOpener,
1556
- );
1116
+ this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
1557
1117
  if (this.garageDoorService) {
1558
- this.warnLog(
1559
- `Bot: ${accessory.displayName} Removing Leftover Garage Door Service`,
1560
- );
1118
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Garage Door Service`);
1561
1119
  }
1562
1120
  accessory.removeService(this.garageDoorService!);
1563
1121
  }
1564
1122
 
1565
- public removeDoorService(accessory: homebridge.PlatformAccessory) {
1123
+ public removeDoorService(accessory: PlatformAccessory) {
1566
1124
  // If doorService still pressent, then remove first
1567
1125
  this.doorService = this.accessory.getService(this.platform.Service.Door);
1568
1126
  if (this.doorService) {
1569
- this.warnLog(
1570
- `Bot: ${accessory.displayName} Removing Leftover Door Service`,
1571
- );
1127
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Door Service`);
1572
1128
  }
1573
1129
  accessory.removeService(this.doorService!);
1574
1130
  }
1575
1131
 
1576
- public removeLockService(accessory: homebridge.PlatformAccessory) {
1132
+ public removeLockService(accessory: PlatformAccessory) {
1577
1133
  // If lockService still pressent, then remove first
1578
- this.lockService = this.accessory.getService(
1579
- this.platform.Service.LockMechanism,
1580
- );
1134
+ this.lockService = this.accessory.getService(this.platform.Service.LockMechanism);
1581
1135
  if (this.lockService) {
1582
- this.warnLog(
1583
- `Bot: ${accessory.displayName} Removing Leftover Lock Service`,
1584
- );
1136
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Lock Service`);
1585
1137
  }
1586
1138
  accessory.removeService(this.lockService!);
1587
1139
  }
1588
1140
 
1589
- public removeFaucetService(accessory: homebridge.PlatformAccessory) {
1141
+ public removeFaucetService(accessory: PlatformAccessory) {
1590
1142
  // If faucetService still pressent, then remove first
1591
- this.faucetService = this.accessory.getService(
1592
- this.platform.Service.Faucet,
1593
- );
1143
+ this.faucetService = this.accessory.getService(this.platform.Service.Faucet);
1594
1144
  if (this.faucetService) {
1595
- this.warnLog(
1596
- `Bot: ${accessory.displayName} Removing Leftover Faucet Service`,
1597
- );
1145
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Faucet Service`);
1598
1146
  }
1599
1147
  accessory.removeService(this.faucetService!);
1600
1148
  }
1601
1149
 
1602
- public removeFanService(accessory: homebridge.PlatformAccessory) {
1150
+ public removeFanService(accessory: PlatformAccessory) {
1603
1151
  // If fanService still pressent, then remove first
1604
1152
  this.fanService = this.accessory.getService(this.platform.Service.Fan);
1605
1153
  if (this.fanService) {
1606
- this.warnLog(
1607
- `Bot: ${accessory.displayName} Removing Leftover Fan Service`,
1608
- );
1154
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Fan Service`);
1609
1155
  }
1610
1156
  accessory.removeService(this.fanService!);
1611
1157
  }
1612
1158
 
1613
- public removeWindowService(accessory: homebridge.PlatformAccessory) {
1159
+ public removeWindowService(accessory: PlatformAccessory) {
1614
1160
  // If windowService still pressent, then remove first
1615
- this.windowService = this.accessory.getService(
1616
- this.platform.Service.Window,
1617
- );
1161
+ this.windowService = this.accessory.getService(this.platform.Service.Window);
1618
1162
  if (this.windowService) {
1619
- this.warnLog(
1620
- `Bot: ${accessory.displayName} Removing Leftover Window Service`,
1621
- );
1163
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Window Service`);
1622
1164
  }
1623
1165
  accessory.removeService(this.windowService!);
1624
1166
  }
1625
1167
 
1626
- public removeWindowCoveringService(accessory: homebridge.PlatformAccessory) {
1168
+ public removeWindowCoveringService(accessory: PlatformAccessory) {
1627
1169
  // If windowCoveringService still pressent, then remove first
1628
- this.windowCoveringService = this.accessory.getService(
1629
- this.platform.Service.WindowCovering,
1630
- );
1170
+ this.windowCoveringService = this.accessory.getService(this.platform.Service.WindowCovering);
1631
1171
  if (this.windowCoveringService) {
1632
- this.warnLog(
1633
- `Bot: ${accessory.displayName} Removing Leftover Window Covering Service`,
1634
- );
1172
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Window Covering Service`);
1635
1173
  }
1636
1174
  accessory.removeService(this.windowCoveringService!);
1637
1175
  }
1638
1176
 
1639
- public removeStatefulProgrammableSwitchService(
1640
- accessory: homebridge.PlatformAccessory,
1641
- ) {
1177
+ public removeStatefulProgrammableSwitchService(accessory: PlatformAccessory) {
1642
1178
  // If statefulProgrammableSwitchService still pressent, then remove first
1643
- this.statefulProgrammableSwitchService = this.accessory.getService(
1644
- this.platform.Service.StatefulProgrammableSwitch,
1645
- );
1179
+ this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
1646
1180
  if (this.statefulProgrammableSwitchService) {
1647
- this.warnLog(
1648
- `Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`,
1649
- );
1181
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
1650
1182
  }
1651
1183
  accessory.removeService(this.statefulProgrammableSwitchService!);
1652
1184
  }
1653
1185
 
1654
- public removeSwitchService(accessory: homebridge.PlatformAccessory) {
1186
+ public removeSwitchService(accessory: PlatformAccessory) {
1655
1187
  // If switchService still pressent, then remove first
1656
- this.switchService = this.accessory.getService(
1657
- this.platform.Service.Switch,
1658
- );
1188
+ this.switchService = this.accessory.getService(this.platform.Service.Switch);
1659
1189
  if (this.switchService) {
1660
- this.warnLog(
1661
- `Bot: ${accessory.displayName} Removing Leftover Switch Service`,
1662
- );
1190
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Switch Service`);
1663
1191
  }
1664
1192
  accessory.removeService(this.switchService!);
1665
1193
  }
1666
1194
 
1667
1195
  /**
1668
- * Logging for Device
1669
- */
1196
+ * Logging for Device
1197
+ */
1670
1198
  infoLog(...log: any[]) {
1671
1199
  if (this.enablingDeviceLogging()) {
1672
1200
  this.platform.log.info(String(...log));
@@ -1687,8 +1215,8 @@ export class Bot {
1687
1215
 
1688
1216
  debugLog(...log: any[]) {
1689
1217
  if (this.enablingDeviceLogging()) {
1690
- if (this.deviceLogging === "debug") {
1691
- this.platform.log.info("[DEBUG]", String(...log));
1218
+ if (this.deviceLogging === 'debug') {
1219
+ this.platform.log.info('[DEBUG]', String(...log));
1692
1220
  } else {
1693
1221
  this.platform.log.debug(String(...log));
1694
1222
  }
@@ -1696,8 +1224,6 @@ export class Bot {
1696
1224
  }
1697
1225
 
1698
1226
  enablingDeviceLogging(): boolean {
1699
- return (
1700
- this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
1701
- );
1227
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
1702
1228
  }
1703
1229
  }