@switchbot/homebridge-switchbot 1.10.2-beta.7 → 1.11.2
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 +20 -3
- package/config.schema.json +49 -0
- package/dist/device/bot.d.ts +43 -40
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +26 -26
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +25 -21
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +176 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -15
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +14 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +25 -22
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -37
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +23 -20
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -38
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +16 -13
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +17 -17
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -15
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +14 -14
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +13 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +19 -19
- package/dist/device/plug.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +44 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +20 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +11 -11
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +29 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +17 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +25 -25
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +13 -13
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +16 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +50 -50
- package/src/device/colorbulb.ts +206 -157
- package/src/device/contact.ts +31 -30
- package/src/device/curtain.ts +68 -57
- package/src/device/humidifier.ts +65 -53
- package/src/device/lock.ts +25 -25
- package/src/device/meter.ts +25 -25
- package/src/device/motion.ts +27 -27
- package/src/device/plug.ts +22 -22
- package/src/irdevice/airconditioner.ts +54 -54
- package/src/irdevice/airpurifier.ts +30 -30
- package/src/irdevice/camera.ts +19 -19
- package/src/irdevice/fan.ts +40 -40
- package/src/irdevice/light.ts +23 -23
- package/src/irdevice/other.ts +25 -25
- package/src/irdevice/tv.ts +42 -42
- package/src/irdevice/vacuumcleaner.ts +21 -21
- package/src/irdevice/waterheater.ts +24 -24
- package/src/platform.ts +4 -4
- package/src/settings.ts +5 -1
package/src/device/contact.ts
CHANGED
|
@@ -11,10 +11,10 @@ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusR
|
|
|
11
11
|
*/
|
|
12
12
|
export class Contact {
|
|
13
13
|
// Services
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
contactSensorservice: Service;
|
|
15
|
+
motionService?: Service;
|
|
16
|
+
lightSensorService?: Service;
|
|
17
|
+
batteryService?: Service;
|
|
18
18
|
|
|
19
19
|
// Characteristic Values
|
|
20
20
|
ContactSensorState!: CharacteristicValue;
|
|
@@ -69,12 +69,13 @@ export class Contact {
|
|
|
69
69
|
accessory
|
|
70
70
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
71
71
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
72
|
-
.setCharacteristic(this.platform.Characteristic.Model, '
|
|
72
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'W1201500')
|
|
73
73
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
74
74
|
|
|
75
75
|
// get the Contact service if it exists, otherwise create a new Contact service
|
|
76
76
|
// you can create multiple services for each accessory
|
|
77
|
-
(this.
|
|
77
|
+
(this.contactSensorservice =
|
|
78
|
+
accessory.getService(this.platform.Service.ContactSensor) || accessory.addService(this.platform.Service.ContactSensor)),
|
|
78
79
|
`${accessory.displayName} Contact Sensor`;
|
|
79
80
|
|
|
80
81
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -83,7 +84,7 @@ export class Contact {
|
|
|
83
84
|
|
|
84
85
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
85
86
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
86
|
-
this.
|
|
87
|
+
this.contactSensorservice.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
87
88
|
|
|
88
89
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
89
90
|
// see https://developers.homebridge.io/#/service/ContactSensor
|
|
@@ -141,15 +142,15 @@ export class Contact {
|
|
|
141
142
|
// Start an update interval
|
|
142
143
|
interval(this.deviceRefreshRate * 1000)
|
|
143
144
|
.pipe(skipWhile(() => this.contactUbpdateInProgress))
|
|
144
|
-
.subscribe(() => {
|
|
145
|
-
this.refreshStatus();
|
|
145
|
+
.subscribe(async () => {
|
|
146
|
+
await this.refreshStatus();
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Parse the device status from the SwitchBot api
|
|
151
152
|
*/
|
|
152
|
-
async parseStatus() {
|
|
153
|
+
async parseStatus(): Promise<void> {
|
|
153
154
|
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
154
155
|
await this.openAPIparseStatus();
|
|
155
156
|
} else {
|
|
@@ -157,7 +158,7 @@ export class Contact {
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
async BLEparseStatus() {
|
|
161
|
+
async BLEparseStatus(): Promise<void> {
|
|
161
162
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
|
|
162
163
|
// Door State
|
|
163
164
|
switch (this.doorState) {
|
|
@@ -207,7 +208,7 @@ export class Contact {
|
|
|
207
208
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
208
209
|
}
|
|
209
210
|
|
|
210
|
-
async openAPIparseStatus() {
|
|
211
|
+
async openAPIparseStatus(): Promise<void> {
|
|
211
212
|
if (this.device.ble) {
|
|
212
213
|
this.SwitchToOpenAPI = false;
|
|
213
214
|
}
|
|
@@ -248,7 +249,7 @@ export class Contact {
|
|
|
248
249
|
/**
|
|
249
250
|
* Asks the SwitchBot API for the latest device information
|
|
250
251
|
*/
|
|
251
|
-
async refreshStatus() {
|
|
252
|
+
async refreshStatus(): Promise<void> {
|
|
252
253
|
if (this.device.ble) {
|
|
253
254
|
await this.BLERefreshStatus();
|
|
254
255
|
} else {
|
|
@@ -256,7 +257,7 @@ export class Contact {
|
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
|
|
259
|
-
|
|
260
|
+
async BLERefreshStatus(): Promise<void> {
|
|
260
261
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
|
|
261
262
|
const switchbot = await this.platform.connectBLE();
|
|
262
263
|
// Convert to BLE Address
|
|
@@ -334,7 +335,7 @@ export class Contact {
|
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
337
|
|
|
337
|
-
|
|
338
|
+
async BLEconnection(switchbot: any): Promise<void> {
|
|
338
339
|
this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
339
340
|
if (this.platform.config.credentials?.openToken) {
|
|
340
341
|
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -343,7 +344,7 @@ export class Contact {
|
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
|
|
346
|
-
|
|
347
|
+
async openAPIRefreshStatus(): Promise<void> {
|
|
347
348
|
if (this.platform.config.credentials?.openToken) {
|
|
348
349
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
349
350
|
try {
|
|
@@ -375,11 +376,11 @@ export class Contact {
|
|
|
375
376
|
/**
|
|
376
377
|
* Updates the status for each of the HomeKit Characteristics
|
|
377
378
|
*/
|
|
378
|
-
updateHomeKitCharacteristics() {
|
|
379
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
379
380
|
if (this.ContactSensorState === undefined) {
|
|
380
381
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
381
382
|
} else {
|
|
382
|
-
this.
|
|
383
|
+
this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
383
384
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
384
385
|
}
|
|
385
386
|
if (!this.device.contact?.hide_motionsensor) {
|
|
@@ -416,8 +417,8 @@ export class Contact {
|
|
|
416
417
|
}
|
|
417
418
|
}
|
|
418
419
|
|
|
419
|
-
|
|
420
|
-
this.
|
|
420
|
+
async apiError(e: any): Promise<void> {
|
|
421
|
+
this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
|
|
421
422
|
if (!this.device.contact?.hide_motionsensor) {
|
|
422
423
|
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
|
|
423
424
|
}
|
|
@@ -431,7 +432,7 @@ export class Contact {
|
|
|
431
432
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
432
433
|
}
|
|
433
434
|
|
|
434
|
-
config(device: device & devicesConfig) {
|
|
435
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
435
436
|
let config = {};
|
|
436
437
|
if (device.contact) {
|
|
437
438
|
config = device.contact;
|
|
@@ -453,7 +454,7 @@ export class Contact {
|
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
refreshRate(device: device & devicesConfig) {
|
|
457
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
457
458
|
if (device.refreshRate) {
|
|
458
459
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
459
460
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
@@ -463,7 +464,7 @@ export class Contact {
|
|
|
463
464
|
}
|
|
464
465
|
}
|
|
465
466
|
|
|
466
|
-
scan(device: device & devicesConfig) {
|
|
467
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
467
468
|
if (device.scanDuration) {
|
|
468
469
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
469
470
|
if (device.ble) {
|
|
@@ -477,7 +478,7 @@ export class Contact {
|
|
|
477
478
|
}
|
|
478
479
|
}
|
|
479
480
|
|
|
480
|
-
logs(device: device & devicesConfig) {
|
|
481
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
481
482
|
if (this.platform.debugMode) {
|
|
482
483
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
483
484
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -493,7 +494,7 @@ export class Contact {
|
|
|
493
494
|
}
|
|
494
495
|
}
|
|
495
496
|
|
|
496
|
-
|
|
497
|
+
minLux(): number {
|
|
497
498
|
if (this.device.contact?.set_minLux) {
|
|
498
499
|
this.set_minLux = this.device.contact!.set_minLux!;
|
|
499
500
|
} else {
|
|
@@ -502,7 +503,7 @@ export class Contact {
|
|
|
502
503
|
return this.set_minLux;
|
|
503
504
|
}
|
|
504
505
|
|
|
505
|
-
|
|
506
|
+
maxLux(): number {
|
|
506
507
|
if (this.device.contact?.set_maxLux) {
|
|
507
508
|
this.set_maxLux = this.device.contact!.set_maxLux!;
|
|
508
509
|
} else {
|
|
@@ -514,25 +515,25 @@ export class Contact {
|
|
|
514
515
|
/**
|
|
515
516
|
* Logging for Device
|
|
516
517
|
*/
|
|
517
|
-
infoLog(...log: any[]) {
|
|
518
|
+
infoLog(...log: any[]): void {
|
|
518
519
|
if (this.enablingDeviceLogging()) {
|
|
519
520
|
this.platform.log.info(String(...log));
|
|
520
521
|
}
|
|
521
522
|
}
|
|
522
523
|
|
|
523
|
-
warnLog(...log: any[]) {
|
|
524
|
+
warnLog(...log: any[]): void {
|
|
524
525
|
if (this.enablingDeviceLogging()) {
|
|
525
526
|
this.platform.log.warn(String(...log));
|
|
526
527
|
}
|
|
527
528
|
}
|
|
528
529
|
|
|
529
|
-
errorLog(...log: any[]) {
|
|
530
|
+
errorLog(...log: any[]): void {
|
|
530
531
|
if (this.enablingDeviceLogging()) {
|
|
531
532
|
this.platform.log.error(String(...log));
|
|
532
533
|
}
|
|
533
534
|
}
|
|
534
535
|
|
|
535
|
-
debugLog(...log: any[]) {
|
|
536
|
+
debugLog(...log: any[]): void {
|
|
536
537
|
if (this.enablingDeviceLogging()) {
|
|
537
538
|
if (this.deviceLogging === 'debug') {
|
|
538
539
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/device/curtain.ts
CHANGED
|
@@ -7,9 +7,9 @@ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusR
|
|
|
7
7
|
|
|
8
8
|
export class Curtain {
|
|
9
9
|
// Services
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
windowCoveringService: Service;
|
|
11
|
+
lightSensorService?: Service;
|
|
12
|
+
batteryService?: Service;
|
|
13
13
|
|
|
14
14
|
// Characteristic Values
|
|
15
15
|
CurrentPosition!: CharacteristicValue;
|
|
@@ -56,8 +56,8 @@ export class Curtain {
|
|
|
56
56
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
57
57
|
// default placeholders
|
|
58
58
|
this.logs(device);
|
|
59
|
-
this.scan(device);
|
|
60
59
|
this.refreshRate(device);
|
|
60
|
+
this.scan(device);
|
|
61
61
|
this.config(device);
|
|
62
62
|
this.CurrentPosition = 0;
|
|
63
63
|
this.TargetPosition = 0;
|
|
@@ -75,12 +75,13 @@ export class Curtain {
|
|
|
75
75
|
accessory
|
|
76
76
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
77
77
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
78
|
-
.setCharacteristic(this.platform.Characteristic.Model, '
|
|
78
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'W0701600')
|
|
79
79
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
80
80
|
|
|
81
81
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
82
82
|
// you can create multiple services for each accessory
|
|
83
|
-
(this.
|
|
83
|
+
(this.windowCoveringService =
|
|
84
|
+
accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
|
|
84
85
|
`${device.deviceName} ${device.deviceType}`;
|
|
85
86
|
|
|
86
87
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -89,15 +90,15 @@ export class Curtain {
|
|
|
89
90
|
|
|
90
91
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
91
92
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
92
|
-
this.
|
|
93
|
+
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
93
94
|
|
|
94
95
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
95
96
|
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
96
97
|
|
|
97
98
|
// create handlers for required characteristics
|
|
98
|
-
this.
|
|
99
|
+
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
99
100
|
|
|
100
|
-
this.
|
|
101
|
+
this.windowCoveringService
|
|
101
102
|
.getCharacteristic(this.platform.Characteristic.CurrentPosition)
|
|
102
103
|
.setProps({
|
|
103
104
|
minStep: this.minStep(device),
|
|
@@ -109,7 +110,7 @@ export class Curtain {
|
|
|
109
110
|
return this.CurrentPosition;
|
|
110
111
|
});
|
|
111
112
|
|
|
112
|
-
this.
|
|
113
|
+
this.windowCoveringService
|
|
113
114
|
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
114
115
|
.setProps({
|
|
115
116
|
minStep: this.minStep(device),
|
|
@@ -154,19 +155,19 @@ export class Curtain {
|
|
|
154
155
|
// Start an update interval
|
|
155
156
|
interval(this.deviceRefreshRate * 1000)
|
|
156
157
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
157
|
-
.subscribe(() => {
|
|
158
|
-
this.refreshStatus();
|
|
158
|
+
.subscribe(async () => {
|
|
159
|
+
await this.refreshStatus();
|
|
159
160
|
});
|
|
160
161
|
|
|
161
162
|
// update slide progress
|
|
162
163
|
interval(this.updateRate * 1000)
|
|
163
164
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
164
|
-
.subscribe(() => {
|
|
165
|
+
.subscribe(async () => {
|
|
165
166
|
if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
this.debugLog(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
|
|
169
|
-
this.refreshStatus();
|
|
170
|
+
await this.refreshStatus();
|
|
170
171
|
});
|
|
171
172
|
|
|
172
173
|
// Watch for Curtain change events
|
|
@@ -198,7 +199,7 @@ export class Curtain {
|
|
|
198
199
|
/**
|
|
199
200
|
* Parse the device status from the SwitchBot api
|
|
200
201
|
*/
|
|
201
|
-
async parseStatus() {
|
|
202
|
+
async parseStatus(): Promise<void> {
|
|
202
203
|
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
203
204
|
await this.openAPIparseStatus();
|
|
204
205
|
} else {
|
|
@@ -206,18 +207,18 @@ export class Curtain {
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
|
|
210
|
+
async BLEparseStatus(): Promise<void> {
|
|
210
211
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
|
|
211
212
|
// CurrentPosition
|
|
212
213
|
this.CurrentPosition = 100 - Number(this.position);
|
|
213
|
-
this.setMinMax();
|
|
214
|
+
await this.setMinMax();
|
|
214
215
|
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
215
216
|
if (this.setNewTarget) {
|
|
216
217
|
this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
if (this.setNewTarget) {
|
|
220
|
-
this.setMinMax();
|
|
221
|
+
await this.setMinMax();
|
|
221
222
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
222
223
|
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
223
224
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
@@ -304,7 +305,7 @@ export class Curtain {
|
|
|
304
305
|
this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
305
306
|
}
|
|
306
307
|
|
|
307
|
-
|
|
308
|
+
async openAPIparseStatus(): Promise<void> {
|
|
308
309
|
if (this.device.ble) {
|
|
309
310
|
this.SwitchToOpenAPI = false;
|
|
310
311
|
}
|
|
@@ -312,14 +313,14 @@ export class Curtain {
|
|
|
312
313
|
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
313
314
|
// CurrentPosition
|
|
314
315
|
this.CurrentPosition = 100 - Number(this.slidePosition);
|
|
315
|
-
this.setMinMax();
|
|
316
|
+
await this.setMinMax();
|
|
316
317
|
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
317
318
|
if (this.setNewTarget) {
|
|
318
319
|
this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
if (this.setNewTarget && this.moving) {
|
|
322
|
-
this.setMinMax();
|
|
323
|
+
await this.setMinMax();
|
|
323
324
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
324
325
|
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
325
326
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
@@ -358,7 +359,7 @@ export class Curtain {
|
|
|
358
359
|
}
|
|
359
360
|
}
|
|
360
361
|
|
|
361
|
-
async refreshStatus() {
|
|
362
|
+
async refreshStatus(): Promise<void> {
|
|
362
363
|
if (this.device.ble) {
|
|
363
364
|
await this.BLERefreshStatus();
|
|
364
365
|
} else {
|
|
@@ -366,7 +367,7 @@ export class Curtain {
|
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
369
|
|
|
369
|
-
|
|
370
|
+
async BLERefreshStatus(): Promise<void> {
|
|
370
371
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
371
372
|
const switchbot = await this.platform.connectBLE();
|
|
372
373
|
// Convert to BLE Address
|
|
@@ -444,7 +445,7 @@ export class Curtain {
|
|
|
444
445
|
}
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
|
|
448
|
+
async BLEconnection(switchbot: any): Promise<void> {
|
|
448
449
|
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
449
450
|
if (this.platform.config.credentials?.openToken) {
|
|
450
451
|
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -453,7 +454,7 @@ export class Curtain {
|
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
|
|
457
|
+
async openAPIRefreshStatus(): Promise<void> {
|
|
457
458
|
if (this.platform.config.credentials?.openToken) {
|
|
458
459
|
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
459
460
|
try {
|
|
@@ -479,7 +480,7 @@ export class Curtain {
|
|
|
479
480
|
}
|
|
480
481
|
}
|
|
481
482
|
|
|
482
|
-
async pushChanges() {
|
|
483
|
+
async pushChanges(): Promise<void> {
|
|
483
484
|
if (this.device.ble) {
|
|
484
485
|
await this.BLEpushChanges();
|
|
485
486
|
} else {
|
|
@@ -488,12 +489,12 @@ export class Curtain {
|
|
|
488
489
|
interval(5000)
|
|
489
490
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
490
491
|
.pipe(take(1))
|
|
491
|
-
.subscribe(() => {
|
|
492
|
-
this.refreshStatus();
|
|
492
|
+
.subscribe(async () => {
|
|
493
|
+
await this.refreshStatus();
|
|
493
494
|
});
|
|
494
495
|
}
|
|
495
496
|
|
|
496
|
-
|
|
497
|
+
async BLEpushChanges(): Promise<void> {
|
|
497
498
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
498
499
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
499
500
|
const switchbot = await this.platform.connectBLE();
|
|
@@ -544,7 +545,7 @@ export class Curtain {
|
|
|
544
545
|
}
|
|
545
546
|
}
|
|
546
547
|
|
|
547
|
-
|
|
548
|
+
async openAPIpushChanges(): Promise<void> {
|
|
548
549
|
if (this.platform.config.credentials?.openToken) {
|
|
549
550
|
try {
|
|
550
551
|
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
@@ -587,12 +588,12 @@ export class Curtain {
|
|
|
587
588
|
}
|
|
588
589
|
}
|
|
589
590
|
|
|
590
|
-
updateHomeKitCharacteristics() {
|
|
591
|
-
this.setMinMax();
|
|
591
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
592
|
+
await this.setMinMax();
|
|
592
593
|
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
593
594
|
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
594
595
|
} else {
|
|
595
|
-
this.
|
|
596
|
+
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
596
597
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
597
598
|
}
|
|
598
599
|
if (this.PositionState === undefined) {
|
|
@@ -603,7 +604,7 @@ export class Curtain {
|
|
|
603
604
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
604
605
|
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
605
606
|
} else {
|
|
606
|
-
this.
|
|
607
|
+
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
607
608
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
608
609
|
}
|
|
609
610
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
@@ -630,10 +631,10 @@ export class Curtain {
|
|
|
630
631
|
}
|
|
631
632
|
}
|
|
632
633
|
|
|
633
|
-
|
|
634
|
-
this.
|
|
635
|
-
this.
|
|
636
|
-
this.
|
|
634
|
+
async apiError(e: any): Promise<void> {
|
|
635
|
+
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
636
|
+
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
637
|
+
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
637
638
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
638
639
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
639
640
|
}
|
|
@@ -644,7 +645,7 @@ export class Curtain {
|
|
|
644
645
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
645
646
|
}
|
|
646
647
|
|
|
647
|
-
|
|
648
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
648
649
|
switch (push.data.statusCode) {
|
|
649
650
|
case 151:
|
|
650
651
|
this.errorLog(`Curtain: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -678,12 +679,12 @@ export class Curtain {
|
|
|
678
679
|
/**
|
|
679
680
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
680
681
|
*/
|
|
681
|
-
TargetPositionSet(value: CharacteristicValue) {
|
|
682
|
+
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
682
683
|
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
683
684
|
|
|
684
685
|
this.TargetPosition = value;
|
|
685
686
|
|
|
686
|
-
this.setMinMax();
|
|
687
|
+
await this.setMinMax();
|
|
687
688
|
if (value > this.CurrentPosition) {
|
|
688
689
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
689
690
|
this.setNewTarget = true;
|
|
@@ -697,8 +698,8 @@ export class Curtain {
|
|
|
697
698
|
this.setNewTarget = false;
|
|
698
699
|
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
699
700
|
}
|
|
700
|
-
this.
|
|
701
|
-
this.
|
|
701
|
+
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
702
|
+
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
702
703
|
|
|
703
704
|
/**
|
|
704
705
|
* If Curtain movement time is short, the moving flag from backend is always false.
|
|
@@ -715,7 +716,7 @@ export class Curtain {
|
|
|
715
716
|
this.doCurtainUpdate.next();
|
|
716
717
|
}
|
|
717
718
|
|
|
718
|
-
|
|
719
|
+
async setMinMax(): Promise<void> {
|
|
719
720
|
if (this.device.curtain?.set_min) {
|
|
720
721
|
if (this.CurrentPosition <= this.device.curtain?.set_min) {
|
|
721
722
|
this.CurrentPosition = 0;
|
|
@@ -728,7 +729,7 @@ export class Curtain {
|
|
|
728
729
|
}
|
|
729
730
|
}
|
|
730
731
|
|
|
731
|
-
config(device: device & devicesConfig) {
|
|
732
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
732
733
|
let config = {};
|
|
733
734
|
if (device.curtain) {
|
|
734
735
|
config = device.curtain;
|
|
@@ -750,7 +751,7 @@ export class Curtain {
|
|
|
750
751
|
}
|
|
751
752
|
}
|
|
752
753
|
|
|
753
|
-
refreshRate(device: device & devicesConfig) {
|
|
754
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
754
755
|
// refreshRate
|
|
755
756
|
if (device.refreshRate) {
|
|
756
757
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
@@ -769,21 +770,31 @@ export class Curtain {
|
|
|
769
770
|
}
|
|
770
771
|
}
|
|
771
772
|
|
|
772
|
-
scan(device: device & devicesConfig) {
|
|
773
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
773
774
|
if (device.scanDuration) {
|
|
774
|
-
|
|
775
|
+
if (this.updateRate > device.scanDuration) {
|
|
776
|
+
this.scanDuration = this.updateRate;
|
|
777
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
778
|
+
} else {
|
|
779
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
780
|
+
}
|
|
775
781
|
if (device.ble) {
|
|
776
782
|
this.debugLog(`Curtain: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
777
783
|
}
|
|
778
784
|
} else {
|
|
779
|
-
|
|
785
|
+
if (this.updateRate > 1) {
|
|
786
|
+
this.scanDuration = this.updateRate;
|
|
787
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
788
|
+
} else {
|
|
789
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
790
|
+
}
|
|
780
791
|
if (this.device.ble) {
|
|
781
792
|
this.debugLog(`Curtain: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
782
793
|
}
|
|
783
794
|
}
|
|
784
795
|
}
|
|
785
796
|
|
|
786
|
-
logs(device: device & devicesConfig) {
|
|
797
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
787
798
|
if (this.platform.debugMode) {
|
|
788
799
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
789
800
|
this.debugLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -799,7 +810,7 @@ export class Curtain {
|
|
|
799
810
|
}
|
|
800
811
|
}
|
|
801
812
|
|
|
802
|
-
|
|
813
|
+
minStep(device: device & devicesConfig): number {
|
|
803
814
|
if (device.curtain?.set_minStep) {
|
|
804
815
|
this.set_minStep = device.curtain?.set_minStep;
|
|
805
816
|
} else {
|
|
@@ -808,7 +819,7 @@ export class Curtain {
|
|
|
808
819
|
return this.set_minStep;
|
|
809
820
|
}
|
|
810
821
|
|
|
811
|
-
|
|
822
|
+
minLux(): number {
|
|
812
823
|
if (this.device.curtain?.set_minLux) {
|
|
813
824
|
this.set_minLux = this.device.curtain?.set_minLux;
|
|
814
825
|
} else {
|
|
@@ -817,7 +828,7 @@ export class Curtain {
|
|
|
817
828
|
return this.set_minLux;
|
|
818
829
|
}
|
|
819
830
|
|
|
820
|
-
|
|
831
|
+
maxLux(): number {
|
|
821
832
|
if (this.device.curtain?.set_maxLux) {
|
|
822
833
|
this.set_maxLux = this.device.curtain?.set_maxLux;
|
|
823
834
|
} else {
|
|
@@ -829,25 +840,25 @@ export class Curtain {
|
|
|
829
840
|
/**
|
|
830
841
|
* Logging for Device
|
|
831
842
|
*/
|
|
832
|
-
infoLog(...log: any[]) {
|
|
843
|
+
infoLog(...log: any[]): void {
|
|
833
844
|
if (this.enablingDeviceLogging()) {
|
|
834
845
|
this.platform.log.info(String(...log));
|
|
835
846
|
}
|
|
836
847
|
}
|
|
837
848
|
|
|
838
|
-
warnLog(...log: any[]) {
|
|
849
|
+
warnLog(...log: any[]): void {
|
|
839
850
|
if (this.enablingDeviceLogging()) {
|
|
840
851
|
this.platform.log.warn(String(...log));
|
|
841
852
|
}
|
|
842
853
|
}
|
|
843
854
|
|
|
844
|
-
errorLog(...log: any[]) {
|
|
855
|
+
errorLog(...log: any[]): void {
|
|
845
856
|
if (this.enablingDeviceLogging()) {
|
|
846
857
|
this.platform.log.error(String(...log));
|
|
847
858
|
}
|
|
848
859
|
}
|
|
849
860
|
|
|
850
|
-
debugLog(...log: any[]) {
|
|
861
|
+
debugLog(...log: any[]): void {
|
|
851
862
|
if (this.enablingDeviceLogging()) {
|
|
852
863
|
if (this.deviceLogging === 'debug') {
|
|
853
864
|
this.platform.log.info('[DEBUG]', String(...log));
|