@switchbot/homebridge-switchbot 1.8.2-beta.2 → 1.9.1-beta.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 +15 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +9 -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 +2 -2
  50. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  51. package/dist/irdevices/airconditioners.js +36 -45
  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 +19 -20
  88. package/dist/platform.js.map +1 -1
  89. package/dist/settings.d.ts +1 -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 +12 -8
  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 +72 -55
  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 +38 -40
  114. package/src/settings.ts +8 -18
  115. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -19,6 +19,7 @@ class Bot {
19
19
  this.scan(device);
20
20
  this.refreshRate(device);
21
21
  this.PressOrSwitch(device);
22
+ this.allowPushChanges(device);
22
23
  this.config(device);
23
24
  if (this.On === undefined) {
24
25
  this.On = false;
@@ -60,9 +61,8 @@ class Bot {
60
61
  this.removeWindowCoveringService(accessory);
61
62
  this.removeStatefulProgrammableSwitchService(accessory);
62
63
  // Add switchService
63
- (this.switchService =
64
- accessory.getService(this.platform.Service.Switch) ||
65
- accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
64
+ (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
65
+ `${accessory.displayName} Switch`;
66
66
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
67
67
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
68
68
  this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
@@ -79,8 +79,8 @@ class Bot {
79
79
  this.removeStatefulProgrammableSwitchService(accessory);
80
80
  // Add switchService
81
81
  (this.garageDoorService =
82
- accessory.getService(this.platform.Service.GarageDoorOpener) ||
83
- accessory.addService(this.platform.Service.GarageDoorOpener)), `${accessory.displayName} Garage Door Opener`;
82
+ accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
83
+ `${accessory.displayName} Garage Door Opener`;
84
84
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
85
85
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
86
86
  this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
@@ -97,18 +97,19 @@ class Bot {
97
97
  this.removeWindowCoveringService(accessory);
98
98
  this.removeStatefulProgrammableSwitchService(accessory);
99
99
  // Add switchService
100
- (this.doorService =
101
- accessory.getService(this.platform.Service.Door) ||
102
- accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
100
+ (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
101
+ `${accessory.displayName} Door`;
103
102
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
104
103
  this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
105
- this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
104
+ this.doorService
105
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
106
106
  .setProps({
107
107
  validValues: [0, 100],
108
108
  minValue: 0,
109
109
  maxValue: 100,
110
110
  minStep: 100,
111
- }).onSet(this.handleOnSet.bind(this));
111
+ })
112
+ .onSet(this.handleOnSet.bind(this));
112
113
  this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
113
114
  }
114
115
  else if (device.bot?.deviceType === 'window') {
@@ -122,18 +123,19 @@ class Bot {
122
123
  this.removeWindowCoveringService(accessory);
123
124
  this.removeStatefulProgrammableSwitchService(accessory);
124
125
  // Add switchService
125
- (this.windowService =
126
- accessory.getService(this.platform.Service.Window) ||
127
- accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
126
+ (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
127
+ `${accessory.displayName} Window`;
128
128
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
129
129
  this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
130
- this.windowService.getCharacteristic(this.platform.Characteristic.TargetPosition)
130
+ this.windowService
131
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
131
132
  .setProps({
132
133
  validValues: [0, 100],
133
134
  minValue: 0,
134
135
  maxValue: 100,
135
136
  minStep: 100,
136
- }).onSet(this.handleOnSet.bind(this));
137
+ })
138
+ .onSet(this.handleOnSet.bind(this));
137
139
  this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
138
140
  }
139
141
  else if (device.bot?.deviceType === 'windowcovering') {
@@ -148,17 +150,19 @@ class Bot {
148
150
  this.removeStatefulProgrammableSwitchService(accessory);
149
151
  // Add switchService
150
152
  (this.windowCoveringService =
151
- accessory.getService(this.platform.Service.WindowCovering) ||
152
- accessory.addService(this.platform.Service.WindowCovering)), `${accessory.displayName} Window Covering`;
153
+ accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
154
+ `${accessory.displayName} Window Covering`;
153
155
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
154
156
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
155
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.TargetPosition)
157
+ this.windowCoveringService
158
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
156
159
  .setProps({
157
160
  validValues: [0, 100],
158
161
  minValue: 0,
159
162
  maxValue: 100,
160
163
  minStep: 100,
161
- }).onSet(this.handleOnSet.bind(this));
164
+ })
165
+ .onSet(this.handleOnSet.bind(this));
162
166
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
163
167
  }
164
168
  else if (device.bot?.deviceType === 'lock') {
@@ -172,9 +176,8 @@ class Bot {
172
176
  this.removeWindowCoveringService(accessory);
173
177
  this.removeStatefulProgrammableSwitchService(accessory);
174
178
  // Add switchService
175
- (this.lockService =
176
- accessory.getService(this.platform.Service.LockMechanism) ||
177
- accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
179
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
180
+ `${accessory.displayName} Lock`;
178
181
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
179
182
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
180
183
  this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
@@ -190,9 +193,8 @@ class Bot {
190
193
  this.removeWindowCoveringService(accessory);
191
194
  this.removeStatefulProgrammableSwitchService(accessory);
192
195
  // Add switchService
193
- (this.faucetService =
194
- accessory.getService(this.platform.Service.Faucet) ||
195
- accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
196
+ (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
197
+ `${accessory.displayName} Faucet`;
196
198
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
197
199
  this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
198
200
  this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
@@ -208,9 +210,8 @@ class Bot {
208
210
  this.removeWindowCoveringService(accessory);
209
211
  this.removeStatefulProgrammableSwitchService(accessory);
210
212
  // Add switchService
211
- (this.fanService =
212
- accessory.getService(this.platform.Service.Fan) ||
213
- accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
213
+ (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
214
+ `${accessory.displayName} Fan`;
214
215
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
215
216
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
216
217
  this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
@@ -228,10 +229,12 @@ class Bot {
228
229
  // Add switchService
229
230
  (this.statefulProgrammableSwitchService =
230
231
  accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
231
- accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
232
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
233
+ `${accessory.displayName} Stateful Programmable Switch`;
232
234
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
233
235
  this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
234
- this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
236
+ this.statefulProgrammableSwitchService
237
+ .getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
235
238
  .onSet(this.handleOnSet.bind(this));
236
239
  }
237
240
  else {
@@ -245,9 +248,8 @@ class Bot {
245
248
  this.removeWindowCoveringService(accessory);
246
249
  this.removeStatefulProgrammableSwitchService(accessory);
247
250
  // Add outletService
248
- (this.outletService =
249
- accessory.getService(this.platform.Service.Outlet) ||
250
- accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
251
+ (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
252
+ `${accessory.displayName} Outlet`;
251
253
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
252
254
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
253
255
  this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
@@ -260,9 +262,8 @@ class Bot {
260
262
  }
261
263
  else if (device.ble && !this.batteryService) {
262
264
  this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
263
- (this.batteryService =
264
- this.accessory.getService(this.platform.Service.Battery) ||
265
- this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
265
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
266
+ `${accessory.displayName} Battery`;
266
267
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
267
268
  }
268
269
  else {
@@ -293,12 +294,10 @@ class Bot {
293
294
  catch (e) {
294
295
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
295
296
  if (this.deviceLogging === 'debug') {
296
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
297
- + ` Error Message: ${JSON.stringify(e.message)}`);
297
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
298
298
  }
299
299
  if (this.platform.debugMode) {
300
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
301
- + ` Error: ${JSON.stringify(e)}`);
300
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
302
301
  }
303
302
  }
304
303
  this.botUpdateInProgress = false;
@@ -389,16 +388,21 @@ class Bot {
389
388
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
390
389
  const switchbot = await this.platform.connectBLE();
391
390
  // Convert to BLE Address
392
- this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
391
+ this.device.bleMac = this.device
392
+ .deviceId.match(/.{1,2}/g)
393
+ .join(':')
394
+ .toLowerCase();
393
395
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
394
396
  // Start to monitor advertisement packets
395
397
  if (switchbot === false) {
396
398
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
397
399
  }
398
- switchbot.startScan({
400
+ switchbot
401
+ .startScan({
399
402
  model: 'H',
400
403
  id: this.device.bleMac,
401
- }).then(() => {
404
+ })
405
+ .then(() => {
402
406
  // Set an event hander
403
407
  switchbot.onadvertisement = (ad) => {
404
408
  this.serviceData = ad.serviceData;
@@ -406,8 +410,8 @@ class Bot {
406
410
  this.state = ad.serviceData.state;
407
411
  this.battery = ad.serviceData.battery;
408
412
  this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
409
- this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
410
- + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
413
+ this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
414
+ ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
411
415
  if (this.serviceData) {
412
416
  this.connected = true;
413
417
  this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -419,7 +423,8 @@ class Bot {
419
423
  };
420
424
  // Wait 2 seconds
421
425
  return switchbot.wait(this.scanDuration * 1000);
422
- }).then(async () => {
426
+ })
427
+ .then(async () => {
423
428
  // Stop to monitor
424
429
  switchbot.stopScan();
425
430
  if (this.connected) {
@@ -434,15 +439,14 @@ class Bot {
434
439
  await this.openAPIRefreshStatus();
435
440
  }
436
441
  }
437
- }).catch(async (e) => {
442
+ })
443
+ .catch(async (e) => {
438
444
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
439
445
  if (this.deviceLogging === 'debug') {
440
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
441
- + ` Error Message: ${JSON.stringify(e.message)}`);
446
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
442
447
  }
443
448
  if (this.platform.debugMode) {
444
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
445
- + ` Error: ${JSON.stringify(e)}`);
449
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
446
450
  }
447
451
  if (this.platform.config.credentials?.openToken) {
448
452
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -465,12 +469,10 @@ class Bot {
465
469
  catch (e) {
466
470
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
467
471
  if (this.deviceLogging === 'debug') {
468
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
469
- + ` Error Message: ${JSON.stringify(e.message)}`);
472
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
470
473
  }
471
474
  if (this.platform.debugMode) {
472
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
473
- + ` Error: ${JSON.stringify(e)}`);
475
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
474
476
  }
475
477
  this.apiError(e);
476
478
  }
@@ -499,20 +501,25 @@ class Bot {
499
501
  }
500
502
  async BLEpushChanges() {
501
503
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
502
- if (this.On !== this.OnCached) {
504
+ if (this.On !== this.OnCached || this.allowPush) {
503
505
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
504
506
  const switchbot = await this.platform.connectBLE();
505
507
  // Convert to BLE Address
506
- this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
508
+ this.device.bleMac = this.device
509
+ .deviceId.match(/.{1,2}/g)
510
+ .join(':')
511
+ .toLowerCase();
507
512
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
508
513
  //if (switchbot !== false) {
509
514
  if (this.botMode === 'press') {
510
515
  this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
511
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
516
+ switchbot
517
+ .discover({ model: 'H', quick: true, id: this.device.bleMac })
512
518
  .then((device_list) => {
513
519
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
514
520
  return device_list[0].press({ id: this.device.bleMac });
515
- }).then(() => {
521
+ })
522
+ .then(() => {
516
523
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
517
524
  this.On = false;
518
525
  this.OnCached = this.On;
@@ -526,15 +533,14 @@ class Bot {
526
533
  }
527
534
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
528
535
  }, 500);
529
- }).catch(async (e) => {
536
+ })
537
+ .catch(async (e) => {
530
538
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
531
539
  if (this.deviceLogging === 'debug') {
532
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
533
- + ` Error Message: ${JSON.stringify(e.message)}`);
540
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
534
541
  }
535
542
  if (this.platform.debugMode) {
536
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
537
- + ` Error: ${JSON.stringify(e)}`);
543
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
538
544
  }
539
545
  if (this.platform.config.credentials?.openToken) {
540
546
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -545,22 +551,24 @@ class Bot {
545
551
  }
546
552
  else if (this.botMode === 'switch') {
547
553
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
548
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
554
+ switchbot
555
+ .discover({ model: 'H', quick: true, id: this.device.bleMac })
556
+ .then((device_list) => {
549
557
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
550
558
  return this.turnOnOff(device_list);
551
- }).then(() => {
559
+ })
560
+ .then(() => {
552
561
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
553
562
  this.OnCached = this.On;
554
563
  this.accessory.context.On = this.OnCached;
555
- }).catch(async (e) => {
564
+ })
565
+ .catch(async (e) => {
556
566
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
557
567
  if (this.deviceLogging === 'debug') {
558
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
559
- + ` Error Message: ${JSON.stringify(e.message)}`);
568
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
560
569
  }
561
570
  if (this.platform.debugMode) {
562
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
563
- + ` Error: ${JSON.stringify(e)}`);
571
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
564
572
  }
565
573
  if (this.platform.config.credentials?.openToken) {
566
574
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -594,7 +602,7 @@ class Bot {
594
602
  async openAPIpushChanges() {
595
603
  if (this.platform.config.credentials?.openToken) {
596
604
  try {
597
- if (this.On !== this.OnCached) {
605
+ if (this.On !== this.OnCached || this.allowPush) {
598
606
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
599
607
  const payload = {
600
608
  commandType: 'command',
@@ -618,10 +626,10 @@ class Bot {
618
626
  else {
619
627
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
620
628
  }
621
- this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
622
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
629
+ this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
630
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
623
631
  // Make the API request
624
- const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
632
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
625
633
  this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
626
634
  this.statusCode(push);
627
635
  this.OnCached = this.On;
@@ -631,12 +639,10 @@ class Bot {
631
639
  catch (e) {
632
640
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
633
641
  if (this.deviceLogging === 'debug') {
634
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
635
- + ` Error Message: ${JSON.stringify(e.message)}`);
642
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
636
643
  }
637
644
  if (this.platform.debugMode) {
638
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
639
- + ` Error: ${JSON.stringify(e)}`);
645
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
640
646
  }
641
647
  this.apiError(e);
642
648
  }
@@ -894,8 +900,8 @@ class Bot {
894
900
  this.offlineOff();
895
901
  break;
896
902
  case 190:
897
- this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
898
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
903
+ this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
904
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
899
905
  break;
900
906
  case 100:
901
907
  this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
@@ -928,9 +934,9 @@ class Bot {
928
934
  this.On = true;
929
935
  }
930
936
  }
931
- else if (this.device.bot?.deviceType === 'door'
932
- || this.device.bot?.deviceType === 'window'
933
- || this.device.bot?.deviceType === 'windowcovering') {
937
+ else if (this.device.bot?.deviceType === 'door' ||
938
+ this.device.bot?.deviceType === 'window' ||
939
+ this.device.bot?.deviceType === 'windowcovering') {
934
940
  this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
935
941
  if (value === 0) {
936
942
  this.On = false;
@@ -1053,6 +1059,15 @@ class Bot {
1053
1059
  throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1054
1060
  }
1055
1061
  }
1062
+ allowPushChanges(device) {
1063
+ if (device.bot?.allowPush) {
1064
+ this.allowPush = true;
1065
+ }
1066
+ else {
1067
+ this.allowPush = false;
1068
+ }
1069
+ this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1070
+ }
1056
1071
  removeOutletService(accessory) {
1057
1072
  // If outletService still pressent, then remove first
1058
1073
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
@@ -1134,8 +1149,8 @@ class Bot {
1134
1149
  accessory.removeService(this.switchService);
1135
1150
  }
1136
1151
  /**
1137
- * Logging for Device
1138
- */
1152
+ * Logging for Device
1153
+ */
1139
1154
  infoLog(...log) {
1140
1155
  if (this.enablingDeviceLogging()) {
1141
1156
  this.platform.log.info(String(...log));