@switchbot/homebridge-switchbot 3.7.1-beta.1 → 3.7.1-beta.3
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/dist/device/blindtilt.d.ts +3 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +38 -24
- 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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +51 -39
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +247 -394
- package/dist/device/device.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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +31 -25
- 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 +30 -24
- 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 +30 -24
- 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 +30 -24
- 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 +31 -25
- 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 +30 -24
- 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 +30 -24
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +30 -133
- package/dist/irdevice/irdevice.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +39 -23
- package/src/device/bot.ts +30 -22
- package/src/device/ceilinglight.ts +31 -23
- package/src/device/colorbulb.ts +30 -22
- package/src/device/contact.ts +30 -22
- package/src/device/curtain.ts +50 -36
- package/src/device/device.ts +283 -395
- package/src/device/fan.ts +30 -22
- package/src/device/hub.ts +30 -22
- package/src/device/humidifier.ts +30 -22
- package/src/device/iosensor.ts +30 -22
- package/src/device/lightstrip.ts +30 -22
- package/src/device/lock.ts +31 -23
- package/src/device/meter.ts +30 -22
- package/src/device/meterplus.ts +30 -22
- package/src/device/motion.ts +30 -22
- package/src/device/plug.ts +31 -23
- package/src/device/robotvacuumcleaner.ts +30 -22
- package/src/device/waterdetector.ts +30 -22
- package/src/irdevice/irdevice.ts +54 -134
package/src/device/blindtilt.ts
CHANGED
|
@@ -57,7 +57,8 @@ export class BlindTilt extends deviceBase {
|
|
|
57
57
|
setNewTargetTimer!: NodeJS.Timeout;
|
|
58
58
|
|
|
59
59
|
// Updates
|
|
60
|
-
|
|
60
|
+
blindTiltMoving: boolean;
|
|
61
|
+
blindTiltUpdateInProgress: boolean;
|
|
61
62
|
doBlindTiltUpdate: Subject<void>;
|
|
62
63
|
|
|
63
64
|
constructor(
|
|
@@ -75,6 +76,7 @@ export class BlindTilt extends deviceBase {
|
|
|
75
76
|
|
|
76
77
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
77
78
|
this.doBlindTiltUpdate = new Subject();
|
|
79
|
+
this.blindTiltMoving = false;
|
|
78
80
|
this.blindTiltUpdateInProgress = false;
|
|
79
81
|
this.setNewTarget = false;
|
|
80
82
|
|
|
@@ -193,10 +195,14 @@ export class BlindTilt extends deviceBase {
|
|
|
193
195
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
194
196
|
this.refreshStatus();
|
|
195
197
|
|
|
196
|
-
//regisiter webhook event handler
|
|
198
|
+
//regisiter webhook event handler if enabled
|
|
197
199
|
this.debugLog('Registering Webhook Event Handler');
|
|
198
200
|
this.registerWebhook();
|
|
199
201
|
|
|
202
|
+
//regisiter platform BLE event handler if enabled
|
|
203
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
204
|
+
this.registerPlatformBLE();
|
|
205
|
+
|
|
200
206
|
// Start an update interval
|
|
201
207
|
interval(this.deviceRefreshRate * 1000)
|
|
202
208
|
.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
@@ -206,6 +212,7 @@ export class BlindTilt extends deviceBase {
|
|
|
206
212
|
|
|
207
213
|
// update slide progress
|
|
208
214
|
interval(this.deviceUpdateRate * 1000)
|
|
215
|
+
.pipe(skipWhile(() => !this.blindTiltMoving))
|
|
209
216
|
.subscribe(async () => {
|
|
210
217
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
211
218
|
return;
|
|
@@ -251,6 +258,7 @@ export class BlindTilt extends deviceBase {
|
|
|
251
258
|
await this.infoLog('Checking Status ...');
|
|
252
259
|
}
|
|
253
260
|
if (this.setNewTarget && this.serviceData.inMotion) {
|
|
261
|
+
this.blindTiltMoving = true;
|
|
254
262
|
await this.setMinMax();
|
|
255
263
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
256
264
|
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
@@ -269,6 +277,7 @@ export class BlindTilt extends deviceBase {
|
|
|
269
277
|
await this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState);
|
|
270
278
|
}
|
|
271
279
|
} else {
|
|
280
|
+
this.blindTiltMoving = false;
|
|
272
281
|
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
273
282
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
274
283
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
@@ -381,7 +390,7 @@ export class BlindTilt extends deviceBase {
|
|
|
381
390
|
async refreshStatus(): Promise<void> {
|
|
382
391
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
383
392
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
384
|
-
} else if (this.BLE
|
|
393
|
+
} else if (this.BLE) {
|
|
385
394
|
await this.BLERefreshStatus();
|
|
386
395
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
387
396
|
await this.openAPIRefreshStatus();
|
|
@@ -392,6 +401,30 @@ export class BlindTilt extends deviceBase {
|
|
|
392
401
|
}
|
|
393
402
|
|
|
394
403
|
async BLERefreshStatus(): Promise<void> {
|
|
404
|
+
await this.debugLog('BLERefreshStatus');
|
|
405
|
+
const switchbot = await this.switchbotBLE();
|
|
406
|
+
if (switchbot === undefined) {
|
|
407
|
+
await this.BLERefreshConnection(switchbot);
|
|
408
|
+
} else {
|
|
409
|
+
// Start to monitor advertisement packets
|
|
410
|
+
(async () => {
|
|
411
|
+
// Start to monitor advertisement packets
|
|
412
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as blindTiltServiceData;
|
|
413
|
+
// Update HomeKit
|
|
414
|
+
if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
|
|
415
|
+
this.serviceData = serviceData;
|
|
416
|
+
await this.BLEparseStatus();
|
|
417
|
+
await this.updateHomeKitCharacteristics();
|
|
418
|
+
} else {
|
|
419
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
420
|
+
await this.BLERefreshConnection(switchbot);
|
|
421
|
+
}
|
|
422
|
+
})();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async registerPlatformBLE(): Promise<void> {
|
|
427
|
+
await this.debugLog('registerPlatformBLE');
|
|
395
428
|
if (this.config.options?.BLE) {
|
|
396
429
|
await this.debugLog('is listening to Platform BLE.');
|
|
397
430
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -407,26 +440,7 @@ export class BlindTilt extends deviceBase {
|
|
|
407
440
|
}
|
|
408
441
|
};
|
|
409
442
|
} 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
|
-
}
|
|
443
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
430
444
|
}
|
|
431
445
|
}
|
|
432
446
|
|
|
@@ -792,6 +806,7 @@ export class BlindTilt extends deviceBase {
|
|
|
792
806
|
}
|
|
793
807
|
|
|
794
808
|
if (this.setNewTarget) {
|
|
809
|
+
this.blindTiltMoving = true;
|
|
795
810
|
await this.infoLog('Checking Status ...');
|
|
796
811
|
await this.setMinMax();
|
|
797
812
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
@@ -812,6 +827,7 @@ export class BlindTilt extends deviceBase {
|
|
|
812
827
|
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
813
828
|
}
|
|
814
829
|
} else {
|
|
830
|
+
this.blindTiltMoving = false;
|
|
815
831
|
await this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
816
832
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
817
833
|
if (homekitTiltAngle) {
|
package/src/device/bot.ts
CHANGED
|
@@ -427,10 +427,14 @@ export class Bot extends deviceBase {
|
|
|
427
427
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
428
428
|
this.refreshStatus();
|
|
429
429
|
|
|
430
|
-
//regisiter webhook event handler
|
|
430
|
+
//regisiter webhook event handler if enabled
|
|
431
431
|
this.debugLog('Registering Webhook Event Handler');
|
|
432
432
|
this.registerWebhook();
|
|
433
433
|
|
|
434
|
+
//regisiter platform BLE event handler if enabled
|
|
435
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
436
|
+
this.registerPlatformBLE();
|
|
437
|
+
|
|
434
438
|
// Start an update interval
|
|
435
439
|
interval(this.deviceRefreshRate * 1000)
|
|
436
440
|
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
@@ -558,7 +562,7 @@ export class Bot extends deviceBase {
|
|
|
558
562
|
async refreshStatus(): Promise<void> {
|
|
559
563
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
560
564
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
561
|
-
} else if (this.BLE
|
|
565
|
+
} else if (this.BLE) {
|
|
562
566
|
await this.BLERefreshStatus();
|
|
563
567
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
564
568
|
await this.openAPIRefreshStatus();
|
|
@@ -570,6 +574,29 @@ export class Bot extends deviceBase {
|
|
|
570
574
|
|
|
571
575
|
async BLERefreshStatus(): Promise<void> {
|
|
572
576
|
await this.debugLog('BLERefreshStatus');
|
|
577
|
+
const switchbot = await this.switchbotBLE();
|
|
578
|
+
if (switchbot === undefined) {
|
|
579
|
+
await this.BLERefreshConnection(switchbot);
|
|
580
|
+
} else {
|
|
581
|
+
// Start to monitor advertisement packets
|
|
582
|
+
(async () => {
|
|
583
|
+
// Start to monitor advertisement packets
|
|
584
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
585
|
+
// Update HomeKit
|
|
586
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
587
|
+
this.serviceData = serviceData;
|
|
588
|
+
await this.BLEparseStatus();
|
|
589
|
+
await this.updateHomeKitCharacteristics();
|
|
590
|
+
} else {
|
|
591
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
592
|
+
await this.BLERefreshConnection(switchbot);
|
|
593
|
+
}
|
|
594
|
+
})();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
async registerPlatformBLE(): Promise<void> {
|
|
599
|
+
await this.debugLog('registerPlatformBLE');
|
|
573
600
|
if (this.config.options?.BLE) {
|
|
574
601
|
await this.debugLog('is listening to Platform BLE.');
|
|
575
602
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -585,26 +612,7 @@ export class Bot extends deviceBase {
|
|
|
585
612
|
}
|
|
586
613
|
};
|
|
587
614
|
} 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
|
-
}
|
|
615
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
608
616
|
}
|
|
609
617
|
}
|
|
610
618
|
|
|
@@ -164,10 +164,14 @@ export class CeilingLight extends deviceBase {
|
|
|
164
164
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
165
165
|
this.refreshStatus();
|
|
166
166
|
|
|
167
|
-
//regisiter webhook event handler
|
|
167
|
+
//regisiter webhook event handler if enabled
|
|
168
168
|
this.debugLog('Registering Webhook Event Handler');
|
|
169
169
|
this.registerWebhook();
|
|
170
170
|
|
|
171
|
+
//regisiter platform BLE event handler if enabled
|
|
172
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
173
|
+
this.registerPlatformBLE();
|
|
174
|
+
|
|
171
175
|
// Start an update interval
|
|
172
176
|
interval(this.deviceRefreshRate * 1000)
|
|
173
177
|
.pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
|
|
@@ -275,7 +279,7 @@ export class CeilingLight extends deviceBase {
|
|
|
275
279
|
async refreshStatus(): Promise<void> {
|
|
276
280
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
277
281
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
278
|
-
} else if (this.BLE
|
|
282
|
+
} else if (this.BLE) {
|
|
279
283
|
await this.BLERefreshStatus();
|
|
280
284
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
281
285
|
await this.openAPIRefreshStatus();
|
|
@@ -287,11 +291,34 @@ export class CeilingLight extends deviceBase {
|
|
|
287
291
|
|
|
288
292
|
async BLERefreshStatus(): Promise<void> {
|
|
289
293
|
await this.debugLog('BLERefreshStatus');
|
|
294
|
+
const switchbot = await this.switchbotBLE();
|
|
295
|
+
if (switchbot === undefined) {
|
|
296
|
+
await this.BLERefreshConnection(switchbot);
|
|
297
|
+
} else {
|
|
298
|
+
(async () => {
|
|
299
|
+
// Start to monitor advertisement packets
|
|
300
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
|
|
301
|
+
// Update HomeKit
|
|
302
|
+
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
303
|
+
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
304
|
+
this.serviceData = serviceData;
|
|
305
|
+
await this.BLEparseStatus();
|
|
306
|
+
await this.updateHomeKitCharacteristics();
|
|
307
|
+
} else {
|
|
308
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
309
|
+
await this.BLERefreshConnection(switchbot);
|
|
310
|
+
}
|
|
311
|
+
})();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async registerPlatformBLE(): Promise<void> {
|
|
316
|
+
await this.debugLog('registerPlatformBLE');
|
|
290
317
|
if (this.config.options?.BLE) {
|
|
291
318
|
await this.debugLog('is listening to Platform BLE.');
|
|
292
319
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
293
320
|
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
294
|
-
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData) => {
|
|
321
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData | ceilingLightProServiceData) => {
|
|
295
322
|
try {
|
|
296
323
|
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
297
324
|
this.serviceData = context;
|
|
@@ -302,26 +329,7 @@ export class CeilingLight extends deviceBase {
|
|
|
302
329
|
}
|
|
303
330
|
};
|
|
304
331
|
} 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
|
-
}
|
|
332
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
335
|
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -160,10 +160,14 @@ export class ColorBulb extends deviceBase {
|
|
|
160
160
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
161
161
|
this.refreshStatus();
|
|
162
162
|
|
|
163
|
-
//regisiter webhook event handler
|
|
163
|
+
//regisiter webhook event handler if enabled
|
|
164
164
|
this.debugLog('Registering Webhook Event Handler');
|
|
165
165
|
this.registerWebhook();
|
|
166
166
|
|
|
167
|
+
//regisiter platform BLE event handler if enabled
|
|
168
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
169
|
+
this.registerPlatformBLE();
|
|
170
|
+
|
|
167
171
|
// Start an update interval
|
|
168
172
|
interval(this.deviceRefreshRate * 1000)
|
|
169
173
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
@@ -296,7 +300,7 @@ export class ColorBulb extends deviceBase {
|
|
|
296
300
|
async refreshStatus(): Promise<void> {
|
|
297
301
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
298
302
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
299
|
-
} else if (this.BLE
|
|
303
|
+
} else if (this.BLE) {
|
|
300
304
|
await this.BLERefreshStatus();
|
|
301
305
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
302
306
|
await this.openAPIRefreshStatus();
|
|
@@ -308,6 +312,29 @@ export class ColorBulb extends deviceBase {
|
|
|
308
312
|
|
|
309
313
|
async BLERefreshStatus(): Promise<void> {
|
|
310
314
|
await this.debugLog('BLERefreshStatus');
|
|
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 colorBulbServiceData;
|
|
323
|
+
// Update HomeKit
|
|
324
|
+
if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
|
|
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
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async registerPlatformBLE(): Promise<void> {
|
|
337
|
+
await this.debugLog('registerPlatformBLE');
|
|
311
338
|
if (this.config.options?.BLE) {
|
|
312
339
|
await this.debugLog('is listening to Platform BLE.');
|
|
313
340
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -323,26 +350,7 @@ export class ColorBulb extends deviceBase {
|
|
|
323
350
|
}
|
|
324
351
|
};
|
|
325
352
|
} 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
|
-
}
|
|
353
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
346
354
|
}
|
|
347
355
|
}
|
|
348
356
|
|
package/src/device/contact.ts
CHANGED
|
@@ -172,10 +172,14 @@ export class Contact extends deviceBase {
|
|
|
172
172
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
173
173
|
this.refreshStatus();
|
|
174
174
|
|
|
175
|
-
//regisiter webhook event handler
|
|
175
|
+
//regisiter webhook event handler if enabled
|
|
176
176
|
this.debugLog('Registering Webhook Event Handler');
|
|
177
177
|
this.registerWebhook();
|
|
178
178
|
|
|
179
|
+
//regisiter platform BLE event handler if enabled
|
|
180
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
181
|
+
this.registerPlatformBLE();
|
|
182
|
+
|
|
179
183
|
// Start an update interval
|
|
180
184
|
interval(this.deviceRefreshRate * 1000)
|
|
181
185
|
.pipe(skipWhile(() => this.contactUpdateInProgress))
|
|
@@ -284,7 +288,7 @@ export class Contact extends deviceBase {
|
|
|
284
288
|
async refreshStatus(): Promise<void> {
|
|
285
289
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
286
290
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
287
|
-
} else if (this.BLE
|
|
291
|
+
} else if (this.BLE) {
|
|
288
292
|
await this.BLERefreshStatus();
|
|
289
293
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
290
294
|
await this.openAPIRefreshStatus();
|
|
@@ -296,6 +300,29 @@ export class Contact extends deviceBase {
|
|
|
296
300
|
|
|
297
301
|
async BLERefreshStatus(): Promise<void> {
|
|
298
302
|
await this.debugLog('BLERefreshStatus');
|
|
303
|
+
const switchbot = await this.switchbotBLE();
|
|
304
|
+
if (switchbot === undefined) {
|
|
305
|
+
await this.BLERefreshConnection(switchbot);
|
|
306
|
+
} else {
|
|
307
|
+
// Start to monitor advertisement packets
|
|
308
|
+
(async () => {
|
|
309
|
+
// Start to monitor advertisement packets
|
|
310
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData;
|
|
311
|
+
// Update HomeKit
|
|
312
|
+
if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
|
|
313
|
+
this.serviceData = serviceData;
|
|
314
|
+
await this.BLEparseStatus();
|
|
315
|
+
await this.updateHomeKitCharacteristics();
|
|
316
|
+
} else {
|
|
317
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
318
|
+
await this.BLERefreshConnection(switchbot);
|
|
319
|
+
}
|
|
320
|
+
})();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async registerPlatformBLE(): Promise<void> {
|
|
325
|
+
await this.debugLog('registerPlatformBLE');
|
|
299
326
|
if (this.config.options?.BLE) {
|
|
300
327
|
await this.debugLog('is listening to Platform BLE.');
|
|
301
328
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -311,26 +338,7 @@ export class Contact extends deviceBase {
|
|
|
311
338
|
}
|
|
312
339
|
};
|
|
313
340
|
} 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
|
-
}
|
|
341
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
334
342
|
}
|
|
335
343
|
}
|
|
336
344
|
|
package/src/device/curtain.ts
CHANGED
|
@@ -54,6 +54,7 @@ export class Curtain extends deviceBase {
|
|
|
54
54
|
setNewTargetTimer!: NodeJS.Timeout;
|
|
55
55
|
|
|
56
56
|
// Updates
|
|
57
|
+
curtainMoving!: boolean;
|
|
57
58
|
curtainUpdateInProgress!: boolean;
|
|
58
59
|
doCurtainUpdate!: Subject<void>;
|
|
59
60
|
|
|
@@ -68,6 +69,7 @@ export class Curtain extends deviceBase {
|
|
|
68
69
|
|
|
69
70
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
70
71
|
this.doCurtainUpdate = new Subject();
|
|
72
|
+
this.curtainMoving = false;
|
|
71
73
|
this.curtainUpdateInProgress = false;
|
|
72
74
|
this.setNewTarget = false;
|
|
73
75
|
|
|
@@ -189,10 +191,14 @@ export class Curtain extends deviceBase {
|
|
|
189
191
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
190
192
|
this.refreshStatus();
|
|
191
193
|
|
|
192
|
-
//regisiter webhook event handler
|
|
194
|
+
//regisiter webhook event handler if enabled
|
|
193
195
|
this.debugLog('Registering Webhook Event Handler');
|
|
194
196
|
this.registerWebhook();
|
|
195
197
|
|
|
198
|
+
//regisiter platform BLE event handler if enabled
|
|
199
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
200
|
+
this.registerPlatformBLE();
|
|
201
|
+
|
|
196
202
|
// History
|
|
197
203
|
this.history();
|
|
198
204
|
|
|
@@ -205,7 +211,7 @@ export class Curtain extends deviceBase {
|
|
|
205
211
|
|
|
206
212
|
// update slide progress
|
|
207
213
|
interval(this.deviceUpdateRate * 1000)
|
|
208
|
-
|
|
214
|
+
.pipe(skipWhile(() => !this.curtainMoving))
|
|
209
215
|
.subscribe(async () => {
|
|
210
216
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
211
217
|
return;
|
|
@@ -340,6 +346,7 @@ export class Curtain extends deviceBase {
|
|
|
340
346
|
await this.infoLog('Checking Status ...');
|
|
341
347
|
}
|
|
342
348
|
if (this.setNewTarget && this.deviceStatus.moving) {
|
|
349
|
+
this.curtainMoving = true;
|
|
343
350
|
await this.setMinMax();
|
|
344
351
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
345
352
|
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
@@ -358,6 +365,7 @@ export class Curtain extends deviceBase {
|
|
|
358
365
|
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
359
366
|
}
|
|
360
367
|
} else {
|
|
368
|
+
this.curtainMoving = false;
|
|
361
369
|
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
362
370
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
363
371
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
@@ -425,7 +433,7 @@ export class Curtain extends deviceBase {
|
|
|
425
433
|
async refreshStatus(): Promise<void> {
|
|
426
434
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
427
435
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
428
|
-
} else if (this.BLE
|
|
436
|
+
} else if (this.BLE) {
|
|
429
437
|
await this.BLERefreshStatus();
|
|
430
438
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
431
439
|
await this.openAPIRefreshStatus();
|
|
@@ -437,42 +445,25 @@ export class Curtain extends deviceBase {
|
|
|
437
445
|
|
|
438
446
|
async BLERefreshStatus(): Promise<void> {
|
|
439
447
|
await this.debugLog('BLERefreshStatus');
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
444
|
-
this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
|
|
445
|
-
try {
|
|
446
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
447
|
-
this.serviceData = context;
|
|
448
|
-
await this.BLEparseStatus();
|
|
449
|
-
await this.updateHomeKitCharacteristics();
|
|
450
|
-
} catch (e: any) {
|
|
451
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
448
|
+
const switchbot = await this.switchbotBLE();
|
|
449
|
+
if (switchbot === undefined) {
|
|
450
|
+
await this.BLERefreshConnection(switchbot);
|
|
454
451
|
} else {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (switchbot === undefined) {
|
|
458
|
-
await this.BLERefreshConnection(switchbot);
|
|
459
|
-
} else {
|
|
452
|
+
// Start to monitor advertisement packets
|
|
453
|
+
(async () => {
|
|
460
454
|
// Start to monitor advertisement packets
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
// Update HomeKit
|
|
465
|
-
if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
|
|
455
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData;
|
|
456
|
+
// Update HomeKit
|
|
457
|
+
if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
|
|
466
458
|
&& (serviceData.modelName === SwitchBotBLEModelName.Curtain || SwitchBotBLEModelName.Curtain3)) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
459
|
+
this.serviceData = serviceData;
|
|
460
|
+
await this.BLEparseStatus();
|
|
461
|
+
await this.updateHomeKitCharacteristics();
|
|
462
|
+
} else {
|
|
463
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
464
|
+
await this.BLERefreshConnection(switchbot);
|
|
465
|
+
}
|
|
466
|
+
})();
|
|
476
467
|
}
|
|
477
468
|
}
|
|
478
469
|
|
|
@@ -515,6 +506,27 @@ export class Curtain extends deviceBase {
|
|
|
515
506
|
}
|
|
516
507
|
}
|
|
517
508
|
|
|
509
|
+
async registerPlatformBLE(): Promise<void> {
|
|
510
|
+
await this.debugLog('registerPlatformBLE');
|
|
511
|
+
if (this.config.options?.BLE) {
|
|
512
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
513
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
514
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
515
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
|
|
516
|
+
try {
|
|
517
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
518
|
+
this.serviceData = context;
|
|
519
|
+
await this.BLEparseStatus();
|
|
520
|
+
await this.updateHomeKitCharacteristics();
|
|
521
|
+
} catch (e: any) {
|
|
522
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
} else {
|
|
526
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
518
530
|
/**
|
|
519
531
|
* Pushes the requested changes to the SwitchBot API
|
|
520
532
|
*/
|
|
@@ -761,6 +773,7 @@ export class Curtain extends deviceBase {
|
|
|
761
773
|
await this.setMinMax();
|
|
762
774
|
await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
763
775
|
if (this.setNewTarget) {
|
|
776
|
+
this.curtainMoving = true;
|
|
764
777
|
this.infoLog('Checking Status ...');
|
|
765
778
|
await this.setMinMax();
|
|
766
779
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
@@ -780,6 +793,7 @@ export class Curtain extends deviceBase {
|
|
|
780
793
|
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
781
794
|
}
|
|
782
795
|
} else {
|
|
796
|
+
this.curtainMoving = false;
|
|
783
797
|
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
784
798
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
785
799
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|