@switchbot/homebridge-switchbot 1.7.0 → 1.7.1-beta.11
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.
- package/CHANGELOG.md +17 -0
- package/config.schema.json +101 -33
- package/dist/devices/bots.d.ts +9 -5
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +144 -77
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +9 -4
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +40 -37
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +10 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +92 -51
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +10 -3
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +52 -34
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +8 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -35
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +14 -12
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +63 -103
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +10 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +114 -68
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +3 -1
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +8 -1
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +1 -0
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +6 -0
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +1 -0
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +6 -0
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +1 -0
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +6 -0
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +1 -0
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +6 -0
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +1 -0
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +6 -0
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +1 -0
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +6 -0
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +1 -0
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +6 -0
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +1 -0
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +6 -0
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +1 -0
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +6 -0
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +14 -1
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +14 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +71 -71
- package/src/devices/bots.ts +140 -74
- package/src/devices/colorbulb.ts +46 -40
- package/src/devices/contact.ts +99 -55
- package/src/devices/curtains.ts +60 -36
- package/src/devices/humidifiers.ts +36 -36
- package/src/devices/meters.ts +79 -113
- package/src/devices/motion.ts +125 -74
- package/src/devices/plugs.ts +11 -2
- package/src/irdevices/airconditioners.ts +7 -0
- package/src/irdevices/airpurifiers.ts +7 -0
- package/src/irdevices/cameras.ts +7 -0
- package/src/irdevices/fans.ts +7 -0
- package/src/irdevices/lights.ts +7 -0
- package/src/irdevices/others.ts +7 -0
- package/src/irdevices/tvs.ts +7 -0
- package/src/irdevices/vacuumcleaners.ts +7 -0
- package/src/irdevices/waterheaters.ts +7 -0
- package/src/platform.ts +14 -1
- package/src/settings.ts +15 -0
package/dist/devices/bots.js
CHANGED
|
@@ -15,10 +15,11 @@ class Bot {
|
|
|
15
15
|
this.accessory = accessory;
|
|
16
16
|
this.device = device;
|
|
17
17
|
// default placeholders
|
|
18
|
-
this.logs();
|
|
19
|
-
this.scan();
|
|
20
|
-
this.refreshRate();
|
|
18
|
+
this.logs(device);
|
|
19
|
+
this.scan(device);
|
|
20
|
+
this.refreshRate(device);
|
|
21
21
|
this.PressOrSwitch();
|
|
22
|
+
this.config(device);
|
|
22
23
|
if (this.On === undefined) {
|
|
23
24
|
this.On = false;
|
|
24
25
|
this.accessory.context.On = this.On;
|
|
@@ -35,9 +36,6 @@ class Bot {
|
|
|
35
36
|
}
|
|
36
37
|
this.BatteryLevel = 100;
|
|
37
38
|
this.StatusLowBattery = 0;
|
|
38
|
-
// Bot Config
|
|
39
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
|
|
40
|
-
+ ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`);
|
|
41
39
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
42
40
|
this.doBotUpdate = new rxjs_1.Subject();
|
|
43
41
|
this.botUpdateInProgress = false;
|
|
@@ -60,6 +58,7 @@ class Bot {
|
|
|
60
58
|
this.removeWindowService(accessory);
|
|
61
59
|
this.removeGarageDoorService(accessory);
|
|
62
60
|
this.removeWindowCoveringService(accessory);
|
|
61
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
63
62
|
// Add switchService
|
|
64
63
|
(this.switchService =
|
|
65
64
|
accessory.getService(this.platform.Service.Switch) ||
|
|
@@ -77,6 +76,7 @@ class Bot {
|
|
|
77
76
|
this.removeSwitchService(accessory);
|
|
78
77
|
this.removeWindowService(accessory);
|
|
79
78
|
this.removeWindowCoveringService(accessory);
|
|
79
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
80
80
|
// Add switchService
|
|
81
81
|
(this.garageDoorService =
|
|
82
82
|
accessory.getService(this.platform.Service.GarageDoorOpener) ||
|
|
@@ -95,6 +95,7 @@ class Bot {
|
|
|
95
95
|
this.removeWindowService(accessory);
|
|
96
96
|
this.removeGarageDoorService(accessory);
|
|
97
97
|
this.removeWindowCoveringService(accessory);
|
|
98
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
98
99
|
// Add switchService
|
|
99
100
|
(this.doorService =
|
|
100
101
|
accessory.getService(this.platform.Service.Door) ||
|
|
@@ -119,6 +120,7 @@ class Bot {
|
|
|
119
120
|
this.removeSwitchService(accessory);
|
|
120
121
|
this.removeGarageDoorService(accessory);
|
|
121
122
|
this.removeWindowCoveringService(accessory);
|
|
123
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
122
124
|
// Add switchService
|
|
123
125
|
(this.windowService =
|
|
124
126
|
accessory.getService(this.platform.Service.Window) ||
|
|
@@ -143,6 +145,7 @@ class Bot {
|
|
|
143
145
|
this.removeSwitchService(accessory);
|
|
144
146
|
this.removeWindowService(accessory);
|
|
145
147
|
this.removeGarageDoorService(accessory);
|
|
148
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
146
149
|
// Add switchService
|
|
147
150
|
(this.windowCoveringService =
|
|
148
151
|
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
@@ -167,6 +170,7 @@ class Bot {
|
|
|
167
170
|
this.removeWindowService(accessory);
|
|
168
171
|
this.removeGarageDoorService(accessory);
|
|
169
172
|
this.removeWindowCoveringService(accessory);
|
|
173
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
170
174
|
// Add switchService
|
|
171
175
|
(this.lockService =
|
|
172
176
|
accessory.getService(this.platform.Service.LockMechanism) ||
|
|
@@ -184,6 +188,7 @@ class Bot {
|
|
|
184
188
|
this.removeWindowService(accessory);
|
|
185
189
|
this.removeGarageDoorService(accessory);
|
|
186
190
|
this.removeWindowCoveringService(accessory);
|
|
191
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
187
192
|
// Add switchService
|
|
188
193
|
(this.faucetService =
|
|
189
194
|
accessory.getService(this.platform.Service.Faucet) ||
|
|
@@ -201,6 +206,7 @@ class Bot {
|
|
|
201
206
|
this.removeWindowService(accessory);
|
|
202
207
|
this.removeGarageDoorService(accessory);
|
|
203
208
|
this.removeWindowCoveringService(accessory);
|
|
209
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
204
210
|
// Add switchService
|
|
205
211
|
(this.fanService =
|
|
206
212
|
accessory.getService(this.platform.Service.Fan) ||
|
|
@@ -209,6 +215,25 @@ class Bot {
|
|
|
209
215
|
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
210
216
|
this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
211
217
|
}
|
|
218
|
+
else if (device.bot?.deviceType === 'stateful') {
|
|
219
|
+
this.removeFanService(accessory);
|
|
220
|
+
this.removeLockService(accessory);
|
|
221
|
+
this.removeDoorService(accessory);
|
|
222
|
+
this.removeFaucetService(accessory);
|
|
223
|
+
this.removeOutletService(accessory);
|
|
224
|
+
this.removeSwitchService(accessory);
|
|
225
|
+
this.removeWindowService(accessory);
|
|
226
|
+
this.removeGarageDoorService(accessory);
|
|
227
|
+
this.removeWindowCoveringService(accessory);
|
|
228
|
+
// Add switchService
|
|
229
|
+
(this.statefulProgrammableSwitchService =
|
|
230
|
+
accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
|
|
231
|
+
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
|
|
232
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
233
|
+
this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
234
|
+
this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
|
|
235
|
+
.onSet(this.handleOnSet.bind(this));
|
|
236
|
+
}
|
|
212
237
|
else {
|
|
213
238
|
this.removeFanService(accessory);
|
|
214
239
|
this.removeLockService(accessory);
|
|
@@ -218,6 +243,7 @@ class Bot {
|
|
|
218
243
|
this.removeWindowService(accessory);
|
|
219
244
|
this.removeGarageDoorService(accessory);
|
|
220
245
|
this.removeWindowCoveringService(accessory);
|
|
246
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
221
247
|
// Add outletService
|
|
222
248
|
(this.outletService =
|
|
223
249
|
accessory.getService(this.platform.Service.Outlet) ||
|
|
@@ -226,12 +252,22 @@ class Bot {
|
|
|
226
252
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
227
253
|
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
228
254
|
}
|
|
229
|
-
|
|
255
|
+
// Battery Service
|
|
256
|
+
if (!device.ble) {
|
|
257
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
|
|
258
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
259
|
+
accessory.removeService(this.batteryService);
|
|
260
|
+
}
|
|
261
|
+
else if (device.ble && !this.batteryService) {
|
|
262
|
+
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
230
263
|
(this.batteryService =
|
|
231
|
-
accessory.getService(this.platform.Service.Battery) ||
|
|
232
|
-
accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
264
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
265
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
233
266
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
234
267
|
}
|
|
268
|
+
else {
|
|
269
|
+
this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
|
|
270
|
+
}
|
|
235
271
|
// Retrieve initial values and updateHomekit
|
|
236
272
|
this.updateHomeKitCharacteristics();
|
|
237
273
|
// Start an update interval
|
|
@@ -332,6 +368,14 @@ class Bot {
|
|
|
332
368
|
}
|
|
333
369
|
accessory.removeService(this.windowCoveringService);
|
|
334
370
|
}
|
|
371
|
+
removeStatefulProgrammableSwitchService(accessory) {
|
|
372
|
+
// If statefulProgrammableSwitchService still pressent, then remove first
|
|
373
|
+
this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
|
|
374
|
+
if (this.statefulProgrammableSwitchService) {
|
|
375
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
376
|
+
}
|
|
377
|
+
accessory.removeService(this.statefulProgrammableSwitchService);
|
|
378
|
+
}
|
|
335
379
|
removeSwitchService(accessory) {
|
|
336
380
|
// If switchService still pressent, then remove first
|
|
337
381
|
this.switchService = this.accessory.getService(this.platform.Service.Switch);
|
|
@@ -340,53 +384,54 @@ class Bot {
|
|
|
340
384
|
}
|
|
341
385
|
accessory.removeService(this.switchService);
|
|
342
386
|
}
|
|
343
|
-
|
|
344
|
-
if (
|
|
345
|
-
this.
|
|
346
|
-
if (
|
|
347
|
-
this.
|
|
387
|
+
scan(device) {
|
|
388
|
+
if (device.scanDuration) {
|
|
389
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
390
|
+
if (device.ble) {
|
|
391
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
348
392
|
}
|
|
349
393
|
}
|
|
350
|
-
else
|
|
351
|
-
this.
|
|
352
|
-
if (this.
|
|
353
|
-
this.
|
|
394
|
+
else {
|
|
395
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
396
|
+
if (this.device.ble) {
|
|
397
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
354
398
|
}
|
|
355
399
|
}
|
|
356
400
|
}
|
|
357
|
-
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
401
|
+
config(device) {
|
|
402
|
+
if (device.bot !== undefined) {
|
|
403
|
+
device.bot['ble'] = device.ble;
|
|
404
|
+
device.bot['logging'] = this.deviceLogging;
|
|
405
|
+
device.bot['refreshRate'] = this.deviceRefreshRate;
|
|
406
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(device.bot)}`);
|
|
363
407
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
408
|
+
}
|
|
409
|
+
refreshRate(device) {
|
|
410
|
+
if (device.refreshRate) {
|
|
411
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
412
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
413
|
+
}
|
|
414
|
+
else if (this.platform.config.options.refreshRate) {
|
|
415
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
416
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
369
417
|
}
|
|
370
418
|
}
|
|
371
|
-
logs() {
|
|
419
|
+
logs(device) {
|
|
372
420
|
if (this.platform.debugMode) {
|
|
373
|
-
this.deviceLogging = this.accessory.context.logging = '
|
|
374
|
-
this.
|
|
421
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
422
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
375
423
|
}
|
|
376
|
-
else if (
|
|
377
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
378
|
-
|
|
379
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
380
|
-
}
|
|
424
|
+
else if (device.logging) {
|
|
425
|
+
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
426
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
381
427
|
}
|
|
382
428
|
else if (this.platform.config.options?.logging) {
|
|
383
429
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
384
|
-
|
|
385
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
386
|
-
}
|
|
430
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
387
431
|
}
|
|
388
432
|
else {
|
|
389
433
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
434
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
390
435
|
}
|
|
391
436
|
}
|
|
392
437
|
PressOrSwitch() {
|
|
@@ -411,11 +456,11 @@ class Bot {
|
|
|
411
456
|
* Parse the device status from the SwitchBot api
|
|
412
457
|
*/
|
|
413
458
|
async parseStatus() {
|
|
414
|
-
if (this.device.ble) {
|
|
415
|
-
await this.
|
|
459
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
460
|
+
await this.openAPIparseStatus();
|
|
416
461
|
}
|
|
417
462
|
else {
|
|
418
|
-
await this.
|
|
463
|
+
await this.BLEparseStatus();
|
|
419
464
|
}
|
|
420
465
|
}
|
|
421
466
|
async BLEparseStatus() {
|
|
@@ -448,6 +493,9 @@ class Bot {
|
|
|
448
493
|
this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
449
494
|
}
|
|
450
495
|
async openAPIparseStatus() {
|
|
496
|
+
if (this.device.ble) {
|
|
497
|
+
this.SwitchToOpenAPI = false;
|
|
498
|
+
}
|
|
451
499
|
if (this.platform.config.credentials?.openToken) {
|
|
452
500
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
453
501
|
if (this.botMode === 'press') {
|
|
@@ -456,15 +504,19 @@ class Bot {
|
|
|
456
504
|
this.accessory.context.On = this.OnCached;
|
|
457
505
|
}
|
|
458
506
|
else {
|
|
459
|
-
if (this.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
507
|
+
/*if (this.power === 'on') {
|
|
508
|
+
this.On = true;
|
|
509
|
+
this.OnCached = this.On;
|
|
510
|
+
this.accessory.context.On = this.OnCached;
|
|
511
|
+
} else {
|
|
512
|
+
this.On = false;
|
|
513
|
+
this.OnCached = this.On;
|
|
514
|
+
this.accessory.context.On = this.OnCached;
|
|
515
|
+
}*/
|
|
516
|
+
this.OnCached = this.On;
|
|
517
|
+
this.accessory.context.On = this.OnCached;
|
|
518
|
+
if (this.On === undefined) {
|
|
465
519
|
this.On = false;
|
|
466
|
-
this.OnCached = this.On;
|
|
467
|
-
this.accessory.context.On = this.OnCached;
|
|
468
520
|
}
|
|
469
521
|
}
|
|
470
522
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -481,34 +533,12 @@ class Bot {
|
|
|
481
533
|
await this.openAPIRefreshStatus();
|
|
482
534
|
}
|
|
483
535
|
}
|
|
484
|
-
async connectBLE() {
|
|
485
|
-
let switchbot;
|
|
486
|
-
try {
|
|
487
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
488
|
-
const Switchbot = require('node-switchbot');
|
|
489
|
-
switchbot = new Switchbot();
|
|
490
|
-
// Convert to BLE Address
|
|
491
|
-
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
492
|
-
this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
switchbot = false;
|
|
496
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
497
|
-
if (this.deviceLogging === 'debug') {
|
|
498
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
499
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
500
|
-
}
|
|
501
|
-
if (this.platform.debugMode) {
|
|
502
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
503
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return switchbot;
|
|
507
|
-
}
|
|
508
536
|
async BLERefreshStatus() {
|
|
509
537
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
538
|
+
const switchbot = await this.platform.connectBLE();
|
|
510
539
|
// Convert to BLE Address
|
|
511
|
-
|
|
540
|
+
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
541
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
512
542
|
// Start to monitor advertisement packets
|
|
513
543
|
if (switchbot === false) {
|
|
514
544
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
@@ -548,6 +578,7 @@ class Bot {
|
|
|
548
578
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
549
579
|
if (this.platform.config.credentials?.openToken) {
|
|
550
580
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
581
|
+
this.SwitchToOpenAPI = true;
|
|
551
582
|
await this.openAPIRefreshStatus();
|
|
552
583
|
}
|
|
553
584
|
}
|
|
@@ -563,6 +594,7 @@ class Bot {
|
|
|
563
594
|
}
|
|
564
595
|
if (this.platform.config.credentials?.openToken) {
|
|
565
596
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
597
|
+
this.SwitchToOpenAPI = true;
|
|
566
598
|
await this.openAPIRefreshStatus();
|
|
567
599
|
}
|
|
568
600
|
this.apiError(e);
|
|
@@ -574,6 +606,7 @@ class Bot {
|
|
|
574
606
|
try {
|
|
575
607
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
576
608
|
this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
609
|
+
this.power = this.deviceStatus.body.power;
|
|
577
610
|
this.parseStatus();
|
|
578
611
|
this.updateHomeKitCharacteristics();
|
|
579
612
|
}
|
|
@@ -616,7 +649,10 @@ class Bot {
|
|
|
616
649
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
617
650
|
if (this.On !== this.OnCached) {
|
|
618
651
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
619
|
-
const switchbot = await this.connectBLE();
|
|
652
|
+
const switchbot = await this.platform.connectBLE();
|
|
653
|
+
// Convert to BLE Address
|
|
654
|
+
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
655
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
620
656
|
//if (switchbot !== false) {
|
|
621
657
|
if (this.botMode === 'press') {
|
|
622
658
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
@@ -886,6 +922,24 @@ class Bot {
|
|
|
886
922
|
}
|
|
887
923
|
this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
888
924
|
}
|
|
925
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
926
|
+
if (this.On === undefined) {
|
|
927
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
if (this.On) {
|
|
931
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
932
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
933
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
937
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
938
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
942
|
+
}
|
|
889
943
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
890
944
|
if (this.On === undefined) {
|
|
891
945
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -952,6 +1006,10 @@ class Bot {
|
|
|
952
1006
|
else if (this.device.bot?.deviceType === 'fan') {
|
|
953
1007
|
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
954
1008
|
}
|
|
1009
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
1010
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
|
|
1011
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1012
|
+
}
|
|
955
1013
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
956
1014
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
957
1015
|
}
|
|
@@ -1047,6 +1105,15 @@ class Bot {
|
|
|
1047
1105
|
this.On = true;
|
|
1048
1106
|
}
|
|
1049
1107
|
}
|
|
1108
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
1109
|
+
this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
|
|
1110
|
+
if (value === 0) {
|
|
1111
|
+
this.On = false;
|
|
1112
|
+
}
|
|
1113
|
+
else {
|
|
1114
|
+
this.On = true;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1050
1117
|
else {
|
|
1051
1118
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
|
|
1052
1119
|
this.On = value;
|