@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-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 +8 -0
- package/dist/device/blindtilt.d.ts +3 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +61 -28
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +53 -28
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +53 -28
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +53 -28
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +53 -28
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +74 -43
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/fan.d.ts +1 -0
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +53 -28
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +53 -28
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +53 -28
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +53 -28
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +53 -28
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +54 -29
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +53 -28
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +53 -28
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +53 -28
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +54 -29
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +53 -28
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -0
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +53 -28
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +22 -3
- package/dist/platform.js.map +1 -1
- package/package.json +7 -7
- package/src/device/blindtilt.ts +59 -27
- package/src/device/bot.ts +50 -26
- package/src/device/ceilinglight.ts +51 -27
- package/src/device/colorbulb.ts +50 -26
- package/src/device/contact.ts +50 -26
- package/src/device/curtain.ts +71 -40
- package/src/device/fan.ts +50 -26
- package/src/device/hub.ts +50 -26
- package/src/device/humidifier.ts +50 -26
- package/src/device/iosensor.ts +50 -26
- package/src/device/lightstrip.ts +50 -26
- package/src/device/lock.ts +51 -27
- package/src/device/meter.ts +50 -26
- package/src/device/meterplus.ts +50 -26
- package/src/device/motion.ts +50 -26
- package/src/device/plug.ts +51 -27
- package/src/device/robotvacuumcleaner.ts +50 -26
- package/src/device/waterdetector.ts +50 -26
- package/src/platform.ts +19 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "SwitchBot",
|
|
3
3
|
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
-
"version": "3.7.1-beta.
|
|
4
|
+
"version": "3.7.1-beta.4",
|
|
5
5
|
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "SwitchBot",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"@homebridge/plugin-ui-utils": "^1.0.3",
|
|
83
83
|
"async-mqtt": "^2.6.3",
|
|
84
|
-
"fakegato-history": "^0.6.
|
|
84
|
+
"fakegato-history": "^0.6.5",
|
|
85
85
|
"homebridge-lib": "^7.0.4",
|
|
86
86
|
"rxjs": "^7.8.1",
|
|
87
87
|
"undici": "^6.19.4"
|
|
@@ -90,11 +90,11 @@
|
|
|
90
90
|
"node-switchbot": "2.3.0"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@eslint/js": "^9.
|
|
94
|
-
"@stylistic/eslint-plugin": "^2.
|
|
93
|
+
"@eslint/js": "^9.8.0",
|
|
94
|
+
"@stylistic/eslint-plugin": "^2.4.0",
|
|
95
95
|
"@types/eslint__js": "^8.42.3",
|
|
96
|
-
"@types/node": "^20.14.
|
|
97
|
-
"eslint": "^9.
|
|
96
|
+
"@types/node": "^20.14.12",
|
|
97
|
+
"eslint": "^9.8.0",
|
|
98
98
|
"globals": "^15.8.0",
|
|
99
99
|
"homebridge": "^2.0.0-beta.0",
|
|
100
100
|
"homebridge-config-ui-x": "4.56.4",
|
|
@@ -104,6 +104,6 @@
|
|
|
104
104
|
"ts-node": "^10.9.2",
|
|
105
105
|
"typedoc": "^0.26.5",
|
|
106
106
|
"typescript": "^5.5.4",
|
|
107
|
-
"typescript-eslint": "^8.0.0-alpha.
|
|
107
|
+
"typescript-eslint": "^8.0.0-alpha.54"
|
|
108
108
|
}
|
|
109
109
|
}
|
package/src/device/blindtilt.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { BlindTiltMappingMode } from '../utils.js';
|
|
7
|
+
/*
|
|
8
|
+
* For Testing Locally:
|
|
9
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
+
*/
|
|
7
11
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
12
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
13
|
|
|
@@ -57,7 +61,8 @@ export class BlindTilt extends deviceBase {
|
|
|
57
61
|
setNewTargetTimer!: NodeJS.Timeout;
|
|
58
62
|
|
|
59
63
|
// Updates
|
|
60
|
-
|
|
64
|
+
blindTiltMoving: boolean;
|
|
65
|
+
blindTiltUpdateInProgress: boolean;
|
|
61
66
|
doBlindTiltUpdate: Subject<void>;
|
|
62
67
|
|
|
63
68
|
constructor(
|
|
@@ -75,6 +80,7 @@ export class BlindTilt extends deviceBase {
|
|
|
75
80
|
|
|
76
81
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
77
82
|
this.doBlindTiltUpdate = new Subject();
|
|
83
|
+
this.blindTiltMoving = false;
|
|
78
84
|
this.blindTiltUpdateInProgress = false;
|
|
79
85
|
this.setNewTarget = false;
|
|
80
86
|
|
|
@@ -190,12 +196,28 @@ export class BlindTilt extends deviceBase {
|
|
|
190
196
|
}
|
|
191
197
|
|
|
192
198
|
// Retrieve initial values and updateHomekit
|
|
193
|
-
|
|
194
|
-
|
|
199
|
+
try {
|
|
200
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
201
|
+
this.refreshStatus();
|
|
202
|
+
} catch (e: any) {
|
|
203
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
204
|
+
}
|
|
195
205
|
|
|
196
|
-
//regisiter webhook event handler
|
|
197
|
-
|
|
198
|
-
|
|
206
|
+
//regisiter webhook event handler if enabled
|
|
207
|
+
try {
|
|
208
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
209
|
+
this.registerWebhook();
|
|
210
|
+
} catch (e: any) {
|
|
211
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
//regisiter platform BLE event handler if enabled
|
|
215
|
+
try {
|
|
216
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
217
|
+
this.registerPlatformBLE();
|
|
218
|
+
} catch (e: any) {
|
|
219
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
220
|
+
}
|
|
199
221
|
|
|
200
222
|
// Start an update interval
|
|
201
223
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -206,6 +228,7 @@ export class BlindTilt extends deviceBase {
|
|
|
206
228
|
|
|
207
229
|
// update slide progress
|
|
208
230
|
interval(this.deviceUpdateRate * 1000)
|
|
231
|
+
.pipe(skipWhile(() => !this.blindTiltMoving))
|
|
209
232
|
.subscribe(async () => {
|
|
210
233
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
211
234
|
return;
|
|
@@ -251,6 +274,7 @@ export class BlindTilt extends deviceBase {
|
|
|
251
274
|
await this.infoLog('Checking Status ...');
|
|
252
275
|
}
|
|
253
276
|
if (this.setNewTarget && this.serviceData.inMotion) {
|
|
277
|
+
this.blindTiltMoving = true;
|
|
254
278
|
await this.setMinMax();
|
|
255
279
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
256
280
|
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
@@ -269,6 +293,7 @@ export class BlindTilt extends deviceBase {
|
|
|
269
293
|
await this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState);
|
|
270
294
|
}
|
|
271
295
|
} else {
|
|
296
|
+
this.blindTiltMoving = false;
|
|
272
297
|
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
273
298
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
274
299
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
@@ -381,7 +406,7 @@ export class BlindTilt extends deviceBase {
|
|
|
381
406
|
async refreshStatus(): Promise<void> {
|
|
382
407
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
383
408
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
384
|
-
} else if (this.BLE
|
|
409
|
+
} else if (this.BLE) {
|
|
385
410
|
await this.BLERefreshStatus();
|
|
386
411
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
387
412
|
await this.openAPIRefreshStatus();
|
|
@@ -392,6 +417,30 @@ export class BlindTilt extends deviceBase {
|
|
|
392
417
|
}
|
|
393
418
|
|
|
394
419
|
async BLERefreshStatus(): Promise<void> {
|
|
420
|
+
await this.debugLog('BLERefreshStatus');
|
|
421
|
+
const switchbot = await this.switchbotBLE();
|
|
422
|
+
if (switchbot === undefined) {
|
|
423
|
+
await this.BLERefreshConnection(switchbot);
|
|
424
|
+
} else {
|
|
425
|
+
// Start to monitor advertisement packets
|
|
426
|
+
(async () => {
|
|
427
|
+
// Start to monitor advertisement packets
|
|
428
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as blindTiltServiceData;
|
|
429
|
+
// Update HomeKit
|
|
430
|
+
if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
|
|
431
|
+
this.serviceData = serviceData;
|
|
432
|
+
await this.BLEparseStatus();
|
|
433
|
+
await this.updateHomeKitCharacteristics();
|
|
434
|
+
} else {
|
|
435
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
436
|
+
await this.BLERefreshConnection(switchbot);
|
|
437
|
+
}
|
|
438
|
+
})();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async registerPlatformBLE(): Promise<void> {
|
|
443
|
+
await this.debugLog('registerPlatformBLE');
|
|
395
444
|
if (this.config.options?.BLE) {
|
|
396
445
|
await this.debugLog('is listening to Platform BLE.');
|
|
397
446
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -407,26 +456,7 @@ export class BlindTilt extends deviceBase {
|
|
|
407
456
|
}
|
|
408
457
|
};
|
|
409
458
|
} else {
|
|
410
|
-
await this.debugLog('is
|
|
411
|
-
const switchbot = await this.switchbotBLE();
|
|
412
|
-
if (switchbot === undefined) {
|
|
413
|
-
await this.BLERefreshConnection(switchbot);
|
|
414
|
-
} else {
|
|
415
|
-
// Start to monitor advertisement packets
|
|
416
|
-
(async () => {
|
|
417
|
-
// Start to monitor advertisement packets
|
|
418
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as blindTiltServiceData;
|
|
419
|
-
// Update HomeKit
|
|
420
|
-
if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
|
|
421
|
-
this.serviceData = serviceData;
|
|
422
|
-
await this.BLEparseStatus();
|
|
423
|
-
await this.updateHomeKitCharacteristics();
|
|
424
|
-
} else {
|
|
425
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
426
|
-
await this.BLERefreshConnection(switchbot);
|
|
427
|
-
}
|
|
428
|
-
})();
|
|
429
|
-
}
|
|
459
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
430
460
|
}
|
|
431
461
|
}
|
|
432
462
|
|
|
@@ -792,6 +822,7 @@ export class BlindTilt extends deviceBase {
|
|
|
792
822
|
}
|
|
793
823
|
|
|
794
824
|
if (this.setNewTarget) {
|
|
825
|
+
this.blindTiltMoving = true;
|
|
795
826
|
await this.infoLog('Checking Status ...');
|
|
796
827
|
await this.setMinMax();
|
|
797
828
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
@@ -812,6 +843,7 @@ export class BlindTilt extends deviceBase {
|
|
|
812
843
|
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
813
844
|
}
|
|
814
845
|
} else {
|
|
846
|
+
this.blindTiltMoving = false;
|
|
815
847
|
await this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
816
848
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
817
849
|
if (homekitTiltAngle) {
|
package/src/device/bot.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
+
/*
|
|
7
|
+
* For Testing Locally:
|
|
8
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
9
|
+
*/
|
|
6
10
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
7
11
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
8
12
|
|
|
@@ -424,12 +428,28 @@ export class Bot extends deviceBase {
|
|
|
424
428
|
}
|
|
425
429
|
|
|
426
430
|
// Retrieve initial values and updateHomekit
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
try {
|
|
432
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
433
|
+
this.refreshStatus();
|
|
434
|
+
} catch (e: any) {
|
|
435
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
436
|
+
}
|
|
429
437
|
|
|
430
|
-
//regisiter webhook event handler
|
|
431
|
-
|
|
432
|
-
|
|
438
|
+
//regisiter webhook event handler if enabled
|
|
439
|
+
try {
|
|
440
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
441
|
+
this.registerWebhook();
|
|
442
|
+
} catch (e: any) {
|
|
443
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
//regisiter platform BLE event handler if enabled
|
|
447
|
+
try {
|
|
448
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
449
|
+
this.registerPlatformBLE();
|
|
450
|
+
} catch (e: any) {
|
|
451
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
452
|
+
}
|
|
433
453
|
|
|
434
454
|
// Start an update interval
|
|
435
455
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -558,7 +578,7 @@ export class Bot extends deviceBase {
|
|
|
558
578
|
async refreshStatus(): Promise<void> {
|
|
559
579
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
560
580
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
561
|
-
} else if (this.BLE
|
|
581
|
+
} else if (this.BLE) {
|
|
562
582
|
await this.BLERefreshStatus();
|
|
563
583
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
564
584
|
await this.openAPIRefreshStatus();
|
|
@@ -570,6 +590,29 @@ export class Bot extends deviceBase {
|
|
|
570
590
|
|
|
571
591
|
async BLERefreshStatus(): Promise<void> {
|
|
572
592
|
await this.debugLog('BLERefreshStatus');
|
|
593
|
+
const switchbot = await this.switchbotBLE();
|
|
594
|
+
if (switchbot === undefined) {
|
|
595
|
+
await this.BLERefreshConnection(switchbot);
|
|
596
|
+
} else {
|
|
597
|
+
// Start to monitor advertisement packets
|
|
598
|
+
(async () => {
|
|
599
|
+
// Start to monitor advertisement packets
|
|
600
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
601
|
+
// Update HomeKit
|
|
602
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
603
|
+
this.serviceData = serviceData;
|
|
604
|
+
await this.BLEparseStatus();
|
|
605
|
+
await this.updateHomeKitCharacteristics();
|
|
606
|
+
} else {
|
|
607
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
608
|
+
await this.BLERefreshConnection(switchbot);
|
|
609
|
+
}
|
|
610
|
+
})();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async registerPlatformBLE(): Promise<void> {
|
|
615
|
+
await this.debugLog('registerPlatformBLE');
|
|
573
616
|
if (this.config.options?.BLE) {
|
|
574
617
|
await this.debugLog('is listening to Platform BLE.');
|
|
575
618
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -585,26 +628,7 @@ export class Bot extends deviceBase {
|
|
|
585
628
|
}
|
|
586
629
|
};
|
|
587
630
|
} else {
|
|
588
|
-
await this.debugLog('is
|
|
589
|
-
const switchbot = await this.switchbotBLE();
|
|
590
|
-
if (switchbot === undefined) {
|
|
591
|
-
await this.BLERefreshConnection(switchbot);
|
|
592
|
-
} else {
|
|
593
|
-
// Start to monitor advertisement packets
|
|
594
|
-
(async () => {
|
|
595
|
-
// Start to monitor advertisement packets
|
|
596
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
597
|
-
// Update HomeKit
|
|
598
|
-
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
599
|
-
this.serviceData = serviceData;
|
|
600
|
-
await this.BLEparseStatus();
|
|
601
|
-
await this.updateHomeKitCharacteristics();
|
|
602
|
-
} else {
|
|
603
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
604
|
-
await this.BLERefreshConnection(switchbot);
|
|
605
|
-
}
|
|
606
|
-
})();
|
|
607
|
-
}
|
|
631
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
608
632
|
}
|
|
609
633
|
}
|
|
610
634
|
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { hs2rgb, m2hs } from '../utils.js';
|
|
7
|
+
/*
|
|
8
|
+
* For Testing Locally:
|
|
9
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
+
*/
|
|
7
11
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
12
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
13
|
|
|
@@ -161,12 +165,28 @@ export class CeilingLight extends deviceBase {
|
|
|
161
165
|
.onSet(this.SaturationSet.bind(this));
|
|
162
166
|
|
|
163
167
|
// Retrieve initial values and updateHomekit
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
try {
|
|
169
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
170
|
+
this.refreshStatus();
|
|
171
|
+
} catch (e: any) {
|
|
172
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
//regisiter webhook event handler if enabled
|
|
176
|
+
try {
|
|
177
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
178
|
+
this.registerWebhook();
|
|
179
|
+
} catch (e: any) {
|
|
180
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
181
|
+
}
|
|
166
182
|
|
|
167
|
-
//regisiter
|
|
168
|
-
|
|
169
|
-
|
|
183
|
+
//regisiter platform BLE event handler if enabled
|
|
184
|
+
try {
|
|
185
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
186
|
+
this.registerPlatformBLE();
|
|
187
|
+
} catch (e: any) {
|
|
188
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
189
|
+
}
|
|
170
190
|
|
|
171
191
|
// Start an update interval
|
|
172
192
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -275,7 +295,7 @@ export class CeilingLight extends deviceBase {
|
|
|
275
295
|
async refreshStatus(): Promise<void> {
|
|
276
296
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
277
297
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
278
|
-
} else if (this.BLE
|
|
298
|
+
} else if (this.BLE) {
|
|
279
299
|
await this.BLERefreshStatus();
|
|
280
300
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
281
301
|
await this.openAPIRefreshStatus();
|
|
@@ -287,11 +307,34 @@ export class CeilingLight extends deviceBase {
|
|
|
287
307
|
|
|
288
308
|
async BLERefreshStatus(): Promise<void> {
|
|
289
309
|
await this.debugLog('BLERefreshStatus');
|
|
310
|
+
const switchbot = await this.switchbotBLE();
|
|
311
|
+
if (switchbot === undefined) {
|
|
312
|
+
await this.BLERefreshConnection(switchbot);
|
|
313
|
+
} else {
|
|
314
|
+
(async () => {
|
|
315
|
+
// Start to monitor advertisement packets
|
|
316
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
|
|
317
|
+
// Update HomeKit
|
|
318
|
+
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
319
|
+
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
320
|
+
this.serviceData = serviceData;
|
|
321
|
+
await this.BLEparseStatus();
|
|
322
|
+
await this.updateHomeKitCharacteristics();
|
|
323
|
+
} else {
|
|
324
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
325
|
+
await this.BLERefreshConnection(switchbot);
|
|
326
|
+
}
|
|
327
|
+
})();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async registerPlatformBLE(): Promise<void> {
|
|
332
|
+
await this.debugLog('registerPlatformBLE');
|
|
290
333
|
if (this.config.options?.BLE) {
|
|
291
334
|
await this.debugLog('is listening to Platform BLE.');
|
|
292
335
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
293
336
|
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
294
|
-
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData) => {
|
|
337
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData | ceilingLightProServiceData) => {
|
|
295
338
|
try {
|
|
296
339
|
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
297
340
|
this.serviceData = context;
|
|
@@ -302,26 +345,7 @@ export class CeilingLight extends deviceBase {
|
|
|
302
345
|
}
|
|
303
346
|
};
|
|
304
347
|
} else {
|
|
305
|
-
await this.debugLog('is
|
|
306
|
-
const switchbot = await this.switchbotBLE();
|
|
307
|
-
if (switchbot === undefined) {
|
|
308
|
-
await this.BLERefreshConnection(switchbot);
|
|
309
|
-
} else {
|
|
310
|
-
(async () => {
|
|
311
|
-
// Start to monitor advertisement packets
|
|
312
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
|
|
313
|
-
// Update HomeKit
|
|
314
|
-
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
315
|
-
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
316
|
-
this.serviceData = serviceData;
|
|
317
|
-
await this.BLEparseStatus();
|
|
318
|
-
await this.updateHomeKitCharacteristics();
|
|
319
|
-
} else {
|
|
320
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
321
|
-
await this.BLERefreshConnection(switchbot);
|
|
322
|
-
}
|
|
323
|
-
})();
|
|
324
|
-
}
|
|
348
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
325
349
|
}
|
|
326
350
|
}
|
|
327
351
|
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
7
|
+
/*
|
|
8
|
+
* For Testing Locally:
|
|
9
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
+
*/
|
|
7
11
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
12
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
13
|
|
|
@@ -157,12 +161,28 @@ export class ColorBulb extends deviceBase {
|
|
|
157
161
|
.onSet(this.SaturationSet.bind(this));
|
|
158
162
|
|
|
159
163
|
// Retrieve initial values and updateHomekit
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
try {
|
|
165
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
166
|
+
this.refreshStatus();
|
|
167
|
+
} catch (e: any) {
|
|
168
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//regisiter webhook event handler if enabled
|
|
172
|
+
try {
|
|
173
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
174
|
+
this.registerWebhook();
|
|
175
|
+
} catch (e: any) {
|
|
176
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
177
|
+
}
|
|
162
178
|
|
|
163
|
-
//regisiter
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
//regisiter platform BLE event handler if enabled
|
|
180
|
+
try {
|
|
181
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
182
|
+
this.registerPlatformBLE();
|
|
183
|
+
} catch (e: any) {
|
|
184
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
185
|
+
}
|
|
166
186
|
|
|
167
187
|
// Start an update interval
|
|
168
188
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -296,7 +316,7 @@ export class ColorBulb extends deviceBase {
|
|
|
296
316
|
async refreshStatus(): Promise<void> {
|
|
297
317
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
298
318
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
299
|
-
} else if (this.BLE
|
|
319
|
+
} else if (this.BLE) {
|
|
300
320
|
await this.BLERefreshStatus();
|
|
301
321
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
302
322
|
await this.openAPIRefreshStatus();
|
|
@@ -308,6 +328,29 @@ export class ColorBulb extends deviceBase {
|
|
|
308
328
|
|
|
309
329
|
async BLERefreshStatus(): Promise<void> {
|
|
310
330
|
await this.debugLog('BLERefreshStatus');
|
|
331
|
+
const switchbot = await this.switchbotBLE();
|
|
332
|
+
if (switchbot === undefined) {
|
|
333
|
+
await this.BLERefreshConnection(switchbot);
|
|
334
|
+
} else {
|
|
335
|
+
// Start to monitor advertisement packets
|
|
336
|
+
(async () => {
|
|
337
|
+
// Start to monitor advertisement packets
|
|
338
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData;
|
|
339
|
+
// Update HomeKit
|
|
340
|
+
if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
|
|
341
|
+
this.serviceData = serviceData;
|
|
342
|
+
await this.BLEparseStatus();
|
|
343
|
+
await this.updateHomeKitCharacteristics();
|
|
344
|
+
} else {
|
|
345
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
346
|
+
await this.BLERefreshConnection(switchbot);
|
|
347
|
+
}
|
|
348
|
+
})();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async registerPlatformBLE(): Promise<void> {
|
|
353
|
+
await this.debugLog('registerPlatformBLE');
|
|
311
354
|
if (this.config.options?.BLE) {
|
|
312
355
|
await this.debugLog('is listening to Platform BLE.');
|
|
313
356
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -323,26 +366,7 @@ export class ColorBulb extends deviceBase {
|
|
|
323
366
|
}
|
|
324
367
|
};
|
|
325
368
|
} else {
|
|
326
|
-
await this.debugLog('is
|
|
327
|
-
const switchbot = await this.switchbotBLE();
|
|
328
|
-
if (switchbot === undefined) {
|
|
329
|
-
await this.BLERefreshConnection(switchbot);
|
|
330
|
-
} else {
|
|
331
|
-
// Start to monitor advertisement packets
|
|
332
|
-
(async () => {
|
|
333
|
-
// Start to monitor advertisement packets
|
|
334
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData;
|
|
335
|
-
// Update HomeKit
|
|
336
|
-
if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
|
|
337
|
-
this.serviceData = serviceData;
|
|
338
|
-
await this.BLEparseStatus();
|
|
339
|
-
await this.updateHomeKitCharacteristics();
|
|
340
|
-
} else {
|
|
341
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
342
|
-
await this.BLERefreshConnection(switchbot);
|
|
343
|
-
}
|
|
344
|
-
})();
|
|
345
|
-
}
|
|
369
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
346
370
|
}
|
|
347
371
|
}
|
|
348
372
|
|
package/src/device/contact.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
7
|
+
/*
|
|
8
|
+
* For Testing Locally:
|
|
9
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
+
*/
|
|
7
11
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
12
|
|
|
9
13
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -169,12 +173,28 @@ export class Contact extends deviceBase {
|
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
// Retrieve initial values and updateHomekit
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
try {
|
|
177
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
178
|
+
this.refreshStatus();
|
|
179
|
+
} catch (e: any) {
|
|
180
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
181
|
+
}
|
|
174
182
|
|
|
175
|
-
//regisiter webhook event handler
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
//regisiter webhook event handler if enabled
|
|
184
|
+
try {
|
|
185
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
186
|
+
this.registerWebhook();
|
|
187
|
+
} catch (e: any) {
|
|
188
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//regisiter platform BLE event handler if enabled
|
|
192
|
+
try {
|
|
193
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
194
|
+
this.registerPlatformBLE();
|
|
195
|
+
} catch (e: any) {
|
|
196
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
197
|
+
}
|
|
178
198
|
|
|
179
199
|
// Start an update interval
|
|
180
200
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -284,7 +304,7 @@ export class Contact extends deviceBase {
|
|
|
284
304
|
async refreshStatus(): Promise<void> {
|
|
285
305
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
286
306
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
287
|
-
} else if (this.BLE
|
|
307
|
+
} else if (this.BLE) {
|
|
288
308
|
await this.BLERefreshStatus();
|
|
289
309
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
290
310
|
await this.openAPIRefreshStatus();
|
|
@@ -296,6 +316,29 @@ export class Contact extends deviceBase {
|
|
|
296
316
|
|
|
297
317
|
async BLERefreshStatus(): Promise<void> {
|
|
298
318
|
await this.debugLog('BLERefreshStatus');
|
|
319
|
+
const switchbot = await this.switchbotBLE();
|
|
320
|
+
if (switchbot === undefined) {
|
|
321
|
+
await this.BLERefreshConnection(switchbot);
|
|
322
|
+
} else {
|
|
323
|
+
// Start to monitor advertisement packets
|
|
324
|
+
(async () => {
|
|
325
|
+
// Start to monitor advertisement packets
|
|
326
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData;
|
|
327
|
+
// Update HomeKit
|
|
328
|
+
if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
|
|
329
|
+
this.serviceData = serviceData;
|
|
330
|
+
await this.BLEparseStatus();
|
|
331
|
+
await this.updateHomeKitCharacteristics();
|
|
332
|
+
} else {
|
|
333
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
334
|
+
await this.BLERefreshConnection(switchbot);
|
|
335
|
+
}
|
|
336
|
+
})();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async registerPlatformBLE(): Promise<void> {
|
|
341
|
+
await this.debugLog('registerPlatformBLE');
|
|
299
342
|
if (this.config.options?.BLE) {
|
|
300
343
|
await this.debugLog('is listening to Platform BLE.');
|
|
301
344
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -311,26 +354,7 @@ export class Contact extends deviceBase {
|
|
|
311
354
|
}
|
|
312
355
|
};
|
|
313
356
|
} else {
|
|
314
|
-
await this.debugLog('is
|
|
315
|
-
const switchbot = await this.switchbotBLE();
|
|
316
|
-
if (switchbot === undefined) {
|
|
317
|
-
await this.BLERefreshConnection(switchbot);
|
|
318
|
-
} else {
|
|
319
|
-
// Start to monitor advertisement packets
|
|
320
|
-
(async () => {
|
|
321
|
-
// Start to monitor advertisement packets
|
|
322
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData;
|
|
323
|
-
// Update HomeKit
|
|
324
|
-
if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
|
|
325
|
-
this.serviceData = serviceData;
|
|
326
|
-
await this.BLEparseStatus();
|
|
327
|
-
await this.updateHomeKitCharacteristics();
|
|
328
|
-
} else {
|
|
329
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
330
|
-
await this.BLERefreshConnection(switchbot);
|
|
331
|
-
}
|
|
332
|
-
})();
|
|
333
|
-
}
|
|
357
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
334
358
|
}
|
|
335
359
|
}
|
|
336
360
|
|