@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,28 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.Bot = void 0;
23
- const rxjs = __importStar(require("rxjs"));
24
- const operators = __importStar(require("rxjs/operators"));
25
- const settings = __importStar(require("../settings"));
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const settings_1 = require("../settings");
26
7
  /**
27
8
  * Platform Accessory
28
9
  * An instance of this class is created for each accessory your platform registers
@@ -38,6 +19,7 @@ class Bot {
38
19
  this.scan(device);
39
20
  this.refreshRate(device);
40
21
  this.PressOrSwitch(device);
22
+ this.allowPushChanges(device);
41
23
  this.config(device);
42
24
  if (this.On === undefined) {
43
25
  this.On = false;
@@ -56,19 +38,19 @@ class Bot {
56
38
  this.BatteryLevel = 100;
57
39
  this.StatusLowBattery = 0;
58
40
  // this is subject we use to track when we need to POST changes to the SwitchBot API
59
- this.doBotUpdate = new rxjs.Subject();
41
+ this.doBotUpdate = new rxjs_1.Subject();
60
42
  this.botUpdateInProgress = false;
61
43
  // Retrieve initial values and updateHomekit
62
44
  this.refreshStatus();
63
45
  // set accessory information
64
46
  accessory
65
47
  .getService(this.platform.Service.AccessoryInformation)
66
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
67
- .setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-BOT-S1")
48
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
49
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
68
50
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
69
51
  // get the LightBulb service if it exists, otherwise create a new LightBulb service
70
52
  // you can create multiple services for each accessory
71
- if (device.bot?.deviceType === "switch") {
53
+ if (device.bot?.deviceType === 'switch') {
72
54
  this.removeFanService(accessory);
73
55
  this.removeLockService(accessory);
74
56
  this.removeDoorService(accessory);
@@ -81,15 +63,12 @@ class Bot {
81
63
  // Add switchService
82
64
  (this.switchService =
83
65
  accessory.getService(this.platform.Service.Switch) ||
84
- accessory.addService(this.platform.Service.Switch)),
85
- `${accessory.displayName} Switch`;
66
+ accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
86
67
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
87
68
  this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
88
- this.switchService
89
- .getCharacteristic(this.platform.Characteristic.On)
90
- .onSet(this.handleOnSet.bind(this));
69
+ this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
91
70
  }
92
- else if (device.bot?.deviceType === "garagedoor") {
71
+ else if (device.bot?.deviceType === 'garagedoor') {
93
72
  this.removeFanService(accessory);
94
73
  this.removeLockService(accessory);
95
74
  this.removeDoorService(accessory);
@@ -102,16 +81,13 @@ class Bot {
102
81
  // Add switchService
103
82
  (this.garageDoorService =
104
83
  accessory.getService(this.platform.Service.GarageDoorOpener) ||
105
- accessory.addService(this.platform.Service.GarageDoorOpener)),
106
- `${accessory.displayName} Garage Door Opener`;
84
+ accessory.addService(this.platform.Service.GarageDoorOpener)), `${accessory.displayName} Garage Door Opener`;
107
85
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
108
86
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
109
- this.garageDoorService
110
- .getCharacteristic(this.platform.Characteristic.TargetDoorState)
111
- .onSet(this.handleOnSet.bind(this));
87
+ this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
112
88
  this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
113
89
  }
114
- else if (device.bot?.deviceType === "door") {
90
+ else if (device.bot?.deviceType === 'door') {
115
91
  this.removeFanService(accessory);
116
92
  this.removeLockService(accessory);
117
93
  this.removeOutletService(accessory);
@@ -124,22 +100,19 @@ class Bot {
124
100
  // Add switchService
125
101
  (this.doorService =
126
102
  accessory.getService(this.platform.Service.Door) ||
127
- accessory.addService(this.platform.Service.Door)),
128
- `${accessory.displayName} Door`;
103
+ accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
129
104
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
130
105
  this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
131
- this.doorService
132
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
106
+ this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
133
107
  .setProps({
134
108
  validValues: [0, 100],
135
109
  minValue: 0,
136
110
  maxValue: 100,
137
111
  minStep: 100,
138
- })
139
- .onSet(this.handleOnSet.bind(this));
112
+ }).onSet(this.handleOnSet.bind(this));
140
113
  this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
141
114
  }
142
- else if (device.bot?.deviceType === "window") {
115
+ else if (device.bot?.deviceType === 'window') {
143
116
  this.removeFanService(accessory);
144
117
  this.removeLockService(accessory);
145
118
  this.removeDoorService(accessory);
@@ -152,22 +125,19 @@ class Bot {
152
125
  // Add switchService
153
126
  (this.windowService =
154
127
  accessory.getService(this.platform.Service.Window) ||
155
- accessory.addService(this.platform.Service.Window)),
156
- `${accessory.displayName} Window`;
128
+ accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
157
129
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
158
130
  this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
159
- this.windowService
160
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
131
+ this.windowService.getCharacteristic(this.platform.Characteristic.TargetPosition)
161
132
  .setProps({
162
133
  validValues: [0, 100],
163
134
  minValue: 0,
164
135
  maxValue: 100,
165
136
  minStep: 100,
166
- })
167
- .onSet(this.handleOnSet.bind(this));
137
+ }).onSet(this.handleOnSet.bind(this));
168
138
  this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
169
139
  }
170
- else if (device.bot?.deviceType === "windowcovering") {
140
+ else if (device.bot?.deviceType === 'windowcovering') {
171
141
  this.removeFanService(accessory);
172
142
  this.removeLockService(accessory);
173
143
  this.removeDoorService(accessory);
@@ -180,22 +150,19 @@ class Bot {
180
150
  // Add switchService
181
151
  (this.windowCoveringService =
182
152
  accessory.getService(this.platform.Service.WindowCovering) ||
183
- accessory.addService(this.platform.Service.WindowCovering)),
184
- `${accessory.displayName} Window Covering`;
153
+ accessory.addService(this.platform.Service.WindowCovering)), `${accessory.displayName} Window Covering`;
185
154
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
186
155
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
187
- this.windowCoveringService
188
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
156
+ this.windowCoveringService.getCharacteristic(this.platform.Characteristic.TargetPosition)
189
157
  .setProps({
190
158
  validValues: [0, 100],
191
159
  minValue: 0,
192
160
  maxValue: 100,
193
161
  minStep: 100,
194
- })
195
- .onSet(this.handleOnSet.bind(this));
162
+ }).onSet(this.handleOnSet.bind(this));
196
163
  this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
197
164
  }
198
- else if (device.bot?.deviceType === "lock") {
165
+ else if (device.bot?.deviceType === 'lock') {
199
166
  this.removeFanService(accessory);
200
167
  this.removeDoorService(accessory);
201
168
  this.removeOutletService(accessory);
@@ -208,15 +175,12 @@ class Bot {
208
175
  // Add switchService
209
176
  (this.lockService =
210
177
  accessory.getService(this.platform.Service.LockMechanism) ||
211
- accessory.addService(this.platform.Service.LockMechanism)),
212
- `${accessory.displayName} Lock`;
178
+ accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
213
179
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
214
180
  this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
215
- this.lockService
216
- .getCharacteristic(this.platform.Characteristic.LockTargetState)
217
- .onSet(this.handleOnSet.bind(this));
181
+ this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
218
182
  }
219
- else if (device.bot?.deviceType === "faucet") {
183
+ else if (device.bot?.deviceType === 'faucet') {
220
184
  this.removeFanService(accessory);
221
185
  this.removeLockService(accessory);
222
186
  this.removeDoorService(accessory);
@@ -229,15 +193,12 @@ class Bot {
229
193
  // Add switchService
230
194
  (this.faucetService =
231
195
  accessory.getService(this.platform.Service.Faucet) ||
232
- accessory.addService(this.platform.Service.Faucet)),
233
- `${accessory.displayName} Faucet`;
196
+ accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
234
197
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
235
198
  this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
236
- this.faucetService
237
- .getCharacteristic(this.platform.Characteristic.Active)
238
- .onSet(this.handleOnSet.bind(this));
199
+ this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
239
200
  }
240
- else if (device.bot?.deviceType === "fan") {
201
+ else if (device.bot?.deviceType === 'fan') {
241
202
  this.removeLockService(accessory);
242
203
  this.removeDoorService(accessory);
243
204
  this.removeFaucetService(accessory);
@@ -250,15 +211,12 @@ class Bot {
250
211
  // Add switchService
251
212
  (this.fanService =
252
213
  accessory.getService(this.platform.Service.Fan) ||
253
- accessory.addService(this.platform.Service.Fan)),
254
- `${accessory.displayName} Fan`;
214
+ accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
255
215
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
256
216
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
257
- this.fanService
258
- .getCharacteristic(this.platform.Characteristic.On)
259
- .onSet(this.handleOnSet.bind(this));
217
+ this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
260
218
  }
261
- else if (device.bot?.deviceType === "stateful") {
219
+ else if (device.bot?.deviceType === 'stateful') {
262
220
  this.removeFanService(accessory);
263
221
  this.removeLockService(accessory);
264
222
  this.removeDoorService(accessory);
@@ -271,12 +229,10 @@ class Bot {
271
229
  // Add switchService
272
230
  (this.statefulProgrammableSwitchService =
273
231
  accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
274
- accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
275
- `${accessory.displayName} Stateful Programmable Switch`;
232
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
276
233
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
277
234
  this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
278
- this.statefulProgrammableSwitchService
279
- .getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
235
+ this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
280
236
  .onSet(this.handleOnSet.bind(this));
281
237
  }
282
238
  else {
@@ -292,13 +248,10 @@ class Bot {
292
248
  // Add outletService
293
249
  (this.outletService =
294
250
  accessory.getService(this.platform.Service.Outlet) ||
295
- accessory.addService(this.platform.Service.Outlet)),
296
- `${accessory.displayName} Outlet`;
251
+ accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
297
252
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
298
253
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
299
- this.outletService
300
- .getCharacteristic(this.platform.Characteristic.On)
301
- .onSet(this.handleOnSet.bind(this));
254
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
302
255
  }
303
256
  // Battery Service
304
257
  if (!device.ble) {
@@ -310,8 +263,7 @@ class Bot {
310
263
  this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
311
264
  (this.batteryService =
312
265
  this.accessory.getService(this.platform.Service.Battery) ||
313
- this.accessory.addService(this.platform.Service.Battery)),
314
- `${accessory.displayName} Battery`;
266
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
315
267
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
316
268
  }
317
269
  else {
@@ -320,32 +272,34 @@ class Bot {
320
272
  // Retrieve initial values and updateHomekit
321
273
  this.updateHomeKitCharacteristics();
322
274
  // Start an update interval
323
- rxjs
324
- .interval(this.deviceRefreshRate * 1000)
325
- .pipe(operators.skipWhile(() => this.botUpdateInProgress))
275
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
276
+ .pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
326
277
  .subscribe(() => {
327
278
  this.refreshStatus();
328
279
  });
329
280
  // Watch for Bot change events
330
281
  // We put in a debounce of 100ms so we don't make duplicate calls
331
282
  this.doBotUpdate
332
- .pipe(operators.tap(() => {
283
+ .pipe((0, operators_1.tap)(() => {
333
284
  this.botUpdateInProgress = true;
334
- }), operators.debounceTime(100))
285
+ }), (0, operators_1.debounceTime)(100))
335
286
  .subscribe(async () => {
336
287
  try {
337
- rxjs
338
- .interval(100)
339
- .pipe(operators.take(this.doublePress))
288
+ (0, rxjs_1.interval)(100)
289
+ .pipe((0, operators_1.take)(this.doublePress))
340
290
  .subscribe(async () => {
341
291
  await this.pushChanges();
342
292
  });
343
293
  }
344
294
  catch (e) {
345
295
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
346
- if (this.deviceLogging.includes("debug")) {
347
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` +
348
- ` Error Message: ${JSON.stringify(e.message)}`);
296
+ if (this.deviceLogging === 'debug') {
297
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
298
+ + ` Error Message: ${JSON.stringify(e.message)}`);
299
+ }
300
+ if (this.platform.debugMode) {
301
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
302
+ + ` Error: ${JSON.stringify(e)}`);
349
303
  }
350
304
  }
351
305
  this.botUpdateInProgress = false;
@@ -381,12 +335,10 @@ class Bot {
381
335
  }
382
336
  this.BatteryLevel = Number(this.battery);
383
337
  if (this.BatteryLevel < 10) {
384
- this.StatusLowBattery =
385
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
338
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
386
339
  }
387
340
  else {
388
- this.StatusLowBattery =
389
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
341
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
390
342
  }
391
343
  if (Number.isNaN(this.BatteryLevel)) {
392
344
  this.BatteryLevel = 100;
@@ -399,7 +351,7 @@ class Bot {
399
351
  }
400
352
  if (this.platform.config.credentials?.openToken) {
401
353
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
402
- if (this.botMode === "press") {
354
+ if (this.botMode === 'press') {
403
355
  this.On = false;
404
356
  this.OnCached = this.On;
405
357
  this.accessory.context.On = this.OnCached;
@@ -438,21 +390,16 @@ class Bot {
438
390
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
439
391
  const switchbot = await this.platform.connectBLE();
440
392
  // Convert to BLE Address
441
- this.device.bleMac = this.device
442
- .deviceId.match(/.{1,2}/g)
443
- .join(":")
444
- .toLowerCase();
445
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
446
- try {
447
- await switchbot.discover({
448
- model: "H",
449
- quick: false,
450
- });
451
- // Start to monitor advertisement packets
452
- await switchbot.startScan({
453
- model: "H",
454
- id: this.device.bleMac,
455
- });
393
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
394
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
395
+ // Start to monitor advertisement packets
396
+ if (switchbot === false) {
397
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
398
+ }
399
+ switchbot.startScan({
400
+ model: 'H',
401
+ id: this.device.bleMac,
402
+ }).then(() => {
456
403
  // Set an event hander
457
404
  switchbot.onadvertisement = (ad) => {
458
405
  this.serviceData = ad.serviceData;
@@ -460,8 +407,8 @@ class Bot {
460
407
  this.state = ad.serviceData.state;
461
408
  this.battery = ad.serviceData.battery;
462
409
  this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
463
- this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
464
- ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
410
+ this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
411
+ + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
465
412
  if (this.serviceData) {
466
413
  this.connected = true;
467
414
  this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -472,7 +419,8 @@ class Bot {
472
419
  }
473
420
  };
474
421
  // Wait 2 seconds
475
- await switchbot.wait(this.scanDuration * 1000);
422
+ return switchbot.wait(this.scanDuration * 1000);
423
+ }).then(async () => {
476
424
  // Stop to monitor
477
425
  switchbot.stopScan();
478
426
  if (this.connected) {
@@ -487,12 +435,15 @@ class Bot {
487
435
  await this.openAPIRefreshStatus();
488
436
  }
489
437
  }
490
- }
491
- catch (e) {
438
+ }).catch(async (e) => {
492
439
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
493
- if (this.deviceLogging.includes("debug")) {
494
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
495
- ` Error Message: ${JSON.stringify(e.message)}`);
440
+ if (this.deviceLogging === 'debug') {
441
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
442
+ + ` Error Message: ${JSON.stringify(e.message)}`);
443
+ }
444
+ if (this.platform.debugMode) {
445
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
446
+ + ` Error: ${JSON.stringify(e)}`);
496
447
  }
497
448
  if (this.platform.config.credentials?.openToken) {
498
449
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -500,13 +451,13 @@ class Bot {
500
451
  await this.openAPIRefreshStatus();
501
452
  }
502
453
  this.apiError(e);
503
- }
454
+ });
504
455
  }
505
456
  async openAPIRefreshStatus() {
506
457
  if (this.platform.config.credentials?.openToken) {
507
458
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
508
459
  try {
509
- this.deviceStatus = (await this.platform.axios.get(`${settings.DeviceURL}/${this.device.deviceId}/status`)).data;
460
+ this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
510
461
  this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
511
462
  this.power = this.deviceStatus.body.power;
512
463
  this.parseStatus();
@@ -514,9 +465,13 @@ class Bot {
514
465
  }
515
466
  catch (e) {
516
467
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
517
- if (this.deviceLogging.includes("debug")) {
518
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
519
- ` Error Message: ${JSON.stringify(e.message)}`);
468
+ if (this.deviceLogging === 'debug') {
469
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
470
+ + ` Error Message: ${JSON.stringify(e.message)}`);
471
+ }
472
+ if (this.platform.debugMode) {
473
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
474
+ + ` Error: ${JSON.stringify(e)}`);
520
475
  }
521
476
  this.apiError(e);
522
477
  }
@@ -536,58 +491,51 @@ class Bot {
536
491
  else {
537
492
  await this.openAPIpushChanges();
538
493
  }
539
- rxjs
540
- .interval(5000)
541
- .pipe(operators.skipWhile(() => this.botUpdateInProgress))
542
- .pipe(operators.take(1))
494
+ (0, rxjs_1.interval)(5000)
495
+ .pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
496
+ .pipe((0, operators_1.take)(1))
543
497
  .subscribe(() => {
544
498
  this.refreshStatus();
545
499
  });
546
500
  }
547
501
  async BLEpushChanges() {
548
502
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
549
- if (this.On !== this.OnCached) {
503
+ if ((this.On !== this.OnCached) || this.allowPush) {
550
504
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
551
505
  const switchbot = await this.platform.connectBLE();
552
506
  // Convert to BLE Address
553
- this.device.bleMac = this.device
554
- .deviceId.match(/.{1,2}/g)
555
- .join(":")
556
- .toLowerCase();
557
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
507
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
508
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
558
509
  //if (switchbot !== false) {
559
- if (this.botMode === "press") {
510
+ if (this.botMode === 'press') {
560
511
  this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
561
- switchbot
562
- .discover({ model: "H", quick: true, id: this.device.bleMac })
512
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
563
513
  .then((device_list) => {
564
514
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
565
515
  return device_list[0].press({ id: this.device.bleMac });
566
- })
567
- .then(() => {
516
+ }).then(() => {
568
517
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
569
518
  this.On = false;
570
519
  this.OnCached = this.On;
571
520
  this.accessory.context.On = this.OnCached;
572
521
  setTimeout(() => {
573
- if (this.device.bot?.deviceType === "switch") {
574
- this.switchService
575
- ?.getCharacteristic(this.platform.Characteristic.On)
576
- .updateValue(this.On);
522
+ if (this.device.bot?.deviceType === 'switch') {
523
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
577
524
  }
578
525
  else {
579
- this.outletService
580
- ?.getCharacteristic(this.platform.Characteristic.On)
581
- .updateValue(this.On);
526
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
582
527
  }
583
528
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
584
529
  }, 500);
585
- })
586
- .catch(async (e) => {
530
+ }).catch(async (e) => {
587
531
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
588
- if (this.deviceLogging.includes("debug")) {
589
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
590
- ` Error Message: ${JSON.stringify(e.message)}`);
532
+ if (this.deviceLogging === 'debug') {
533
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
534
+ + ` Error Message: ${JSON.stringify(e.message)}`);
535
+ }
536
+ if (this.platform.debugMode) {
537
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
538
+ + ` Error: ${JSON.stringify(e)}`);
591
539
  }
592
540
  if (this.platform.config.credentials?.openToken) {
593
541
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -596,24 +544,24 @@ class Bot {
596
544
  this.apiError(e);
597
545
  });
598
546
  }
599
- else if (this.botMode === "switch") {
547
+ else if (this.botMode === 'switch') {
600
548
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
601
- switchbot
602
- .discover({ model: "H", quick: true, id: this.device.bleMac })
603
- .then((device_list) => {
549
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
604
550
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
605
551
  return this.turnOnOff(device_list);
606
- })
607
- .then(() => {
552
+ }).then(() => {
608
553
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
609
554
  this.OnCached = this.On;
610
555
  this.accessory.context.On = this.OnCached;
611
- })
612
- .catch(async (e) => {
556
+ }).catch(async (e) => {
613
557
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
614
- if (this.deviceLogging.includes("debug")) {
615
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
616
- ` Error Message: ${JSON.stringify(e.message)}`);
558
+ if (this.deviceLogging === 'debug') {
559
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
560
+ + ` Error Message: ${JSON.stringify(e.message)}`);
561
+ }
562
+ if (this.platform.debugMode) {
563
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
564
+ + ` Error: ${JSON.stringify(e)}`);
617
565
  }
618
566
  if (this.platform.config.credentials?.openToken) {
619
567
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -647,34 +595,34 @@ class Bot {
647
595
  async openAPIpushChanges() {
648
596
  if (this.platform.config.credentials?.openToken) {
649
597
  try {
650
- if (this.On !== this.OnCached) {
598
+ if ((this.On !== this.OnCached) || this.allowPush) {
651
599
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
652
600
  const payload = {
653
- commandType: "command",
654
- parameter: "default",
601
+ commandType: 'command',
602
+ parameter: 'default',
655
603
  };
656
- if (this.botMode === "switch" && this.On) {
657
- payload.command = "turnOn";
604
+ if (this.botMode === 'switch' && this.On) {
605
+ payload.command = 'turnOn';
658
606
  this.On = true;
659
607
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
660
608
  }
661
- else if (this.botMode === "switch" && !this.On) {
662
- payload.command = "turnOff";
609
+ else if (this.botMode === 'switch' && !this.On) {
610
+ payload.command = 'turnOff';
663
611
  this.On = false;
664
612
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
665
613
  }
666
- else if (this.botMode === "press") {
667
- payload.command = "press";
614
+ else if (this.botMode === 'press') {
615
+ payload.command = 'press';
668
616
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
669
617
  this.On = false;
670
618
  }
671
619
  else {
672
620
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
673
621
  }
674
- this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
675
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
622
+ this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
623
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
676
624
  // Make the API request
677
- const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
625
+ const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
678
626
  this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
679
627
  this.statusCode(push);
680
628
  this.OnCached = this.On;
@@ -683,9 +631,13 @@ class Bot {
683
631
  }
684
632
  catch (e) {
685
633
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
686
- if (this.deviceLogging.includes("debug")) {
687
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
688
- ` Error Message: ${JSON.stringify(e.message)}`);
634
+ if (this.deviceLogging === 'debug') {
635
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
636
+ + ` Error Message: ${JSON.stringify(e.message)}`);
637
+ }
638
+ if (this.platform.debugMode) {
639
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
640
+ + ` Error: ${JSON.stringify(e)}`);
689
641
  }
690
642
  this.apiError(e);
691
643
  }
@@ -695,7 +647,7 @@ class Bot {
695
647
  * Updates the status for each of the HomeKit Characteristics
696
648
  */
697
649
  updateHomeKitCharacteristics() {
698
- if (this.device.bot?.deviceType === "garagedoor") {
650
+ if (this.device.bot?.deviceType === 'garagedoor') {
699
651
  if (this.On === undefined) {
700
652
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
701
653
  }
@@ -713,7 +665,7 @@ class Bot {
713
665
  }
714
666
  this.debugLog(`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`);
715
667
  }
716
- else if (this.device.bot?.deviceType === "door") {
668
+ else if (this.device.bot?.deviceType === 'door') {
717
669
  if (this.On === undefined) {
718
670
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
719
671
  }
@@ -733,7 +685,7 @@ class Bot {
733
685
  }
734
686
  this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
735
687
  }
736
- else if (this.device.bot?.deviceType === "window") {
688
+ else if (this.device.bot?.deviceType === 'window') {
737
689
  if (this.On === undefined) {
738
690
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
739
691
  }
@@ -753,7 +705,7 @@ class Bot {
753
705
  }
754
706
  this.debugLog(`Bot: ${this.accessory.displayName} Window On: ${this.On}`);
755
707
  }
756
- else if (this.device.bot?.deviceType === "windowcovering") {
708
+ else if (this.device.bot?.deviceType === 'windowcovering') {
757
709
  if (this.On === undefined) {
758
710
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
759
711
  }
@@ -773,7 +725,7 @@ class Bot {
773
725
  }
774
726
  this.debugLog(`Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`);
775
727
  }
776
- else if (this.device.bot?.deviceType === "lock") {
728
+ else if (this.device.bot?.deviceType === 'lock') {
777
729
  if (this.On === undefined) {
778
730
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
779
731
  }
@@ -791,7 +743,7 @@ class Bot {
791
743
  }
792
744
  this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
793
745
  }
794
- else if (this.device.bot?.deviceType === "faucet") {
746
+ else if (this.device.bot?.deviceType === 'faucet') {
795
747
  if (this.On === undefined) {
796
748
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
797
749
  }
@@ -807,7 +759,7 @@ class Bot {
807
759
  }
808
760
  this.debugLog(`Bot: ${this.accessory.displayName} Faucet On: ${this.On}`);
809
761
  }
810
- else if (this.device.bot?.deviceType === "fan") {
762
+ else if (this.device.bot?.deviceType === 'fan') {
811
763
  if (this.On === undefined) {
812
764
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
813
765
  }
@@ -823,7 +775,7 @@ class Bot {
823
775
  }
824
776
  this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
825
777
  }
826
- else if (this.device.bot?.deviceType === "stateful") {
778
+ else if (this.device.bot?.deviceType === 'stateful') {
827
779
  if (this.On === undefined) {
828
780
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
829
781
  }
@@ -841,7 +793,7 @@ class Bot {
841
793
  }
842
794
  this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
843
795
  }
844
- else if (this.device.bot?.deviceType === "switch") {
796
+ else if (this.device.bot?.deviceType === 'switch') {
845
797
  if (this.On === undefined) {
846
798
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
847
799
  }
@@ -877,41 +829,41 @@ class Bot {
877
829
  }
878
830
  }
879
831
  apiError(e) {
880
- if (this.device.bot?.deviceType === "garagedoor") {
832
+ if (this.device.bot?.deviceType === 'garagedoor') {
881
833
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
882
834
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
883
835
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, e);
884
836
  }
885
- else if (this.device.bot?.deviceType === "door") {
837
+ else if (this.device.bot?.deviceType === 'door') {
886
838
  this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
887
839
  this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
888
840
  this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
889
841
  }
890
- else if (this.device.bot?.deviceType === "window") {
842
+ else if (this.device.bot?.deviceType === 'window') {
891
843
  this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
892
844
  this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
893
845
  this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
894
846
  }
895
- else if (this.device.bot?.deviceType === "windowcovering") {
847
+ else if (this.device.bot?.deviceType === 'windowcovering') {
896
848
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
897
849
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
898
850
  this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
899
851
  }
900
- else if (this.device.bot?.deviceType === "lock") {
852
+ else if (this.device.bot?.deviceType === 'lock') {
901
853
  this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
902
854
  this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
903
855
  }
904
- else if (this.device.bot?.deviceType === "faucet") {
856
+ else if (this.device.bot?.deviceType === 'faucet') {
905
857
  this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, e);
906
858
  }
907
- else if (this.device.bot?.deviceType === "fan") {
859
+ else if (this.device.bot?.deviceType === 'fan') {
908
860
  this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
909
861
  }
910
- else if (this.device.bot?.deviceType === "stateful") {
862
+ else if (this.device.bot?.deviceType === 'stateful') {
911
863
  this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
912
864
  this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
913
865
  }
914
- else if (this.device.bot?.deviceType === "switch") {
866
+ else if (this.device.bot?.deviceType === 'switch') {
915
867
  this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
916
868
  }
917
869
  else {
@@ -943,8 +895,8 @@ class Bot {
943
895
  this.offlineOff();
944
896
  break;
945
897
  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`);
898
+ this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
899
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
948
900
  break;
949
901
  case 100:
950
902
  this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
@@ -956,15 +908,11 @@ class Bot {
956
908
  offlineOff() {
957
909
  if (this.device.offline) {
958
910
  this.On = false;
959
- if (this.device.bot?.deviceType === "switch") {
960
- this.switchService
961
- ?.getCharacteristic(this.platform.Characteristic.On)
962
- .updateValue(this.On);
911
+ if (this.device.bot?.deviceType === 'switch') {
912
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
963
913
  }
964
914
  else {
965
- this.outletService
966
- ?.getCharacteristic(this.platform.Characteristic.On)
967
- .updateValue(this.On);
915
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
968
916
  }
969
917
  }
970
918
  }
@@ -972,7 +920,7 @@ class Bot {
972
920
  * Handle requests to set the "On" characteristic
973
921
  */
974
922
  handleOnSet(value) {
975
- if (this.device.bot?.deviceType === "garagedoor") {
923
+ if (this.device.bot?.deviceType === 'garagedoor') {
976
924
  this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
977
925
  if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
978
926
  this.On = false;
@@ -981,9 +929,9 @@ class Bot {
981
929
  this.On = true;
982
930
  }
983
931
  }
984
- else if (this.device.bot?.deviceType === "door" ||
985
- this.device.bot?.deviceType === "window" ||
986
- this.device.bot?.deviceType === "windowcovering") {
932
+ else if (this.device.bot?.deviceType === 'door'
933
+ || this.device.bot?.deviceType === 'window'
934
+ || this.device.bot?.deviceType === 'windowcovering') {
987
935
  this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
988
936
  if (value === 0) {
989
937
  this.On = false;
@@ -992,7 +940,7 @@ class Bot {
992
940
  this.On = true;
993
941
  }
994
942
  }
995
- else if (this.device.bot?.deviceType === "lock") {
943
+ else if (this.device.bot?.deviceType === 'lock') {
996
944
  this.debugLog(`Bot: ${this.accessory.displayName} LockTargetState: ${value}`);
997
945
  if (value === this.platform.Characteristic.LockTargetState.SECURED) {
998
946
  this.On = false;
@@ -1001,7 +949,7 @@ class Bot {
1001
949
  this.On = true;
1002
950
  }
1003
951
  }
1004
- else if (this.device.bot?.deviceType === "faucet") {
952
+ else if (this.device.bot?.deviceType === 'faucet') {
1005
953
  this.debugLog(`Bot: ${this.accessory.displayName} Active: ${value}`);
1006
954
  if (value === this.platform.Characteristic.Active.INACTIVE) {
1007
955
  this.On = false;
@@ -1010,7 +958,7 @@ class Bot {
1010
958
  this.On = true;
1011
959
  }
1012
960
  }
1013
- else if (this.device.bot?.deviceType === "stateful") {
961
+ else if (this.device.bot?.deviceType === 'stateful') {
1014
962
  this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
1015
963
  if (value === 0) {
1016
964
  this.On = false;
@@ -1031,16 +979,16 @@ class Bot {
1031
979
  config = device.bot;
1032
980
  }
1033
981
  if (device.ble) {
1034
- config["ble"] = device.ble;
982
+ config['ble'] = device.ble;
1035
983
  }
1036
984
  if (device.logging !== undefined) {
1037
- config["logging"] = device.logging;
985
+ config['logging'] = device.logging;
1038
986
  }
1039
987
  if (device.refreshRate !== undefined) {
1040
- config["refreshRate"] = device.refreshRate;
988
+ config['refreshRate'] = device.refreshRate;
1041
989
  }
1042
990
  if (device.scanDuration !== undefined) {
1043
- config["scanDuration"] = device.scanDuration;
991
+ config['scanDuration'] = device.scanDuration;
1044
992
  }
1045
993
  if (Object.entries(config).length !== 0) {
1046
994
  this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
@@ -1048,20 +996,17 @@ class Bot {
1048
996
  }
1049
997
  refreshRate(device) {
1050
998
  if (device.refreshRate) {
1051
- this.deviceRefreshRate = this.accessory.context.refreshRate =
1052
- device.refreshRate;
999
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1053
1000
  this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
1054
1001
  }
1055
1002
  else if (this.platform.config.options.refreshRate) {
1056
- this.deviceRefreshRate = this.accessory.context.refreshRate =
1057
- this.platform.config.options.refreshRate;
1003
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
1058
1004
  this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
1059
1005
  }
1060
1006
  }
1061
1007
  scan(device) {
1062
1008
  if (device.scanDuration) {
1063
- this.scanDuration = this.accessory.context.scanDuration =
1064
- device.scanDuration;
1009
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
1065
1010
  if (device.ble) {
1066
1011
  this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
1067
1012
  }
@@ -1075,7 +1020,7 @@ class Bot {
1075
1020
  }
1076
1021
  logs(device) {
1077
1022
  if (this.platform.debugMode) {
1078
- this.deviceLogging = this.accessory.context.logging = "debugMode";
1023
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
1079
1024
  this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
1080
1025
  }
1081
1026
  else if (device.logging) {
@@ -1083,33 +1028,41 @@ class Bot {
1083
1028
  this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
1084
1029
  }
1085
1030
  else if (this.platform.config.options?.logging) {
1086
- this.deviceLogging = this.accessory.context.logging =
1087
- this.platform.config.options?.logging;
1031
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
1088
1032
  this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
1089
1033
  }
1090
1034
  else {
1091
- this.deviceLogging = this.accessory.context.logging = "standard";
1035
+ this.deviceLogging = this.accessory.context.logging = 'standard';
1092
1036
  this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
1093
1037
  }
1094
1038
  }
1095
1039
  PressOrSwitch(device) {
1096
1040
  if (!device.bot?.mode) {
1097
- this.botMode = "switch";
1041
+ this.botMode = 'switch';
1098
1042
  this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
1099
1043
  this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
1100
1044
  }
1101
- else if (device.bot?.mode === "switch") {
1102
- this.botMode = "switch";
1045
+ else if (device.bot?.mode === 'switch') {
1046
+ this.botMode = 'switch';
1103
1047
  this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1104
1048
  }
1105
- else if (device.bot?.mode === "press") {
1106
- this.botMode = "press";
1049
+ else if (device.bot?.mode === 'press') {
1050
+ this.botMode = 'press';
1107
1051
  this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1108
1052
  }
1109
1053
  else {
1110
1054
  throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1111
1055
  }
1112
1056
  }
1057
+ allowPushChanges(device) {
1058
+ if (device.bot?.allowPush) {
1059
+ this.allowPush = true;
1060
+ }
1061
+ else {
1062
+ this.allowPush = false;
1063
+ }
1064
+ this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1065
+ }
1113
1066
  removeOutletService(accessory) {
1114
1067
  // If outletService still pressent, then remove first
1115
1068
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
@@ -1191,8 +1144,8 @@ class Bot {
1191
1144
  accessory.removeService(this.switchService);
1192
1145
  }
1193
1146
  /**
1194
- * Logging for Device
1195
- */
1147
+ * Logging for Device
1148
+ */
1196
1149
  infoLog(...log) {
1197
1150
  if (this.enablingDeviceLogging()) {
1198
1151
  this.platform.log.info(String(...log));
@@ -1210,8 +1163,8 @@ class Bot {
1210
1163
  }
1211
1164
  debugLog(...log) {
1212
1165
  if (this.enablingDeviceLogging()) {
1213
- if (this.deviceLogging === "debug") {
1214
- this.platform.log.info("[DEBUG]", String(...log));
1166
+ if (this.deviceLogging === 'debug') {
1167
+ this.platform.log.info('[DEBUG]', String(...log));
1215
1168
  }
1216
1169
  else {
1217
1170
  this.platform.log.debug(String(...log));
@@ -1219,7 +1172,7 @@ class Bot {
1219
1172
  }
1220
1173
  }
1221
1174
  enablingDeviceLogging() {
1222
- return (this.deviceLogging.includes("debug") || this.deviceLogging === "standard");
1175
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
1223
1176
  }
1224
1177
  }
1225
1178
  exports.Bot = Bot;