@switchbot/homebridge-switchbot 1.8.2 → 1.10.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 (115) hide show
  1. package/.eslintrc +3 -1
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +5 -0
  12. package/.vscode/settings.json +27 -0
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +4 -2
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +101 -86
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +15 -15
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +60 -71
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +2 -2
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +33 -31
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +2 -2
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +71 -71
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +2 -2
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +74 -76
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +2 -2
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +29 -27
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +2 -2
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +34 -32
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +7 -7
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +18 -23
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/irdevices/airconditioners.d.ts +5 -2
  50. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  51. package/dist/irdevices/airconditioners.js +61 -56
  52. package/dist/irdevices/airconditioners.js.map +1 -1
  53. package/dist/irdevices/airpurifiers.d.ts +2 -2
  54. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  55. package/dist/irdevices/airpurifiers.js +12 -17
  56. package/dist/irdevices/airpurifiers.js.map +1 -1
  57. package/dist/irdevices/cameras.d.ts +2 -2
  58. package/dist/irdevices/cameras.d.ts.map +1 -1
  59. package/dist/irdevices/cameras.js +10 -13
  60. package/dist/irdevices/cameras.js.map +1 -1
  61. package/dist/irdevices/fans.d.ts +2 -2
  62. package/dist/irdevices/fans.d.ts.map +1 -1
  63. package/dist/irdevices/fans.js +15 -17
  64. package/dist/irdevices/fans.js.map +1 -1
  65. package/dist/irdevices/lights.d.ts +2 -2
  66. package/dist/irdevices/lights.d.ts.map +1 -1
  67. package/dist/irdevices/lights.js +10 -13
  68. package/dist/irdevices/lights.js.map +1 -1
  69. package/dist/irdevices/others.d.ts +2 -2
  70. package/dist/irdevices/others.d.ts.map +1 -1
  71. package/dist/irdevices/others.js +10 -13
  72. package/dist/irdevices/others.js.map +1 -1
  73. package/dist/irdevices/tvs.d.ts +2 -2
  74. package/dist/irdevices/tvs.d.ts.map +1 -1
  75. package/dist/irdevices/tvs.js +22 -30
  76. package/dist/irdevices/tvs.js.map +1 -1
  77. package/dist/irdevices/vacuumcleaners.d.ts +2 -2
  78. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  79. package/dist/irdevices/vacuumcleaners.js +11 -13
  80. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  81. package/dist/irdevices/waterheaters.d.ts +2 -2
  82. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  83. package/dist/irdevices/waterheaters.js +10 -13
  84. package/dist/irdevices/waterheaters.js.map +1 -1
  85. package/dist/platform.d.ts +3 -3
  86. package/dist/platform.d.ts.map +1 -1
  87. package/dist/platform.js +13 -14
  88. package/dist/platform.js.map +1 -1
  89. package/dist/settings.d.ts +2 -0
  90. package/dist/settings.d.ts.map +1 -1
  91. package/dist/settings.js.map +1 -1
  92. package/homebridge-ui/public/index.html +231 -245
  93. package/homebridge-ui/server.js +2 -4
  94. package/nodemon.json +2 -4
  95. package/package.json +18 -12
  96. package/src/devices/bots.ts +228 -186
  97. package/src/devices/colorbulb.ts +90 -84
  98. package/src/devices/contact.ts +85 -78
  99. package/src/devices/curtains.ts +152 -135
  100. package/src/devices/humidifiers.ts +162 -137
  101. package/src/devices/meters.ts +76 -73
  102. package/src/devices/motion.ts +87 -78
  103. package/src/devices/plugs.ts +27 -31
  104. package/src/irdevices/airconditioners.ts +91 -59
  105. package/src/irdevices/airpurifiers.ts +22 -23
  106. package/src/irdevices/cameras.ts +18 -19
  107. package/src/irdevices/fans.ts +27 -25
  108. package/src/irdevices/lights.ts +18 -20
  109. package/src/irdevices/others.ts +18 -19
  110. package/src/irdevices/tvs.ts +33 -41
  111. package/src/irdevices/vacuumcleaners.ts +19 -19
  112. package/src/irdevices/waterheaters.ts +21 -31
  113. package/src/platform.ts +32 -33
  114. package/src/settings.ts +9 -18
  115. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -1,4 +1,3 @@
1
-
2
1
  import { AxiosResponse } from 'axios';
3
2
  import { interval, Subject } from 'rxjs';
4
3
  import { SwitchBotPlatform } from '../platform';
@@ -25,7 +24,6 @@ export class Bot {
25
24
  private windowCoveringService?: Service;
26
25
  private statefulProgrammableSwitchService?: Service;
27
26
 
28
-
29
27
  // Characteristic Values
30
28
  On!: CharacteristicValue;
31
29
  OnCached!: CharacteristicValue;
@@ -47,6 +45,7 @@ export class Bot {
47
45
 
48
46
  // Config
49
47
  botMode!: string;
48
+ allowPush?: boolean;
50
49
  scanDuration!: number;
51
50
  deviceLogging!: string;
52
51
  deviceRefreshRate!: number;
@@ -58,16 +57,13 @@ export class Bot {
58
57
  botUpdateInProgress!: boolean;
59
58
  doBotUpdate!: Subject<void>;
60
59
 
61
- constructor(
62
- private readonly platform: SwitchBotPlatform,
63
- private accessory: PlatformAccessory,
64
- public device: device & devicesConfig,
65
- ) {
60
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
66
61
  // default placeholders
67
62
  this.logs(device);
68
63
  this.scan(device);
69
64
  this.refreshRate(device);
70
65
  this.PressOrSwitch(device);
66
+ this.allowPushChanges(device);
71
67
  this.config(device);
72
68
  if (this.On === undefined) {
73
69
  this.On = false;
@@ -112,9 +108,8 @@ export class Bot {
112
108
  this.removeStatefulProgrammableSwitchService(accessory);
113
109
 
114
110
  // Add switchService
115
- (this.switchService =
116
- accessory.getService(this.platform.Service.Switch) ||
117
- accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
111
+ (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
112
+ `${accessory.displayName} Switch`;
118
113
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
119
114
 
120
115
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -132,8 +127,8 @@ export class Bot {
132
127
 
133
128
  // Add switchService
134
129
  (this.garageDoorService =
135
- accessory.getService(this.platform.Service.GarageDoorOpener) ||
136
- accessory.addService(this.platform.Service.GarageDoorOpener)), `${accessory.displayName} Garage Door Opener`;
130
+ accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
131
+ `${accessory.displayName} Garage Door Opener`;
137
132
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
138
133
 
139
134
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -151,19 +146,20 @@ export class Bot {
151
146
  this.removeStatefulProgrammableSwitchService(accessory);
152
147
 
153
148
  // Add switchService
154
- (this.doorService =
155
- accessory.getService(this.platform.Service.Door) ||
156
- accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
149
+ (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
150
+ `${accessory.displayName} Door`;
157
151
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
158
152
 
159
153
  this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
160
- this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
154
+ this.doorService
155
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
161
156
  .setProps({
162
157
  validValues: [0, 100],
163
158
  minValue: 0,
164
159
  maxValue: 100,
165
160
  minStep: 100,
166
- }).onSet(this.handleOnSet.bind(this));
161
+ })
162
+ .onSet(this.handleOnSet.bind(this));
167
163
  this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
168
164
  } else if (device.bot?.deviceType === 'window') {
169
165
  this.removeFanService(accessory);
@@ -177,19 +173,20 @@ export class Bot {
177
173
  this.removeStatefulProgrammableSwitchService(accessory);
178
174
 
179
175
  // Add switchService
180
- (this.windowService =
181
- accessory.getService(this.platform.Service.Window) ||
182
- accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
176
+ (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
177
+ `${accessory.displayName} Window`;
183
178
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
184
179
 
185
180
  this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
186
- this.windowService.getCharacteristic(this.platform.Characteristic.TargetPosition)
181
+ this.windowService
182
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
187
183
  .setProps({
188
184
  validValues: [0, 100],
189
185
  minValue: 0,
190
186
  maxValue: 100,
191
187
  minStep: 100,
192
- }).onSet(this.handleOnSet.bind(this));
188
+ })
189
+ .onSet(this.handleOnSet.bind(this));
193
190
  this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
194
191
  } else if (device.bot?.deviceType === 'windowcovering') {
195
192
  this.removeFanService(accessory);
@@ -204,18 +201,20 @@ export class Bot {
204
201
 
205
202
  // Add switchService
206
203
  (this.windowCoveringService =
207
- accessory.getService(this.platform.Service.WindowCovering) ||
208
- accessory.addService(this.platform.Service.WindowCovering)), `${accessory.displayName} Window Covering`;
204
+ accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
205
+ `${accessory.displayName} Window Covering`;
209
206
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
210
207
 
211
208
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
212
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.TargetPosition)
209
+ this.windowCoveringService
210
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
213
211
  .setProps({
214
212
  validValues: [0, 100],
215
213
  minValue: 0,
216
214
  maxValue: 100,
217
215
  minStep: 100,
218
- }).onSet(this.handleOnSet.bind(this));
216
+ })
217
+ .onSet(this.handleOnSet.bind(this));
219
218
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
220
219
  } else if (device.bot?.deviceType === 'lock') {
221
220
  this.removeFanService(accessory);
@@ -229,9 +228,8 @@ export class Bot {
229
228
  this.removeStatefulProgrammableSwitchService(accessory);
230
229
 
231
230
  // Add switchService
232
- (this.lockService =
233
- accessory.getService(this.platform.Service.LockMechanism) ||
234
- accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
231
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
232
+ `${accessory.displayName} Lock`;
235
233
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
236
234
 
237
235
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -248,9 +246,8 @@ export class Bot {
248
246
  this.removeStatefulProgrammableSwitchService(accessory);
249
247
 
250
248
  // Add switchService
251
- (this.faucetService =
252
- accessory.getService(this.platform.Service.Faucet) ||
253
- accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
249
+ (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
250
+ `${accessory.displayName} Faucet`;
254
251
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
255
252
 
256
253
  this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -267,9 +264,8 @@ export class Bot {
267
264
  this.removeStatefulProgrammableSwitchService(accessory);
268
265
 
269
266
  // Add switchService
270
- (this.fanService =
271
- accessory.getService(this.platform.Service.Fan) ||
272
- accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
267
+ (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
268
+ `${accessory.displayName} Fan`;
273
269
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
274
270
 
275
271
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -288,11 +284,13 @@ export class Bot {
288
284
  // Add switchService
289
285
  (this.statefulProgrammableSwitchService =
290
286
  accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
291
- accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
287
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
288
+ `${accessory.displayName} Stateful Programmable Switch`;
292
289
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
293
290
 
294
291
  this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
295
- this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
292
+ this.statefulProgrammableSwitchService
293
+ .getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
296
294
  .onSet(this.handleOnSet.bind(this));
297
295
  } else {
298
296
  this.removeFanService(accessory);
@@ -306,9 +304,8 @@ export class Bot {
306
304
  this.removeStatefulProgrammableSwitchService(accessory);
307
305
 
308
306
  // Add outletService
309
- (this.outletService =
310
- accessory.getService(this.platform.Service.Outlet) ||
311
- accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
307
+ (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
308
+ `${accessory.displayName} Outlet`;
312
309
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
313
310
 
314
311
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
@@ -322,12 +319,10 @@ export class Bot {
322
319
  accessory.removeService(this.batteryService!);
323
320
  } else if (device.ble && !this.batteryService) {
324
321
  this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
325
- (this.batteryService =
326
- this.accessory.getService(this.platform.Service.Battery) ||
327
- this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
322
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
323
+ `${accessory.displayName} Battery`;
328
324
 
329
325
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
330
-
331
326
  } else {
332
327
  this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
333
328
  }
@@ -361,12 +356,10 @@ export class Bot {
361
356
  } catch (e: any) {
362
357
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
363
358
  if (this.deviceLogging === 'debug') {
364
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
365
- + ` Error Message: ${JSON.stringify(e.message)}`);
359
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
366
360
  }
367
361
  if (this.platform.debugMode) {
368
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
369
- + ` Error: ${JSON.stringify(e)}`);
362
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
370
363
  }
371
364
  }
372
365
  this.botUpdateInProgress = false;
@@ -458,67 +451,76 @@ export class Bot {
458
451
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
459
452
  const switchbot = await this.platform.connectBLE();
460
453
  // Convert to BLE Address
461
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
454
+ this.device.bleMac = this.device
455
+ .deviceId!.match(/.{1,2}/g)!
456
+ .join(':')
457
+ .toLowerCase();
462
458
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
463
459
  // Start to monitor advertisement packets
464
460
  if (switchbot === false) {
465
461
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
466
462
  }
467
- switchbot.startScan({
468
- model: 'H',
469
- id: this.device.bleMac,
470
- }).then(() => {
471
- // Set an event hander
472
- switchbot.onadvertisement = (ad: ad) => {
473
- this.serviceData = ad.serviceData;
474
- this.mode = ad.serviceData.mode;
475
- this.state = ad.serviceData.state;
476
- this.battery = ad.serviceData.battery;
477
- this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
478
- this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
479
- + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
480
-
481
- if (this.serviceData) {
482
- this.connected = true;
483
- this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
463
+ switchbot
464
+ .startScan({
465
+ model: 'H',
466
+ id: this.device.bleMac,
467
+ })
468
+ .then(() => {
469
+ // Set an event hander
470
+ switchbot.onadvertisement = (ad: ad) => {
471
+ this.serviceData = ad.serviceData;
472
+ this.mode = ad.serviceData.mode;
473
+ this.state = ad.serviceData.state;
474
+ this.battery = ad.serviceData.battery;
475
+ this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
476
+ this.debugLog(
477
+ `Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
478
+ ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
479
+ );
480
+
481
+ if (this.serviceData) {
482
+ this.connected = true;
483
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
484
+ } else {
485
+ this.connected = false;
486
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
487
+ }
488
+ };
489
+ // Wait 2 seconds
490
+ return switchbot.wait(this.scanDuration * 1000);
491
+ })
492
+ .then(async () => {
493
+ // Stop to monitor
494
+ switchbot.stopScan();
495
+ if (this.connected) {
496
+ this.parseStatus();
497
+ this.updateHomeKitCharacteristics();
484
498
  } else {
485
- this.connected = false;
486
- this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
499
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
500
+ if (this.platform.config.credentials?.openToken) {
501
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
502
+ this.SwitchToOpenAPI = true;
503
+ await this.openAPIRefreshStatus();
504
+ }
505
+ }
506
+ })
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(
511
+ `Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
512
+ );
513
+ }
514
+ if (this.platform.debugMode) {
515
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
487
516
  }
488
- };
489
- // Wait 2 seconds
490
- return switchbot.wait(this.scanDuration * 1000);
491
- }).then(async () => {
492
- // Stop to monitor
493
- switchbot.stopScan();
494
- if (this.connected) {
495
- this.parseStatus();
496
- this.updateHomeKitCharacteristics();
497
- } else {
498
- this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
499
517
  if (this.platform.config.credentials?.openToken) {
500
518
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
501
519
  this.SwitchToOpenAPI = true;
502
520
  await this.openAPIRefreshStatus();
503
521
  }
504
- }
505
- }).catch(async (e: any) => {
506
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
507
- if (this.deviceLogging === 'debug') {
508
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
509
- + ` Error Message: ${JSON.stringify(e.message)}`);
510
- }
511
- if (this.platform.debugMode) {
512
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
513
- + ` Error: ${JSON.stringify(e)}`);
514
- }
515
- if (this.platform.config.credentials?.openToken) {
516
- this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
517
- this.SwitchToOpenAPI = true;
518
- await this.openAPIRefreshStatus();
519
- }
520
- this.apiError(e);
521
- });
522
+ this.apiError(e);
523
+ });
522
524
  }
523
525
 
524
526
  private async openAPIRefreshStatus() {
@@ -533,12 +535,12 @@ export class Bot {
533
535
  } catch (e: any) {
534
536
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
535
537
  if (this.deviceLogging === 'debug') {
536
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
537
- + ` Error Message: ${JSON.stringify(e.message)}`);
538
+ this.errorLog(
539
+ `Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
540
+ );
538
541
  }
539
542
  if (this.platform.debugMode) {
540
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
541
- + ` Error: ${JSON.stringify(e)}`);
543
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
542
544
  }
543
545
  this.apiError(e);
544
546
  }
@@ -568,20 +570,25 @@ export class Bot {
568
570
 
569
571
  private async BLEpushChanges() {
570
572
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
571
- if (this.On !== this.OnCached) {
573
+ if (this.On !== this.OnCached || this.allowPush) {
572
574
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
573
575
  const switchbot = await this.platform.connectBLE();
574
576
  // Convert to BLE Address
575
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
577
+ this.device.bleMac = this.device
578
+ .deviceId!.match(/.{1,2}/g)!
579
+ .join(':')
580
+ .toLowerCase();
576
581
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
577
582
  //if (switchbot !== false) {
578
583
  if (this.botMode === 'press') {
579
584
  this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
580
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
581
- .then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => {
585
+ switchbot
586
+ .discover({ model: 'H', quick: true, id: this.device.bleMac })
587
+ .then((device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
582
588
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
583
589
  return device_list[0].press({ id: this.device.bleMac });
584
- }).then(() => {
590
+ })
591
+ .then(() => {
585
592
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
586
593
  this.On = false;
587
594
  this.OnCached = this.On;
@@ -594,15 +601,16 @@ export class Bot {
594
601
  }
595
602
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
596
603
  }, 500);
597
- }).catch(async (e: any) => {
604
+ })
605
+ .catch(async (e: any) => {
598
606
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
599
607
  if (this.deviceLogging === 'debug') {
600
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
601
- + ` Error Message: ${JSON.stringify(e.message)}`);
608
+ this.errorLog(
609
+ `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
610
+ );
602
611
  }
603
612
  if (this.platform.debugMode) {
604
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
605
- + ` Error: ${JSON.stringify(e)}`);
613
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
606
614
  }
607
615
  if (this.platform.config.credentials?.openToken) {
608
616
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -612,29 +620,33 @@ export class Bot {
612
620
  });
613
621
  } else if (this.botMode === 'switch') {
614
622
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
615
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
616
- this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
617
- return this.turnOnOff(device_list);
618
- }).then(() => {
619
- this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
620
- this.OnCached = this.On;
621
- this.accessory.context.On = this.OnCached;
622
- }).catch(async (e: any) => {
623
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
624
- if (this.deviceLogging === 'debug') {
625
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
626
- + ` Error Message: ${JSON.stringify(e.message)}`);
627
- }
628
- if (this.platform.debugMode) {
629
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
630
- + ` Error: ${JSON.stringify(e)}`);
631
- }
632
- if (this.platform.config.credentials?.openToken) {
633
- this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
634
- await this.openAPIpushChanges();
635
- }
636
- this.apiError(e);
637
- });
623
+ switchbot
624
+ .discover({ model: 'H', quick: true, id: this.device.bleMac })
625
+ .then((device_list: any) => {
626
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
627
+ return this.turnOnOff(device_list);
628
+ })
629
+ .then(() => {
630
+ this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
631
+ this.OnCached = this.On;
632
+ this.accessory.context.On = this.OnCached;
633
+ })
634
+ .catch(async (e: any) => {
635
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
636
+ if (this.deviceLogging === 'debug') {
637
+ this.errorLog(
638
+ `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
639
+ );
640
+ }
641
+ if (this.platform.debugMode) {
642
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
643
+ }
644
+ if (this.platform.config.credentials?.openToken) {
645
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
646
+ await this.openAPIpushChanges();
647
+ }
648
+ this.apiError(e);
649
+ });
638
650
  } else {
639
651
  throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
640
652
  }
@@ -661,7 +673,7 @@ export class Bot {
661
673
  private async openAPIpushChanges() {
662
674
  if (this.platform.config.credentials?.openToken) {
663
675
  try {
664
- if (this.On !== this.OnCached) {
676
+ if (this.On !== this.OnCached || this.allowPush) {
665
677
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
666
678
  const payload = {
667
679
  commandType: 'command',
@@ -684,11 +696,13 @@ export class Bot {
684
696
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
685
697
  }
686
698
 
687
- this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
688
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
699
+ this.infoLog(
700
+ `Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
701
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
702
+ );
689
703
 
690
704
  // Make the API request
691
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
705
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
692
706
  this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
693
707
  this.statusCode(push);
694
708
  this.OnCached = this.On;
@@ -697,12 +711,12 @@ export class Bot {
697
711
  } catch (e: any) {
698
712
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
699
713
  if (this.deviceLogging === 'debug') {
700
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
701
- + ` Error Message: ${JSON.stringify(e.message)}`);
714
+ this.errorLog(
715
+ `Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
716
+ );
702
717
  }
703
718
  if (this.platform.debugMode) {
704
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
705
- + ` Error: ${JSON.stringify(e)}`);
719
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
706
720
  }
707
721
  this.apiError(e);
708
722
  }
@@ -718,16 +732,24 @@ export class Bot {
718
732
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
719
733
  } else {
720
734
  if (this.On) {
721
- this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState,
722
- this.platform.Characteristic.TargetDoorState.OPEN);
723
- this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState,
724
- this.platform.Characteristic.CurrentDoorState.OPEN);
735
+ this.garageDoorService?.updateCharacteristic(
736
+ this.platform.Characteristic.TargetDoorState,
737
+ this.platform.Characteristic.TargetDoorState.OPEN,
738
+ );
739
+ this.garageDoorService?.updateCharacteristic(
740
+ this.platform.Characteristic.CurrentDoorState,
741
+ this.platform.Characteristic.CurrentDoorState.OPEN,
742
+ );
725
743
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
726
744
  } else {
727
- this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState,
728
- this.platform.Characteristic.TargetDoorState.CLOSED);
729
- this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState,
730
- this.platform.Characteristic.CurrentDoorState.CLOSED);
745
+ this.garageDoorService?.updateCharacteristic(
746
+ this.platform.Characteristic.TargetDoorState,
747
+ this.platform.Characteristic.TargetDoorState.CLOSED,
748
+ );
749
+ this.garageDoorService?.updateCharacteristic(
750
+ this.platform.Characteristic.CurrentDoorState,
751
+ this.platform.Characteristic.CurrentDoorState.CLOSED,
752
+ );
731
753
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
732
754
  }
733
755
  }
@@ -739,14 +761,12 @@ export class Bot {
739
761
  if (this.On) {
740
762
  this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
741
763
  this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
742
- this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState,
743
- this.platform.Characteristic.PositionState.STOPPED);
764
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
744
765
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
745
766
  } else {
746
767
  this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
747
768
  this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
748
- this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState,
749
- this.platform.Characteristic.PositionState.STOPPED);
769
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
750
770
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
751
771
  }
752
772
  }
@@ -758,14 +778,12 @@ export class Bot {
758
778
  if (this.On) {
759
779
  this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
760
780
  this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
761
- this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState,
762
- this.platform.Characteristic.PositionState.STOPPED);
781
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
763
782
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
764
783
  } else {
765
784
  this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
766
785
  this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
767
- this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState,
768
- this.platform.Characteristic.PositionState.STOPPED);
786
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
769
787
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
770
788
  }
771
789
  }
@@ -777,14 +795,18 @@ export class Bot {
777
795
  if (this.On) {
778
796
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
779
797
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
780
- this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState,
781
- this.platform.Characteristic.PositionState.STOPPED);
798
+ this.windowCoveringService?.updateCharacteristic(
799
+ this.platform.Characteristic.PositionState,
800
+ this.platform.Characteristic.PositionState.STOPPED,
801
+ );
782
802
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
783
803
  } else {
784
804
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
785
805
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
786
- this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState,
787
- this.platform.Characteristic.PositionState.STOPPED);
806
+ this.windowCoveringService?.updateCharacteristic(
807
+ this.platform.Characteristic.PositionState,
808
+ this.platform.Characteristic.PositionState.STOPPED,
809
+ );
788
810
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
789
811
  }
790
812
  }
@@ -794,16 +816,21 @@ export class Bot {
794
816
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
795
817
  } else {
796
818
  if (this.On) {
797
- this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState,
798
- this.platform.Characteristic.LockTargetState.UNSECURED);
799
- this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState,
800
- this.platform.Characteristic.LockCurrentState.UNSECURED);
819
+ this.lockService?.updateCharacteristic(
820
+ this.platform.Characteristic.LockTargetState,
821
+ this.platform.Characteristic.LockTargetState.UNSECURED,
822
+ );
823
+ this.lockService?.updateCharacteristic(
824
+ this.platform.Characteristic.LockCurrentState,
825
+ this.platform.Characteristic.LockCurrentState.UNSECURED,
826
+ );
801
827
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
802
828
  } else {
803
- this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState,
804
- this.platform.Characteristic.LockTargetState.SECURED);
805
- this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState,
806
- this.platform.Characteristic.LockCurrentState.SECURED);
829
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.SECURED);
830
+ this.lockService?.updateCharacteristic(
831
+ this.platform.Characteristic.LockCurrentState,
832
+ this.platform.Characteristic.LockCurrentState.SECURED,
833
+ );
807
834
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
808
835
  }
809
836
  }
@@ -813,12 +840,10 @@ export class Bot {
813
840
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
814
841
  } else {
815
842
  if (this.On) {
816
- this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active,
817
- this.platform.Characteristic.Active.ACTIVE);
843
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE);
818
844
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
819
845
  } else {
820
- this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active,
821
- this.platform.Characteristic.Active.INACTIVE);
846
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.INACTIVE);
822
847
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
823
848
  }
824
849
  }
@@ -841,13 +866,17 @@ export class Bot {
841
866
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
842
867
  } else {
843
868
  if (this.On) {
844
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent,
845
- this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
869
+ this.statefulProgrammableSwitchService?.updateCharacteristic(
870
+ this.platform.Characteristic.ProgrammableSwitchEvent,
871
+ this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
872
+ );
846
873
  this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
847
874
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
848
875
  } else {
849
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent,
850
- this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
876
+ this.statefulProgrammableSwitchService?.updateCharacteristic(
877
+ this.platform.Characteristic.ProgrammableSwitchEvent,
878
+ this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
879
+ );
851
880
  this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
852
881
  this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
853
882
  }
@@ -923,7 +952,7 @@ export class Bot {
923
952
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
924
953
  }
925
954
 
926
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
955
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
927
956
  switch (push.data.statusCode) {
928
957
  case 151:
929
958
  this.errorLog(`Bot: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -943,8 +972,10 @@ export class Bot {
943
972
  this.offlineOff();
944
973
  break;
945
974
  case 190:
946
- this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
947
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
975
+ this.errorLog(
976
+ `Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
977
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`,
978
+ );
948
979
  break;
949
980
  case 100:
950
981
  this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
@@ -976,9 +1007,11 @@ export class Bot {
976
1007
  } else {
977
1008
  this.On = true;
978
1009
  }
979
- } else if (this.device.bot?.deviceType === 'door'
980
- || this.device.bot?.deviceType === 'window'
981
- || this.device.bot?.deviceType === 'windowcovering') {
1010
+ } else if (
1011
+ this.device.bot?.deviceType === 'door' ||
1012
+ this.device.bot?.deviceType === 'window' ||
1013
+ this.device.bot?.deviceType === 'windowcovering'
1014
+ ) {
982
1015
  this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
983
1016
  if (value === 0) {
984
1017
  this.On = false;
@@ -1091,6 +1124,15 @@ export class Bot {
1091
1124
  }
1092
1125
  }
1093
1126
 
1127
+ allowPushChanges(device: device & devicesConfig) {
1128
+ if (device.bot?.allowPush) {
1129
+ this.allowPush = true;
1130
+ } else {
1131
+ this.allowPush = false;
1132
+ }
1133
+ this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1134
+ }
1135
+
1094
1136
  public removeOutletService(accessory: PlatformAccessory) {
1095
1137
  // If outletService still pressent, then remove first
1096
1138
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
@@ -1182,8 +1224,8 @@ export class Bot {
1182
1224
  }
1183
1225
 
1184
1226
  /**
1185
- * Logging for Device
1186
- */
1227
+ * Logging for Device
1228
+ */
1187
1229
  infoLog(...log: any[]) {
1188
1230
  if (this.enablingDeviceLogging()) {
1189
1231
  this.platform.log.info(String(...log));