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