@switchbot/homebridge-switchbot 3.5.0 → 3.5.1-beta.1
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/.github/npm-version-script.cjs +81 -0
- package/config.schema.json +4 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +64 -189
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +34 -68
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +65 -158
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +47 -159
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +42 -105
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +61 -182
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -2
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +182 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +76 -145
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +7 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +54 -17
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +55 -104
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +27 -46
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +56 -120
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +36 -66
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +27 -46
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +26 -45
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +24 -43
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +32 -66
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +43 -88
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +23 -43
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +10 -28
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +8 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +8 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +8 -20
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +7 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +28 -0
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +8 -20
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +8 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +8 -20
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +8 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +8 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +4 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +19 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -1
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +71 -186
- package/src/device/bot.ts +32 -68
- package/src/device/ceilinglight.ts +67 -153
- package/src/device/colorbulb.ts +51 -155
- package/src/device/contact.ts +49 -104
- package/src/device/curtain.ts +70 -177
- package/src/device/device.ts +207 -8
- package/src/device/fan.ts +75 -147
- package/src/device/hub.ts +55 -19
- package/src/device/humidifier.ts +52 -104
- package/src/device/iosensor.ts +25 -46
- package/src/device/lightstrip.ts +54 -121
- package/src/device/lock.ts +35 -67
- package/src/device/meter.ts +25 -46
- package/src/device/meterplus.ts +24 -45
- package/src/device/motion.ts +22 -43
- package/src/device/plug.ts +30 -66
- package/src/device/robotvacuumcleaner.ts +40 -89
- package/src/device/waterdetector.ts +22 -43
- package/src/irdevice/airconditioner.ts +10 -26
- package/src/irdevice/airpurifier.ts +8 -20
- package/src/irdevice/camera.ts +8 -20
- package/src/irdevice/fan.ts +8 -20
- package/src/irdevice/irdevice.ts +29 -0
- package/src/irdevice/light.ts +8 -20
- package/src/irdevice/other.ts +8 -20
- package/src/irdevice/tv.ts +8 -20
- package/src/irdevice/vacuumcleaner.ts +8 -20
- package/src/irdevice/waterheater.ts +8 -20
- package/src/settings.ts +4 -2
- package/src/utils.ts +20 -1
package/src/device/curtain.ts
CHANGED
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
* curtain.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { hostname } from 'os';
|
|
6
|
-
import { request } from 'undici';
|
|
7
6
|
import { interval, Subject } from 'rxjs';
|
|
8
7
|
import { deviceBase } from './device.js';
|
|
9
|
-
import { Devices } from '../settings.js';
|
|
10
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
11
9
|
|
|
12
10
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -296,8 +294,9 @@ export class Curtain extends deviceBase {
|
|
|
296
294
|
|
|
297
295
|
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
298
296
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
297
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(serviceData)}`);
|
|
299
298
|
// CurrentPosition
|
|
300
|
-
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.position);
|
|
299
|
+
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.position!);
|
|
301
300
|
await this.setMinMax();
|
|
302
301
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
303
302
|
if (this.setNewTarget) {
|
|
@@ -345,44 +344,36 @@ export class Curtain extends deviceBase {
|
|
|
345
344
|
break;
|
|
346
345
|
case 2:
|
|
347
346
|
this.LightSensor!.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
348
|
-
this.debugLog(
|
|
349
|
-
|
|
350
|
-
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
347
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
348
|
+
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
351
349
|
break;
|
|
352
350
|
case 3:
|
|
353
351
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
354
352
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
355
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
356
353
|
break;
|
|
357
354
|
case 4:
|
|
358
355
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
359
356
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
360
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
361
357
|
break;
|
|
362
358
|
case 5:
|
|
363
359
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
364
360
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
365
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
366
361
|
break;
|
|
367
362
|
case 6:
|
|
368
363
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
369
364
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
370
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
371
365
|
break;
|
|
372
366
|
case 7:
|
|
373
367
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
374
368
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
375
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
376
369
|
break;
|
|
377
370
|
case 8:
|
|
378
371
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
379
372
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
380
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
381
373
|
break;
|
|
382
374
|
case 9:
|
|
383
375
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
384
376
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
385
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
386
377
|
break;
|
|
387
378
|
case 10:
|
|
388
379
|
default:
|
|
@@ -506,63 +497,43 @@ export class Curtain extends deviceBase {
|
|
|
506
497
|
|
|
507
498
|
async BLERefreshStatus(): Promise<void> {
|
|
508
499
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
509
|
-
const switchbot = await this.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.
|
|
513
|
-
|
|
514
|
-
.toLowerCase();
|
|
515
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
516
|
-
this.getCustomBLEAddress(switchbot);
|
|
500
|
+
const switchbot = await this.switchbotBLE();
|
|
501
|
+
|
|
502
|
+
if (switchbot === undefined) {
|
|
503
|
+
await this.BLERefreshConnection(switchbot);
|
|
504
|
+
} else {
|
|
517
505
|
// Start to monitor advertisement packets
|
|
518
|
-
|
|
506
|
+
(async () => {
|
|
519
507
|
// Start to monitor advertisement packets
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
526
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
508
|
+
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
509
|
+
// Update HomeKit
|
|
510
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
511
|
+
await this.BLEparseStatus(serviceData);
|
|
512
|
+
await this.updateHomeKitCharacteristics();
|
|
527
513
|
} else {
|
|
528
|
-
this.
|
|
514
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
515
|
+
await this.BLERefreshConnection(switchbot);
|
|
529
516
|
}
|
|
530
|
-
};
|
|
531
|
-
// Wait 10 seconds
|
|
532
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
533
|
-
// Stop to monitor
|
|
534
|
-
await switchbot.stopScan();
|
|
535
|
-
// Update HomeKit
|
|
536
|
-
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
537
|
-
await this.updateHomeKitCharacteristics();
|
|
538
|
-
})();
|
|
539
|
-
if (switchbot === undefined) {
|
|
540
|
-
await this.BLERefreshConnection(switchbot);
|
|
517
|
+
})();
|
|
541
518
|
}
|
|
542
519
|
}
|
|
543
520
|
|
|
544
521
|
async openAPIRefreshStatus(): Promise<void> {
|
|
545
522
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
546
523
|
try {
|
|
547
|
-
const { body, statusCode } = await this.
|
|
548
|
-
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
549
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
524
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
550
525
|
const deviceStatus: any = await body.json();
|
|
551
|
-
this.
|
|
552
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
526
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);
|
|
553
527
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
554
|
-
this.
|
|
555
|
-
|
|
556
|
-
this.
|
|
557
|
-
this.updateHomeKitCharacteristics();
|
|
528
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
529
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
530
|
+
await this.updateHomeKitCharacteristics();
|
|
558
531
|
} else {
|
|
559
|
-
this.
|
|
560
|
-
this.statusCode(deviceStatus.statusCode);
|
|
532
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
561
533
|
}
|
|
562
534
|
} catch (e: any) {
|
|
563
|
-
this.apiError(e);
|
|
564
|
-
this.
|
|
565
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
535
|
+
await this.apiError(e);
|
|
536
|
+
await this.openAPIRefreshError(e);
|
|
566
537
|
}
|
|
567
538
|
}
|
|
568
539
|
|
|
@@ -597,8 +568,7 @@ export class Curtain extends deviceBase {
|
|
|
597
568
|
await this.openAPIpushChanges();
|
|
598
569
|
} else {
|
|
599
570
|
await this.offlineOff();
|
|
600
|
-
this.
|
|
601
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
571
|
+
await this.pushChangeDisabled();
|
|
602
572
|
}
|
|
603
573
|
// Refresh the status from the API
|
|
604
574
|
interval(15000)
|
|
@@ -614,17 +584,13 @@ export class Curtain extends deviceBase {
|
|
|
614
584
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
615
585
|
const switchbot = await this.platform.connectBLE();
|
|
616
586
|
// Convert to BLE Address
|
|
617
|
-
|
|
618
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
619
|
-
.join(':')
|
|
620
|
-
.toLowerCase();
|
|
621
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
587
|
+
await this.convertBLEAddress();
|
|
622
588
|
const { setPositionMode, Mode }: { setPositionMode: number; Mode: string; } = await this.setPerformance();
|
|
623
589
|
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xff;
|
|
624
590
|
this.debugLog(`${this.accessory.displayName} Mode: ${Mode}`);
|
|
625
591
|
if (switchbot !== false) {
|
|
626
592
|
try {
|
|
627
|
-
const device_list = await switchbot.discover({ model:
|
|
593
|
+
const device_list = await switchbot.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac });
|
|
628
594
|
this.infoLog(`${this.accessory.displayName} Target Position: ${this.WindowCovering.TargetPosition}`);
|
|
629
595
|
|
|
630
596
|
await this.retryBLE({
|
|
@@ -681,16 +647,9 @@ export class Curtain extends deviceBase {
|
|
|
681
647
|
});
|
|
682
648
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
683
649
|
try {
|
|
684
|
-
const { body, statusCode } = await
|
|
685
|
-
body: bodyChange,
|
|
686
|
-
method: 'POST',
|
|
687
|
-
headers: this.platform.generateHeaders(),
|
|
688
|
-
});
|
|
689
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
650
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
690
651
|
const deviceStatus: any = await body.json();
|
|
691
|
-
this.
|
|
692
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
693
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
652
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
694
653
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
695
654
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
696
655
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
@@ -726,26 +685,27 @@ export class Curtain extends deviceBase {
|
|
|
726
685
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition);
|
|
727
686
|
|
|
728
687
|
this.WindowCovering.TargetPosition = value;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
688
|
+
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
|
|
689
|
+
await this.mqtt('HoldPosition', this.WindowCovering.HoldPosition);
|
|
690
|
+
await this.startUpdatingCurtainIfNeeded();
|
|
691
|
+
}
|
|
733
692
|
|
|
693
|
+
async startUpdatingCurtainIfNeeded() {
|
|
734
694
|
await this.setMinMax();
|
|
735
|
-
if (
|
|
695
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
736
696
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
737
697
|
this.setNewTarget = true;
|
|
738
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
698
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
739
699
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
740
|
-
} else if (
|
|
700
|
+
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
741
701
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
742
702
|
this.setNewTarget = true;
|
|
743
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
703
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
744
704
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
745
705
|
} else {
|
|
746
706
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
747
707
|
this.setNewTarget = false;
|
|
748
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
708
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
749
709
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
750
710
|
}
|
|
751
711
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
@@ -777,102 +737,33 @@ export class Curtain extends deviceBase {
|
|
|
777
737
|
|
|
778
738
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
779
739
|
await this.setMinMax();
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
this.
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
this.accessory.context.PositionState = this.WindowCovering.PositionState;
|
|
798
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
|
|
799
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
800
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
801
|
-
}
|
|
802
|
-
if (this.WindowCovering.TargetPosition === undefined || Number.isNaN(this.WindowCovering.TargetPosition)) {
|
|
803
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
804
|
-
} else {
|
|
805
|
-
if (this.device.mqttURL) {
|
|
806
|
-
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
807
|
-
}
|
|
808
|
-
this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
|
|
809
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
|
|
810
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
811
|
-
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
812
|
-
}
|
|
813
|
-
if (this.WindowCovering.HoldPosition === undefined) {
|
|
814
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} HoldPosition: ${this.WindowCovering.HoldPosition}`);
|
|
815
|
-
} else {
|
|
816
|
-
if (this.device.mqttURL) {
|
|
817
|
-
this.mqttPublish('HoldPosition', this.WindowCovering.HoldPosition.toString());
|
|
818
|
-
}
|
|
819
|
-
this.accessory.context.HoldPosition = this.WindowCovering.HoldPosition;
|
|
820
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition);
|
|
821
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
822
|
-
+ ` HoldPosition: ${this.WindowCovering.HoldPosition}`);
|
|
823
|
-
}
|
|
824
|
-
if (!this.device.curtain?.hide_lightsensor) {
|
|
825
|
-
if (this.LightSensor!.CurrentAmbientLightLevel === undefined || Number.isNaN(this.LightSensor!.CurrentAmbientLightLevel)) {
|
|
826
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
827
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
828
|
-
} else {
|
|
829
|
-
if (this.device.mqttURL) {
|
|
830
|
-
this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor!.CurrentAmbientLightLevel.toString());
|
|
831
|
-
}
|
|
832
|
-
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor!.CurrentAmbientLightLevel;
|
|
833
|
-
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor!.CurrentAmbientLightLevel);
|
|
834
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
835
|
-
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
836
|
-
if (this.device.history) {
|
|
837
|
-
this.historyService?.addEntry({
|
|
838
|
-
time: Math.round(new Date().valueOf() / 1000),
|
|
839
|
-
lux: this.LightSensor!.CurrentAmbientLightLevel,
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
845
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
846
|
-
} else {
|
|
847
|
-
if (this.device.mqttURL) {
|
|
848
|
-
this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
|
|
849
|
-
}
|
|
850
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
851
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
852
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
853
|
-
}
|
|
854
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
855
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
856
|
-
} else {
|
|
857
|
-
if (this.device.mqttURL) {
|
|
858
|
-
this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
|
|
859
|
-
}
|
|
860
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
861
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
862
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
863
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
864
|
-
}
|
|
865
|
-
if (this.Battery.ChargingState === undefined) {
|
|
866
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
867
|
-
} else {
|
|
868
|
-
if (this.device.mqttURL) {
|
|
869
|
-
this.mqttPublish('ChargingState', this.Battery.ChargingState.toString());
|
|
870
|
-
}
|
|
871
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
872
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
873
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
874
|
-
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
740
|
+
// CurrentPosition
|
|
741
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition,
|
|
742
|
+
this.WindowCovering.CurrentPosition, 'CurrentPosition');
|
|
743
|
+
// PositionState
|
|
744
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState,
|
|
745
|
+
this.WindowCovering.PositionState, 'PositionState');
|
|
746
|
+
// TargetPosition
|
|
747
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition,
|
|
748
|
+
this.WindowCovering.TargetPosition, 'TargetPosition');
|
|
749
|
+
// HoldPosition
|
|
750
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.HoldPosition,
|
|
751
|
+
this.WindowCovering.HoldPosition, 'HoldPosition');
|
|
752
|
+
// CurrentAmbientLightLevel
|
|
753
|
+
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
754
|
+
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel };
|
|
755
|
+
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
756
|
+
this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
|
|
875
757
|
}
|
|
758
|
+
// BatteryLevel
|
|
759
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
760
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
761
|
+
// StatusLowBattery
|
|
762
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
763
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
764
|
+
// ChargingState
|
|
765
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
766
|
+
this.Battery.ChargingState, 'ChargingState');
|
|
876
767
|
}
|
|
877
768
|
|
|
878
769
|
async BLEPushConnection() {
|
|
@@ -883,8 +774,10 @@ export class Curtain extends deviceBase {
|
|
|
883
774
|
}
|
|
884
775
|
|
|
885
776
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
886
|
-
|
|
777
|
+
if (switchbot !== undefined) {
|
|
778
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
887
779
|
+ ` ${JSON.stringify(switchbot)}`);
|
|
780
|
+
}
|
|
888
781
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
889
782
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
890
783
|
await this.openAPIRefreshStatus();
|