@switchbot/homebridge-switchbot 1.6.4-beta.0 → 1.6.4-beta.4
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 +12 -0
- package/dist/devices/bots.d.ts +5 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +276 -139
- 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 +253 -119
- 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
|
@@ -12,6 +12,8 @@ export declare class Bot {
|
|
|
12
12
|
private accessory;
|
|
13
13
|
device: device & devicesConfig;
|
|
14
14
|
private switchService?;
|
|
15
|
+
private doorService?;
|
|
16
|
+
private lockService?;
|
|
15
17
|
private garageDoorService?;
|
|
16
18
|
private outletService?;
|
|
17
19
|
private batteryService?;
|
|
@@ -36,6 +38,8 @@ export declare class Bot {
|
|
|
36
38
|
constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device & devicesConfig);
|
|
37
39
|
private removeOutletService;
|
|
38
40
|
private removeGarageDoorService;
|
|
41
|
+
private removeDoorService;
|
|
42
|
+
private removeLockService;
|
|
39
43
|
private removeSwitchService;
|
|
40
44
|
refreshRate(): void;
|
|
41
45
|
scan(): void;
|
|
@@ -51,9 +55,8 @@ export declare class Bot {
|
|
|
51
55
|
* Asks the SwitchBot API for the latest device information
|
|
52
56
|
*/
|
|
53
57
|
refreshStatus(): Promise<void>;
|
|
54
|
-
|
|
58
|
+
connectBLE(): Promise<any>;
|
|
55
59
|
private BLERefreshStatus;
|
|
56
|
-
private BLEconnection;
|
|
57
60
|
private openAPIRefreshStatus;
|
|
58
61
|
/**
|
|
59
62
|
* Pushes the requested changes to the SwitchBot API
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bots.d.ts","source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MrB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMtB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAUtB,qBAAqB,IAAI,OAAO;CAGjC"}
|
package/dist/devices/bots.js
CHANGED
|
@@ -52,6 +52,8 @@ 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);
|
|
56
|
+
this.removeDoorService(accessory);
|
|
55
57
|
this.removeOutletService(accessory);
|
|
56
58
|
this.removeGarageDoorService(accessory);
|
|
57
59
|
// Add switchService
|
|
@@ -63,6 +65,8 @@ class Bot {
|
|
|
63
65
|
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
64
66
|
}
|
|
65
67
|
else if (device.bot?.deviceType === 'garagedoor') {
|
|
68
|
+
this.removeLockService(accessory);
|
|
69
|
+
this.removeDoorService(accessory);
|
|
66
70
|
this.removeOutletService(accessory);
|
|
67
71
|
this.removeSwitchService(accessory);
|
|
68
72
|
// Add switchService
|
|
@@ -74,7 +78,42 @@ class Bot {
|
|
|
74
78
|
this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
|
|
75
79
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
|
|
76
80
|
}
|
|
81
|
+
else if (device.bot?.deviceType === 'door') {
|
|
82
|
+
this.removeLockService(accessory);
|
|
83
|
+
this.removeOutletService(accessory);
|
|
84
|
+
this.removeSwitchService(accessory);
|
|
85
|
+
this.removeGarageDoorService(accessory);
|
|
86
|
+
// Add switchService
|
|
87
|
+
(this.doorService =
|
|
88
|
+
accessory.getService(this.platform.Service.Door) ||
|
|
89
|
+
accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
|
|
90
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
|
|
91
|
+
this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
92
|
+
this.doorService.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
93
|
+
.setProps({
|
|
94
|
+
validValues: [0, 100],
|
|
95
|
+
minValue: 0,
|
|
96
|
+
maxValue: 100,
|
|
97
|
+
minStep: 100,
|
|
98
|
+
}).onSet(this.handleOnSet.bind(this));
|
|
99
|
+
this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
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
|
+
}
|
|
77
114
|
else {
|
|
115
|
+
this.removeLockService(accessory);
|
|
116
|
+
this.removeDoorService(accessory);
|
|
78
117
|
this.removeSwitchService(accessory);
|
|
79
118
|
this.removeGarageDoorService(accessory);
|
|
80
119
|
// Add outletService
|
|
@@ -136,12 +175,28 @@ class Bot {
|
|
|
136
175
|
accessory.removeService(this.outletService);
|
|
137
176
|
}
|
|
138
177
|
removeGarageDoorService(accessory) {
|
|
139
|
-
// If
|
|
140
|
-
if (this.
|
|
141
|
-
this.debugLog(`Bot: ${accessory.displayName} Removing Leftover
|
|
178
|
+
// If garageDoorService still pressent, then remove first
|
|
179
|
+
if (this.garageDoorService) {
|
|
180
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Leftover garageDoorService first`);
|
|
142
181
|
}
|
|
143
|
-
this.
|
|
144
|
-
accessory.removeService(this.
|
|
182
|
+
this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
|
|
183
|
+
accessory.removeService(this.garageDoorService);
|
|
184
|
+
}
|
|
185
|
+
removeDoorService(accessory) {
|
|
186
|
+
// If doorService still pressent, then remove first
|
|
187
|
+
if (this.doorService) {
|
|
188
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Leftover doorService first`);
|
|
189
|
+
}
|
|
190
|
+
this.doorService = this.accessory.getService(this.platform.Service.Door);
|
|
191
|
+
accessory.removeService(this.doorService);
|
|
192
|
+
}
|
|
193
|
+
removeLockService(accessory) {
|
|
194
|
+
// If lockService still pressent, then remove first
|
|
195
|
+
if (this.lockService) {
|
|
196
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Leftover lockService first`);
|
|
197
|
+
}
|
|
198
|
+
this.lockService = this.accessory.getService(this.platform.Service.Door);
|
|
199
|
+
accessory.removeService(this.lockService);
|
|
145
200
|
}
|
|
146
201
|
removeSwitchService(accessory) {
|
|
147
202
|
// If switchService still pressent, then remove first
|
|
@@ -292,80 +347,92 @@ class Bot {
|
|
|
292
347
|
await this.openAPIRefreshStatus();
|
|
293
348
|
}
|
|
294
349
|
}
|
|
295
|
-
connectBLE() {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
}
|
|
300
372
|
return switchbot;
|
|
301
373
|
}
|
|
302
374
|
async BLERefreshStatus() {
|
|
303
375
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
304
376
|
// Convert to BLE Address
|
|
305
|
-
const switchbot = this.connectBLE();
|
|
377
|
+
const switchbot = await this.connectBLE();
|
|
306
378
|
// Start to monitor advertisement packets
|
|
307
|
-
if (switchbot
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.connected = false;
|
|
327
|
-
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
// Wait 2 seconds
|
|
331
|
-
return switchbot.wait(this.scanDuration * 1000);
|
|
332
|
-
}).then(async () => {
|
|
333
|
-
// Stop to monitor
|
|
334
|
-
switchbot.stopScan();
|
|
335
|
-
if (this.connected) {
|
|
336
|
-
this.parseStatus();
|
|
337
|
-
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}`);
|
|
338
398
|
}
|
|
339
399
|
else {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}).catch(async (e) => {
|
|
343
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
344
|
-
if (this.deviceLogging === 'debug') {
|
|
345
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
346
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
347
|
-
}
|
|
348
|
-
if (this.platform.debugMode) {
|
|
349
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
350
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
400
|
+
this.connected = false;
|
|
401
|
+
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
351
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`);
|
|
352
415
|
if (this.platform.config.credentials?.openToken) {
|
|
353
416
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
354
417
|
await this.openAPIRefreshStatus();
|
|
355
418
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
+
});
|
|
369
436
|
}
|
|
370
437
|
async openAPIRefreshStatus() {
|
|
371
438
|
if (this.platform.config.credentials?.openToken) {
|
|
@@ -412,84 +479,84 @@ class Bot {
|
|
|
412
479
|
});
|
|
413
480
|
}
|
|
414
481
|
async BLEpushChanges() {
|
|
482
|
+
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
415
483
|
if (this.On !== this.OnCached) {
|
|
416
484
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
417
|
-
const switchbot = this.connectBLE();
|
|
418
|
-
if (switchbot !== false) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
else {
|
|
435
|
-
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
436
|
-
}
|
|
437
|
-
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
438
|
-
}, 500);
|
|
439
|
-
}).catch(async (e) => {
|
|
440
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
441
|
-
if (this.deviceLogging === 'debug') {
|
|
442
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
443
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
444
|
-
}
|
|
445
|
-
if (this.platform.debugMode) {
|
|
446
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
447
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
448
|
-
}
|
|
449
|
-
if (this.platform.config.credentials?.openToken) {
|
|
450
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
451
|
-
await this.openAPIpushChanges();
|
|
452
|
-
}
|
|
453
|
-
this.apiError(e);
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
else if (this.botMode === 'switch') {
|
|
457
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
458
|
-
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
459
|
-
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
460
|
-
return this.turnOnOff(device_list);
|
|
461
|
-
}).then(() => {
|
|
462
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
463
|
-
this.OnCached = this.On;
|
|
464
|
-
this.accessory.context.On = this.OnCached;
|
|
465
|
-
}).catch(async (e) => {
|
|
466
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
467
|
-
if (this.deviceLogging === 'debug') {
|
|
468
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
469
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
470
|
-
}
|
|
471
|
-
if (this.platform.debugMode) {
|
|
472
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
473
|
-
+ ` 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);
|
|
474
501
|
}
|
|
475
|
-
|
|
476
|
-
this.
|
|
477
|
-
await this.openAPIpushChanges();
|
|
502
|
+
else {
|
|
503
|
+
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
478
504
|
}
|
|
479
|
-
this.
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
+
});
|
|
485
549
|
}
|
|
486
550
|
else {
|
|
487
|
-
|
|
488
|
-
if (this.platform.config.credentials?.openToken) {
|
|
489
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
490
|
-
await this.openAPIpushChanges();
|
|
491
|
-
}
|
|
551
|
+
throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
492
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
|
+
}*/
|
|
493
560
|
}
|
|
494
561
|
this.OnCached = this.On;
|
|
495
562
|
this.accessory.context.On = this.OnCached;
|
|
@@ -573,7 +640,45 @@ class Bot {
|
|
|
573
640
|
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
574
641
|
}
|
|
575
642
|
}
|
|
576
|
-
this.debugLog(`Bot: ${this.accessory.displayName}
|
|
643
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
644
|
+
}
|
|
645
|
+
else if (this.device.bot?.deviceType === 'door') {
|
|
646
|
+
if (this.On === undefined) {
|
|
647
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
if (this.On) {
|
|
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);
|
|
654
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
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);
|
|
660
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
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}`);
|
|
577
682
|
}
|
|
578
683
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
579
684
|
if (this.On === undefined) {
|
|
@@ -611,7 +716,21 @@ class Bot {
|
|
|
611
716
|
}
|
|
612
717
|
}
|
|
613
718
|
apiError(e) {
|
|
614
|
-
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') {
|
|
615
734
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
616
735
|
}
|
|
617
736
|
else {
|
|
@@ -677,6 +796,24 @@ class Bot {
|
|
|
677
796
|
this.On = true;
|
|
678
797
|
}
|
|
679
798
|
}
|
|
799
|
+
else if (this.device.bot?.deviceType === 'door') {
|
|
800
|
+
this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
801
|
+
if (value === 100) {
|
|
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) {
|
|
811
|
+
this.On = false;
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
this.On = true;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
680
817
|
else {
|
|
681
818
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
|
|
682
819
|
this.On = value;
|