@switchbot/homebridge-switchbot 1.7.1-beta.0 → 1.7.1-beta.12
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 +12 -2
- package/config.schema.json +80 -36
- package/dist/devices/bots.d.ts +7 -5
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +72 -69
- 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 +46 -36
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +6 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +59 -108
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +11 -4
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +67 -44
- 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 +39 -36
- 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 +13 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/devices/bots.ts +74 -72
- package/src/devices/colorbulb.ts +52 -39
- package/src/devices/contact.ts +61 -113
- package/src/devices/curtains.ts +76 -48
- package/src/devices/humidifiers.ts +47 -37
- 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 +14 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Homebridge SwitchBot",
|
|
3
3
|
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
-
"version": "1.7.1-beta.
|
|
4
|
+
"version": "1.7.1-beta.12",
|
|
5
5
|
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
|
|
6
6
|
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
7
7
|
"license": "ISC",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"homebridge": "^1.3.9",
|
|
17
|
-
"node": "^14.18.
|
|
17
|
+
"node": "^14.18.3 || ^16.13.2"
|
|
18
18
|
},
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"scripts": {
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@homebridge/plugin-ui-utils": "^0.0.19",
|
|
55
55
|
"axios": "^0.24.0",
|
|
56
|
-
"rxjs": "^7.5.
|
|
56
|
+
"rxjs": "^7.5.2"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^17.0.8",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^5.9.
|
|
61
|
-
"@typescript-eslint/parser": "^5.9.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
61
|
+
"@typescript-eslint/parser": "^5.9.1",
|
|
62
62
|
"eslint": "^8.6.0",
|
|
63
63
|
"homebridge": "^1.3.9",
|
|
64
64
|
"nodemon": "^2.0.15",
|
package/src/devices/bots.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload } from '../settings';
|
|
7
|
+
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
@@ -33,11 +33,13 @@ export class Bot {
|
|
|
33
33
|
StatusLowBattery!: CharacteristicValue;
|
|
34
34
|
|
|
35
35
|
// OpenAPI Others
|
|
36
|
+
power: deviceStatus['power'];
|
|
36
37
|
deviceStatus!: deviceStatusResponse;
|
|
37
38
|
|
|
38
39
|
// BLE Others
|
|
39
40
|
connected?: boolean;
|
|
40
41
|
switchbot!: switchbot;
|
|
42
|
+
SwitchToOpenAPI?: boolean;
|
|
41
43
|
serviceData!: serviceData;
|
|
42
44
|
mode!: serviceData['mode'];
|
|
43
45
|
state!: serviceData['state'];
|
|
@@ -62,11 +64,11 @@ export class Bot {
|
|
|
62
64
|
public device: device & devicesConfig,
|
|
63
65
|
) {
|
|
64
66
|
// default placeholders
|
|
65
|
-
this.logs();
|
|
66
|
-
this.scan();
|
|
67
|
-
this.refreshRate();
|
|
67
|
+
this.logs(device);
|
|
68
|
+
this.scan(device);
|
|
69
|
+
this.refreshRate(device);
|
|
68
70
|
this.PressOrSwitch();
|
|
69
|
-
|
|
71
|
+
this.config(device);
|
|
70
72
|
if (this.On === undefined) {
|
|
71
73
|
this.On = false;
|
|
72
74
|
this.accessory.context.On = this.On;
|
|
@@ -82,10 +84,6 @@ export class Bot {
|
|
|
82
84
|
this.BatteryLevel = 100;
|
|
83
85
|
this.StatusLowBattery = 0;
|
|
84
86
|
|
|
85
|
-
// Bot Config
|
|
86
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
|
|
87
|
-
+ ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`);
|
|
88
|
-
|
|
89
87
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
90
88
|
this.doBotUpdate = new Subject();
|
|
91
89
|
this.botUpdateInProgress = false;
|
|
@@ -317,12 +315,21 @@ export class Bot {
|
|
|
317
315
|
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
318
316
|
}
|
|
319
317
|
|
|
320
|
-
|
|
318
|
+
// Battery Service
|
|
319
|
+
if (!device.ble) {
|
|
320
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
|
|
321
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
322
|
+
accessory.removeService(this.batteryService!);
|
|
323
|
+
} else if (device.ble && !this.batteryService) {
|
|
324
|
+
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
321
325
|
(this.batteryService =
|
|
322
|
-
accessory.getService(this.platform.Service.Battery) ||
|
|
323
|
-
accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
326
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
327
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
324
328
|
|
|
325
329
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
330
|
+
|
|
331
|
+
} else {
|
|
332
|
+
this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
|
|
326
333
|
}
|
|
327
334
|
|
|
328
335
|
// Retrieve initial values and updateHomekit
|
|
@@ -456,50 +463,59 @@ export class Bot {
|
|
|
456
463
|
accessory.removeService(this.switchService!);
|
|
457
464
|
}
|
|
458
465
|
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
this.
|
|
462
|
-
if (
|
|
463
|
-
this.
|
|
466
|
+
scan(device: device & devicesConfig) {
|
|
467
|
+
if (device.scanDuration) {
|
|
468
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
469
|
+
if (device.ble) {
|
|
470
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
464
471
|
}
|
|
465
|
-
} else
|
|
466
|
-
this.
|
|
467
|
-
if (this.
|
|
468
|
-
this.
|
|
472
|
+
} else {
|
|
473
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
474
|
+
if (this.device.ble) {
|
|
475
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
469
476
|
}
|
|
470
477
|
}
|
|
471
478
|
}
|
|
472
479
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
if (
|
|
477
|
-
|
|
480
|
+
config(device: device & devicesConfig) {
|
|
481
|
+
const config: any = device.bot;
|
|
482
|
+
if (device.bot !== undefined) {
|
|
483
|
+
if (device.ble !== undefined) {
|
|
484
|
+
config['ble'] = device.ble;
|
|
478
485
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
482
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
486
|
+
if (device.logging !== undefined) {
|
|
487
|
+
config['logging'] = device.logging;
|
|
483
488
|
}
|
|
489
|
+
if (device.refreshRate !== undefined) {
|
|
490
|
+
config['refreshRate'] = device.refreshRate;
|
|
491
|
+
}
|
|
492
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
refreshRate(device: device & devicesConfig) {
|
|
497
|
+
if (device.refreshRate) {
|
|
498
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
499
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
500
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
501
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
502
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
484
503
|
}
|
|
485
504
|
}
|
|
486
505
|
|
|
487
|
-
logs() {
|
|
506
|
+
logs(device: device & devicesConfig) {
|
|
488
507
|
if (this.platform.debugMode) {
|
|
489
|
-
this.deviceLogging = this.accessory.context.logging = '
|
|
490
|
-
this.
|
|
491
|
-
} else if (
|
|
492
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
493
|
-
|
|
494
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
495
|
-
}
|
|
508
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
509
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
510
|
+
} else if (device.logging) {
|
|
511
|
+
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
512
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
496
513
|
} else if (this.platform.config.options?.logging) {
|
|
497
514
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
498
|
-
|
|
499
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
500
|
-
}
|
|
515
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
501
516
|
} else {
|
|
502
517
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
518
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
503
519
|
}
|
|
504
520
|
}
|
|
505
521
|
|
|
@@ -523,10 +539,10 @@ export class Bot {
|
|
|
523
539
|
* Parse the device status from the SwitchBot api
|
|
524
540
|
*/
|
|
525
541
|
async parseStatus() {
|
|
526
|
-
if (this.device.ble) {
|
|
527
|
-
await this.BLEparseStatus();
|
|
528
|
-
} else {
|
|
542
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
529
543
|
await this.openAPIparseStatus();
|
|
544
|
+
} else {
|
|
545
|
+
await this.BLEparseStatus();
|
|
530
546
|
}
|
|
531
547
|
}
|
|
532
548
|
|
|
@@ -560,6 +576,9 @@ export class Bot {
|
|
|
560
576
|
}
|
|
561
577
|
|
|
562
578
|
private async openAPIparseStatus() {
|
|
579
|
+
if (this.device.ble) {
|
|
580
|
+
this.SwitchToOpenAPI = false;
|
|
581
|
+
}
|
|
563
582
|
if (this.platform.config.credentials?.openToken) {
|
|
564
583
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
565
584
|
if (this.botMode === 'press') {
|
|
@@ -567,7 +586,7 @@ export class Bot {
|
|
|
567
586
|
this.OnCached = this.On;
|
|
568
587
|
this.accessory.context.On = this.OnCached;
|
|
569
588
|
} else {
|
|
570
|
-
/*if (this.
|
|
589
|
+
/*if (this.power === 'on') {
|
|
571
590
|
this.On = true;
|
|
572
591
|
this.OnCached = this.On;
|
|
573
592
|
this.accessory.context.On = this.OnCached;
|
|
@@ -597,35 +616,12 @@ export class Bot {
|
|
|
597
616
|
}
|
|
598
617
|
}
|
|
599
618
|
|
|
600
|
-
public async connectBLE() {
|
|
601
|
-
let switchbot: any;
|
|
602
|
-
try {
|
|
603
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
604
|
-
const Switchbot = require('node-switchbot');
|
|
605
|
-
switchbot = new Switchbot();
|
|
606
|
-
// Convert to BLE Address
|
|
607
|
-
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
608
|
-
this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
609
|
-
} catch (e: any) {
|
|
610
|
-
switchbot = false;
|
|
611
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
612
|
-
if (this.deviceLogging === 'debug') {
|
|
613
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
614
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
615
|
-
}
|
|
616
|
-
if (this.platform.debugMode) {
|
|
617
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
618
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
return switchbot;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
619
|
private async BLERefreshStatus() {
|
|
625
620
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
626
|
-
|
|
621
|
+
const switchbot = await this.platform.connectBLE();
|
|
627
622
|
// Convert to BLE Address
|
|
628
|
-
|
|
623
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
624
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
629
625
|
// Start to monitor advertisement packets
|
|
630
626
|
if (switchbot === false) {
|
|
631
627
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
@@ -664,6 +660,7 @@ export class Bot {
|
|
|
664
660
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
665
661
|
if (this.platform.config.credentials?.openToken) {
|
|
666
662
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
663
|
+
this.SwitchToOpenAPI = true;
|
|
667
664
|
await this.openAPIRefreshStatus();
|
|
668
665
|
}
|
|
669
666
|
}
|
|
@@ -679,6 +676,7 @@ export class Bot {
|
|
|
679
676
|
}
|
|
680
677
|
if (this.platform.config.credentials?.openToken) {
|
|
681
678
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
679
|
+
this.SwitchToOpenAPI = true;
|
|
682
680
|
await this.openAPIRefreshStatus();
|
|
683
681
|
}
|
|
684
682
|
this.apiError(e);
|
|
@@ -691,6 +689,7 @@ export class Bot {
|
|
|
691
689
|
try {
|
|
692
690
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
693
691
|
this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
692
|
+
this.power = this.deviceStatus.body.power;
|
|
694
693
|
this.parseStatus();
|
|
695
694
|
this.updateHomeKitCharacteristics();
|
|
696
695
|
} catch (e: any) {
|
|
@@ -733,7 +732,10 @@ export class Bot {
|
|
|
733
732
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
734
733
|
if (this.On !== this.OnCached) {
|
|
735
734
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
736
|
-
const switchbot = await this.connectBLE();
|
|
735
|
+
const switchbot = await this.platform.connectBLE();
|
|
736
|
+
// Convert to BLE Address
|
|
737
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
738
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
737
739
|
//if (switchbot !== false) {
|
|
738
740
|
if (this.botMode === 'press') {
|
|
739
741
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
package/src/devices/colorbulb.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
6
|
-
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs } from '../settings';
|
|
6
|
+
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs, deviceStatus } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
@@ -27,6 +27,10 @@ export class ColorBulb {
|
|
|
27
27
|
ColorTemperatureCached!: CharacteristicValue;
|
|
28
28
|
|
|
29
29
|
// OpenAPI Others
|
|
30
|
+
power: deviceStatus['power'];
|
|
31
|
+
color: deviceStatus['color'];
|
|
32
|
+
brightness: deviceStatus['brightness'];
|
|
33
|
+
colorTemperature: deviceStatus['colorTemperature'];
|
|
30
34
|
deviceStatus!: deviceStatusResponse;
|
|
31
35
|
|
|
32
36
|
// BLE Others
|
|
@@ -54,9 +58,10 @@ export class ColorBulb {
|
|
|
54
58
|
public device: device & devicesConfig,
|
|
55
59
|
) {
|
|
56
60
|
// default placeholders
|
|
57
|
-
this.logs();
|
|
58
|
-
this.refreshRate();
|
|
59
|
-
this.adaptiveLighting();
|
|
61
|
+
this.logs(device);
|
|
62
|
+
this.refreshRate(device);
|
|
63
|
+
this.adaptiveLighting(device);
|
|
64
|
+
this.config(device);
|
|
60
65
|
if (this.On === undefined) {
|
|
61
66
|
this.On = false;
|
|
62
67
|
} else {
|
|
@@ -68,11 +73,6 @@ export class ColorBulb {
|
|
|
68
73
|
this.ColorTemperature = 140;
|
|
69
74
|
this.minKelvin = 2000;
|
|
70
75
|
this.maxKelvin = 9000;
|
|
71
|
-
|
|
72
|
-
// ColorBulb Config
|
|
73
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep},`
|
|
74
|
-
+ ` adaptiveLighting: ${device.colorbulb?.adaptiveLightingShift})`);
|
|
75
|
-
|
|
76
76
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
77
77
|
this.doColorBulbUpdate = new Subject();
|
|
78
78
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -214,42 +214,51 @@ export class ColorBulb {
|
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
217
|
+
config(device: device & devicesConfig) {
|
|
218
|
+
const config: any = device.colorbulb;
|
|
219
|
+
if (device.colorbulb !== undefined) {
|
|
220
|
+
if (device.ble !== undefined) {
|
|
221
|
+
config['ble'] = device.ble;
|
|
222
|
+
}
|
|
223
|
+
if (device.logging !== undefined) {
|
|
224
|
+
config['logging'] = device.logging;
|
|
222
225
|
}
|
|
226
|
+
if (device.refreshRate !== undefined) {
|
|
227
|
+
config['refreshRate'] = device.refreshRate;
|
|
228
|
+
}
|
|
229
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
refreshRate(device: device & devicesConfig) {
|
|
234
|
+
if (device.refreshRate) {
|
|
235
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
236
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
223
237
|
} else if (this.platform.config.options!.refreshRate) {
|
|
224
238
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
225
|
-
|
|
226
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
227
|
-
}
|
|
239
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
228
240
|
}
|
|
229
241
|
}
|
|
230
242
|
|
|
231
|
-
logs() {
|
|
243
|
+
logs(device: device & devicesConfig) {
|
|
232
244
|
if (this.platform.debugMode) {
|
|
233
|
-
this.deviceLogging = this.accessory.context.logging = '
|
|
234
|
-
this.
|
|
235
|
-
} else if (
|
|
236
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
237
|
-
|
|
238
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
239
|
-
}
|
|
245
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
246
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
247
|
+
} else if (device.logging) {
|
|
248
|
+
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
249
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
240
250
|
} else if (this.platform.config.options?.logging) {
|
|
241
251
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
242
|
-
|
|
243
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
244
|
-
}
|
|
252
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
245
253
|
} else {
|
|
246
254
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
255
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
247
256
|
}
|
|
248
257
|
}
|
|
249
258
|
|
|
250
|
-
adaptiveLighting() {
|
|
251
|
-
if (
|
|
252
|
-
this.adaptiveLightingShift =
|
|
259
|
+
adaptiveLighting(device: device & devicesConfig) {
|
|
260
|
+
if (device.colorbulb?.adaptiveLightingShift) {
|
|
261
|
+
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
253
262
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
254
263
|
} else {
|
|
255
264
|
this.adaptiveLightingShift = 0;
|
|
@@ -267,7 +276,7 @@ export class ColorBulb {
|
|
|
267
276
|
}
|
|
268
277
|
|
|
269
278
|
parseStatus() {
|
|
270
|
-
switch (this.
|
|
279
|
+
switch (this.power) {
|
|
271
280
|
case 'on':
|
|
272
281
|
this.On = true;
|
|
273
282
|
break;
|
|
@@ -277,13 +286,13 @@ export class ColorBulb {
|
|
|
277
286
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
278
287
|
|
|
279
288
|
// Brightness
|
|
280
|
-
this.Brightness = Number(this.
|
|
289
|
+
this.Brightness = Number(this.brightness);
|
|
281
290
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
282
291
|
|
|
283
292
|
// Color, Hue & Brightness
|
|
284
|
-
if (this.
|
|
285
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
286
|
-
const [red, green, blue] = this.
|
|
293
|
+
if (this.color) {
|
|
294
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
295
|
+
const [red, green, blue] = this.color!.split(':');
|
|
287
296
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
288
297
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
289
298
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -301,9 +310,9 @@ export class ColorBulb {
|
|
|
301
310
|
}
|
|
302
311
|
|
|
303
312
|
// ColorTemperature
|
|
304
|
-
if (!Number.isNaN(this.
|
|
305
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.
|
|
306
|
-
const mired = Math.round(1000000 / this.
|
|
313
|
+
if (!Number.isNaN(this.colorTemperature)) {
|
|
314
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
315
|
+
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
307
316
|
|
|
308
317
|
this.ColorTemperature = Number(mired);
|
|
309
318
|
|
|
@@ -316,6 +325,10 @@ export class ColorBulb {
|
|
|
316
325
|
try {
|
|
317
326
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
318
327
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
328
|
+
this.power = this.deviceStatus.body.power;
|
|
329
|
+
this.color = this.deviceStatus.body.color;
|
|
330
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
331
|
+
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
319
332
|
this.parseStatus();
|
|
320
333
|
this.updateHomeKitCharacteristics();
|
|
321
334
|
} catch (e: any) {
|