@switchbot/homebridge-switchbot 1.6.4-beta.1 → 1.6.4-beta.5
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 +3 -1
- package/config.schema.json +6 -0
- package/dist/devices/bots.d.ts +3 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +229 -149
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +26 -9
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -2
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +27 -10
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -11
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +27 -10
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +27 -10
- package/dist/devices/motion.js.map +1 -1
- package/dist/platform.d.ts +0 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +0 -12
- package/dist/platform.js.map +1 -1
- package/package.json +2 -2
- package/src/devices/bots.ts +208 -129
- package/src/devices/contact.ts +25 -9
- package/src/devices/curtains.ts +26 -10
- package/src/devices/humidifiers.ts +27 -11
- package/src/devices/meters.ts +26 -11
- package/src/devices/motion.ts +26 -10
- package/src/platform.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
5
5
|
## [Beta - Version 1.7.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.7.0) (2022-01-XX)
|
|
6
6
|
|
|
7
7
|
## What's Changed
|
|
8
|
-
* Added option to display Bot a Garage Door Opener
|
|
8
|
+
* Added option to display Bot a Garage Door Opener. [#179](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/179)
|
|
9
|
+
* Added option to display Bot a Door. [#179](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/179)
|
|
10
|
+
* Added option to display Bot a Lock. [#179](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/179)
|
|
9
11
|
|
|
10
12
|
**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.3...v1.7.0
|
|
11
13
|
|
package/config.schema.json
CHANGED
package/dist/devices/bots.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class Bot {
|
|
|
13
13
|
device: device & devicesConfig;
|
|
14
14
|
private switchService?;
|
|
15
15
|
private doorService?;
|
|
16
|
+
private lockService?;
|
|
16
17
|
private garageDoorService?;
|
|
17
18
|
private outletService?;
|
|
18
19
|
private batteryService?;
|
|
@@ -38,6 +39,7 @@ export declare class Bot {
|
|
|
38
39
|
private removeOutletService;
|
|
39
40
|
private removeGarageDoorService;
|
|
40
41
|
private removeDoorService;
|
|
42
|
+
private removeLockService;
|
|
41
43
|
private removeSwitchService;
|
|
42
44
|
refreshRate(): void;
|
|
43
45
|
scan(): void;
|
|
@@ -53,9 +55,8 @@ export declare class Bot {
|
|
|
53
55
|
* Asks the SwitchBot API for the latest device information
|
|
54
56
|
*/
|
|
55
57
|
refreshStatus(): Promise<void>;
|
|
56
|
-
|
|
58
|
+
connectBLE(): Promise<any>;
|
|
57
59
|
private BLERefreshStatus;
|
|
58
|
-
private BLEconnection;
|
|
59
60
|
private openAPIRefreshStatus;
|
|
60
61
|
/**
|
|
61
62
|
* Pushes the requested changes to the SwitchBot API
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bots.d.ts","sourceRoot":"","sources":["../../src/devices/bots.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,OAAO,EAAE,MAAM,MAAM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AE,GAAG,EAAE;IAUtB,qBAAqB,IAAI,OAAO;CAGjC"}
|
package/dist/devices/bots.js
CHANGED
|
@@ -52,6 +52,7 @@ class Bot {
|
|
|
52
52
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
53
53
|
// you can create multiple services for each accessory
|
|
54
54
|
if (device.bot?.deviceType === 'switch') {
|
|
55
|
+
this.removeLockService(accessory);
|
|
55
56
|
this.removeDoorService(accessory);
|
|
56
57
|
this.removeOutletService(accessory);
|
|
57
58
|
this.removeGarageDoorService(accessory);
|
|
@@ -64,6 +65,7 @@ class Bot {
|
|
|
64
65
|
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
65
66
|
}
|
|
66
67
|
else if (device.bot?.deviceType === 'garagedoor') {
|
|
68
|
+
this.removeLockService(accessory);
|
|
67
69
|
this.removeDoorService(accessory);
|
|
68
70
|
this.removeOutletService(accessory);
|
|
69
71
|
this.removeSwitchService(accessory);
|
|
@@ -77,6 +79,7 @@ class Bot {
|
|
|
77
79
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
|
|
78
80
|
}
|
|
79
81
|
else if (device.bot?.deviceType === 'door') {
|
|
82
|
+
this.removeLockService(accessory);
|
|
80
83
|
this.removeOutletService(accessory);
|
|
81
84
|
this.removeSwitchService(accessory);
|
|
82
85
|
this.removeGarageDoorService(accessory);
|
|
@@ -84,7 +87,7 @@ class Bot {
|
|
|
84
87
|
(this.doorService =
|
|
85
88
|
accessory.getService(this.platform.Service.Door) ||
|
|
86
89
|
accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
|
|
87
|
-
this.infoLog(`Bot: ${accessory.displayName} Displaying as
|
|
90
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
|
|
88
91
|
this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
89
92
|
this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
90
93
|
.setProps({
|
|
@@ -95,7 +98,21 @@ class Bot {
|
|
|
95
98
|
}).onSet(this.handleOnSet.bind(this));
|
|
96
99
|
this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
97
100
|
}
|
|
101
|
+
else if (device.bot?.deviceType === 'lock') {
|
|
102
|
+
this.removeDoorService(accessory);
|
|
103
|
+
this.removeOutletService(accessory);
|
|
104
|
+
this.removeSwitchService(accessory);
|
|
105
|
+
this.removeGarageDoorService(accessory);
|
|
106
|
+
// Add switchService
|
|
107
|
+
(this.lockService =
|
|
108
|
+
accessory.getService(this.platform.Service.LockMechanism) ||
|
|
109
|
+
accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
|
|
110
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
|
|
111
|
+
this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
112
|
+
this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
|
|
113
|
+
}
|
|
98
114
|
else {
|
|
115
|
+
this.removeLockService(accessory);
|
|
99
116
|
this.removeDoorService(accessory);
|
|
100
117
|
this.removeSwitchService(accessory);
|
|
101
118
|
this.removeGarageDoorService(accessory);
|
|
@@ -151,34 +168,42 @@ class Bot {
|
|
|
151
168
|
}
|
|
152
169
|
removeOutletService(accessory) {
|
|
153
170
|
// If outletService still pressent, then remove first
|
|
171
|
+
this.outletService = this.accessory.getService(this.platform.Service.Outlet);
|
|
154
172
|
if (this.outletService) {
|
|
155
|
-
this.
|
|
173
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
156
174
|
}
|
|
157
|
-
this.outletService = this.accessory.getService(this.platform.Service.Outlet);
|
|
158
175
|
accessory.removeService(this.outletService);
|
|
159
176
|
}
|
|
160
177
|
removeGarageDoorService(accessory) {
|
|
161
178
|
// If garageDoorService still pressent, then remove first
|
|
179
|
+
this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
|
|
162
180
|
if (this.garageDoorService) {
|
|
163
|
-
this.
|
|
181
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
164
182
|
}
|
|
165
|
-
this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
|
|
166
183
|
accessory.removeService(this.garageDoorService);
|
|
167
184
|
}
|
|
168
185
|
removeDoorService(accessory) {
|
|
169
186
|
// If doorService still pressent, then remove first
|
|
187
|
+
this.doorService = this.accessory.getService(this.platform.Service.Door);
|
|
170
188
|
if (this.doorService) {
|
|
171
|
-
this.
|
|
189
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Door Service`);
|
|
172
190
|
}
|
|
173
|
-
this.doorService = this.accessory.getService(this.platform.Service.Door);
|
|
174
191
|
accessory.removeService(this.doorService);
|
|
175
192
|
}
|
|
193
|
+
removeLockService(accessory) {
|
|
194
|
+
// If lockService still pressent, then remove first
|
|
195
|
+
this.lockService = this.accessory.getService(this.platform.Service.LockMechanism);
|
|
196
|
+
if (this.lockService) {
|
|
197
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
198
|
+
}
|
|
199
|
+
accessory.removeService(this.lockService);
|
|
200
|
+
}
|
|
176
201
|
removeSwitchService(accessory) {
|
|
177
202
|
// If switchService still pressent, then remove first
|
|
203
|
+
this.switchService = this.accessory.getService(this.platform.Service.Switch);
|
|
178
204
|
if (this.switchService) {
|
|
179
|
-
this.
|
|
205
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
180
206
|
}
|
|
181
|
-
this.switchService = this.accessory.getService(this.platform.Service.Switch);
|
|
182
207
|
accessory.removeService(this.switchService);
|
|
183
208
|
}
|
|
184
209
|
refreshRate() {
|
|
@@ -322,80 +347,92 @@ class Bot {
|
|
|
322
347
|
await this.openAPIRefreshStatus();
|
|
323
348
|
}
|
|
324
349
|
}
|
|
325
|
-
connectBLE() {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
350
|
+
async connectBLE() {
|
|
351
|
+
let switchbot;
|
|
352
|
+
try {
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
354
|
+
const Switchbot = require('node-switchbot');
|
|
355
|
+
switchbot = new Switchbot();
|
|
356
|
+
// Convert to BLE Address
|
|
357
|
+
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
358
|
+
this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
switchbot = false;
|
|
362
|
+
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
363
|
+
if (this.deviceLogging === 'debug') {
|
|
364
|
+
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
365
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
366
|
+
}
|
|
367
|
+
if (this.platform.debugMode) {
|
|
368
|
+
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
369
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
330
372
|
return switchbot;
|
|
331
373
|
}
|
|
332
374
|
async BLERefreshStatus() {
|
|
333
375
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
334
376
|
// Convert to BLE Address
|
|
335
|
-
const switchbot = this.connectBLE();
|
|
377
|
+
const switchbot = await this.connectBLE();
|
|
336
378
|
// Start to monitor advertisement packets
|
|
337
|
-
if (switchbot
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.connected = false;
|
|
357
|
-
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
// Wait 2 seconds
|
|
361
|
-
return switchbot.wait(this.scanDuration * 1000);
|
|
362
|
-
}).then(async () => {
|
|
363
|
-
// Stop to monitor
|
|
364
|
-
switchbot.stopScan();
|
|
365
|
-
if (this.connected) {
|
|
366
|
-
this.parseStatus();
|
|
367
|
-
this.updateHomeKitCharacteristics();
|
|
379
|
+
if (switchbot === false) {
|
|
380
|
+
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
381
|
+
}
|
|
382
|
+
switchbot.startScan({
|
|
383
|
+
model: 'H',
|
|
384
|
+
id: this.device.bleMac,
|
|
385
|
+
}).then(() => {
|
|
386
|
+
// Set an event hander
|
|
387
|
+
switchbot.onadvertisement = (ad) => {
|
|
388
|
+
this.serviceData = ad.serviceData;
|
|
389
|
+
this.mode = ad.serviceData.mode;
|
|
390
|
+
this.state = ad.serviceData.state;
|
|
391
|
+
this.battery = ad.serviceData.battery;
|
|
392
|
+
this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
393
|
+
this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
|
|
394
|
+
+ ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
|
|
395
|
+
if (this.serviceData) {
|
|
396
|
+
this.connected = true;
|
|
397
|
+
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
368
398
|
}
|
|
369
399
|
else {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}).catch(async (e) => {
|
|
373
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
374
|
-
if (this.deviceLogging === 'debug') {
|
|
375
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
376
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
377
|
-
}
|
|
378
|
-
if (this.platform.debugMode) {
|
|
379
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
380
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
400
|
+
this.connected = false;
|
|
401
|
+
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
381
402
|
}
|
|
403
|
+
};
|
|
404
|
+
// Wait 2 seconds
|
|
405
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
406
|
+
}).then(async () => {
|
|
407
|
+
// Stop to monitor
|
|
408
|
+
switchbot.stopScan();
|
|
409
|
+
if (this.connected) {
|
|
410
|
+
this.parseStatus();
|
|
411
|
+
this.updateHomeKitCharacteristics();
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
382
415
|
if (this.platform.config.credentials?.openToken) {
|
|
383
416
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
384
417
|
await this.openAPIRefreshStatus();
|
|
385
418
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
419
|
+
}
|
|
420
|
+
}).catch(async (e) => {
|
|
421
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
422
|
+
if (this.deviceLogging === 'debug') {
|
|
423
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
424
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
425
|
+
}
|
|
426
|
+
if (this.platform.debugMode) {
|
|
427
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
428
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
429
|
+
}
|
|
430
|
+
if (this.platform.config.credentials?.openToken) {
|
|
431
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
432
|
+
await this.openAPIRefreshStatus();
|
|
433
|
+
}
|
|
434
|
+
this.apiError(e);
|
|
435
|
+
});
|
|
399
436
|
}
|
|
400
437
|
async openAPIRefreshStatus() {
|
|
401
438
|
if (this.platform.config.credentials?.openToken) {
|
|
@@ -442,84 +479,84 @@ class Bot {
|
|
|
442
479
|
});
|
|
443
480
|
}
|
|
444
481
|
async BLEpushChanges() {
|
|
482
|
+
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
445
483
|
if (this.On !== this.OnCached) {
|
|
446
484
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
447
|
-
const switchbot = this.connectBLE();
|
|
448
|
-
if (switchbot !== false) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
466
|
-
}
|
|
467
|
-
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
468
|
-
}, 500);
|
|
469
|
-
}).catch(async (e) => {
|
|
470
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
471
|
-
if (this.deviceLogging === 'debug') {
|
|
472
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
473
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
474
|
-
}
|
|
475
|
-
if (this.platform.debugMode) {
|
|
476
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
477
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
478
|
-
}
|
|
479
|
-
if (this.platform.config.credentials?.openToken) {
|
|
480
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
481
|
-
await this.openAPIpushChanges();
|
|
482
|
-
}
|
|
483
|
-
this.apiError(e);
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
else if (this.botMode === 'switch') {
|
|
487
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
488
|
-
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
489
|
-
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
490
|
-
return this.turnOnOff(device_list);
|
|
491
|
-
}).then(() => {
|
|
492
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
493
|
-
this.OnCached = this.On;
|
|
494
|
-
this.accessory.context.On = this.OnCached;
|
|
495
|
-
}).catch(async (e) => {
|
|
496
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
497
|
-
if (this.deviceLogging === 'debug') {
|
|
498
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
499
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
500
|
-
}
|
|
501
|
-
if (this.platform.debugMode) {
|
|
502
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
503
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
485
|
+
const switchbot = await this.connectBLE();
|
|
486
|
+
//if (switchbot !== false) {
|
|
487
|
+
if (this.botMode === 'press') {
|
|
488
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
489
|
+
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
490
|
+
.then((device_list) => {
|
|
491
|
+
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
492
|
+
return device_list[0].press({ id: this.device.bleMac });
|
|
493
|
+
}).then(() => {
|
|
494
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
495
|
+
this.On = false;
|
|
496
|
+
this.OnCached = this.On;
|
|
497
|
+
this.accessory.context.On = this.OnCached;
|
|
498
|
+
setTimeout(() => {
|
|
499
|
+
if (this.device.bot?.deviceType === 'switch') {
|
|
500
|
+
this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
504
501
|
}
|
|
505
|
-
|
|
506
|
-
this.
|
|
507
|
-
await this.openAPIpushChanges();
|
|
502
|
+
else {
|
|
503
|
+
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
508
504
|
}
|
|
509
|
-
this.
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
505
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
506
|
+
}, 500);
|
|
507
|
+
}).catch(async (e) => {
|
|
508
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
509
|
+
if (this.deviceLogging === 'debug') {
|
|
510
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
511
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
512
|
+
}
|
|
513
|
+
if (this.platform.debugMode) {
|
|
514
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
515
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
516
|
+
}
|
|
517
|
+
if (this.platform.config.credentials?.openToken) {
|
|
518
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
519
|
+
await this.openAPIpushChanges();
|
|
520
|
+
}
|
|
521
|
+
this.apiError(e);
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
else if (this.botMode === 'switch') {
|
|
525
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
526
|
+
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
527
|
+
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
528
|
+
return this.turnOnOff(device_list);
|
|
529
|
+
}).then(() => {
|
|
530
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
531
|
+
this.OnCached = this.On;
|
|
532
|
+
this.accessory.context.On = this.OnCached;
|
|
533
|
+
}).catch(async (e) => {
|
|
534
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
535
|
+
if (this.deviceLogging === 'debug') {
|
|
536
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
537
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
538
|
+
}
|
|
539
|
+
if (this.platform.debugMode) {
|
|
540
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
541
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
542
|
+
}
|
|
543
|
+
if (this.platform.config.credentials?.openToken) {
|
|
544
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
545
|
+
await this.openAPIpushChanges();
|
|
546
|
+
}
|
|
547
|
+
this.apiError(e);
|
|
548
|
+
});
|
|
515
549
|
}
|
|
516
550
|
else {
|
|
517
|
-
|
|
518
|
-
if (this.platform.config.credentials?.openToken) {
|
|
519
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
520
|
-
await this.openAPIpushChanges();
|
|
521
|
-
}
|
|
551
|
+
throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
522
552
|
}
|
|
553
|
+
/* } else {
|
|
554
|
+
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
555
|
+
if (this.platform.config.credentials?.openToken) {
|
|
556
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
557
|
+
await this.openAPIpushChanges();
|
|
558
|
+
}
|
|
559
|
+
}*/
|
|
523
560
|
}
|
|
524
561
|
this.OnCached = this.On;
|
|
525
562
|
this.accessory.context.On = this.OnCached;
|
|
@@ -603,7 +640,7 @@ class Bot {
|
|
|
603
640
|
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
604
641
|
}
|
|
605
642
|
}
|
|
606
|
-
this.debugLog(`Bot: ${this.accessory.displayName}
|
|
643
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
607
644
|
}
|
|
608
645
|
else if (this.device.bot?.deviceType === 'door') {
|
|
609
646
|
if (this.On === undefined) {
|
|
@@ -611,17 +648,37 @@ class Bot {
|
|
|
611
648
|
}
|
|
612
649
|
else {
|
|
613
650
|
if (this.On) {
|
|
614
|
-
this.
|
|
615
|
-
this.
|
|
651
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
|
|
652
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
|
|
653
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
616
654
|
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
617
655
|
}
|
|
618
656
|
else {
|
|
619
|
-
this.
|
|
620
|
-
this.
|
|
657
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
|
|
658
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
|
|
659
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
621
660
|
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
622
661
|
}
|
|
623
662
|
}
|
|
624
|
-
this.debugLog(`Bot: ${this.accessory.displayName}
|
|
663
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
664
|
+
}
|
|
665
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
666
|
+
if (this.On === undefined) {
|
|
667
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
if (this.On) {
|
|
671
|
+
this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.UNSECURED);
|
|
672
|
+
this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.platform.Characteristic.LockCurrentState.UNSECURED);
|
|
673
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.SECURED);
|
|
677
|
+
this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.platform.Characteristic.LockCurrentState.SECURED);
|
|
678
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
625
682
|
}
|
|
626
683
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
627
684
|
if (this.On === undefined) {
|
|
@@ -659,7 +716,21 @@ class Bot {
|
|
|
659
716
|
}
|
|
660
717
|
}
|
|
661
718
|
apiError(e) {
|
|
662
|
-
if (this.device.bot?.deviceType === '
|
|
719
|
+
if (this.device.bot?.deviceType === 'garagedoor') {
|
|
720
|
+
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
|
|
721
|
+
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
|
|
722
|
+
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, e);
|
|
723
|
+
}
|
|
724
|
+
else if (this.device.bot?.deviceType === 'door') {
|
|
725
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
726
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
727
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
728
|
+
}
|
|
729
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
730
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
|
|
731
|
+
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
|
|
732
|
+
}
|
|
733
|
+
else if (this.device.bot?.deviceType === 'switch') {
|
|
663
734
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
664
735
|
}
|
|
665
736
|
else {
|
|
@@ -727,7 +798,16 @@ class Bot {
|
|
|
727
798
|
}
|
|
728
799
|
else if (this.device.bot?.deviceType === 'door') {
|
|
729
800
|
this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
730
|
-
if (value ===
|
|
801
|
+
if (value === 0) {
|
|
802
|
+
this.On = false;
|
|
803
|
+
}
|
|
804
|
+
else {
|
|
805
|
+
this.On = true;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
809
|
+
this.debugLog(`Bot: ${this.accessory.displayName} LockTargetState: ${value}`);
|
|
810
|
+
if (value === this.platform.Characteristic.LockTargetState.SECURED) {
|
|
731
811
|
this.On = false;
|
|
732
812
|
}
|
|
733
813
|
else {
|