@switchbot/homebridge-switchbot 1.3.1-beta.9 → 1.4.1-beta.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 +18 -2
- package/config.schema.json +82 -32
- package/dist/devices/bots.d.ts +15 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +227 -165
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +14 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +163 -105
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +102 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +180 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +14 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +173 -133
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +17 -13
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +150 -105
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +89 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +15 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +115 -53
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +13 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +97 -46
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +13 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +85 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +12 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +73 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +12 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +83 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +12 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +74 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +12 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +80 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +12 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +90 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +12 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +73 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +12 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +73 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -6
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +6 -6
- package/src/devices/bots.ts +221 -152
- package/src/devices/colorbulb.ts +172 -108
- package/src/devices/contact.ts +109 -64
- package/src/devices/curtains.ts +190 -146
- package/src/devices/humidifiers.ts +181 -135
- package/src/devices/meters.ts +156 -105
- package/src/devices/motion.ts +95 -45
- package/src/devices/plugs.ts +121 -53
- package/src/irdevices/airconditioners.ts +102 -46
- package/src/irdevices/airpurifiers.ts +91 -31
- package/src/irdevices/cameras.ts +79 -24
- package/src/irdevices/fans.ts +89 -36
- package/src/irdevices/lights.ts +80 -25
- package/src/irdevices/others.ts +86 -31
- package/src/irdevices/tvs.ts +96 -42
- package/src/irdevices/vacuumcleaners.ts +79 -24
- package/src/irdevices/waterheaters.ts +79 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +10 -6
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/devices/curtains.ts
CHANGED
|
@@ -4,7 +4,7 @@ import Switchbot from 'node-switchbot';
|
|
|
4
4
|
import { interval, Subject } from 'rxjs';
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
+
import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
|
|
8
8
|
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
|
|
9
9
|
|
|
10
10
|
export class Curtain {
|
|
@@ -39,12 +39,12 @@ export class Curtain {
|
|
|
39
39
|
|
|
40
40
|
// Config
|
|
41
41
|
set_minStep!: number;
|
|
42
|
-
|
|
42
|
+
curtainRefreshRate!: number;
|
|
43
43
|
set_minLux!: number;
|
|
44
44
|
set_maxLux!: number;
|
|
45
|
+
deviceLogging!: string;
|
|
46
|
+
deviceRefreshRate!: number;
|
|
45
47
|
spaceBetweenLevels!: number;
|
|
46
|
-
private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
|
|
47
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
48
48
|
|
|
49
49
|
// Updates
|
|
50
50
|
curtainUpdateInProgress!: boolean;
|
|
@@ -55,18 +55,20 @@ export class Curtain {
|
|
|
55
55
|
private accessory: PlatformAccessory,
|
|
56
56
|
public device: device & devicesConfig,
|
|
57
57
|
) {
|
|
58
|
-
// Curtain Config
|
|
59
|
-
this.platform.device(`Curtain: ${this.accessory.displayName} Config: (ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},`
|
|
60
|
-
+ ` hide_lightsensor: ${device.curtain?.hide_lightsensor}, set_minLux: ${device.curtain?.set_minLux}, set_maxLux: `
|
|
61
|
-
+ `${device.curtain?.set_maxLux}, refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: `
|
|
62
|
-
+ `${device.curtain?.set_min}, set_minStep: ${device.curtain?.set_minStep})`);
|
|
63
|
-
|
|
64
58
|
// default placeholders
|
|
59
|
+
this.refreshRate();
|
|
60
|
+
this.logs();
|
|
65
61
|
this.setMinMax();
|
|
66
62
|
this.CurrentPosition = 0;
|
|
67
63
|
this.TargetPosition = 0;
|
|
68
64
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
69
65
|
|
|
66
|
+
// Curtain Config
|
|
67
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Config: (ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},`
|
|
68
|
+
+ ` hide_lightsensor: ${device.curtain?.hide_lightsensor}, set_minLux: ${device.curtain?.set_minLux}, set_maxLux: `
|
|
69
|
+
+ `${device.curtain?.set_maxLux}, refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: `
|
|
70
|
+
+ `${device.curtain?.set_min}, set_minStep: ${device.curtain?.set_minStep})`);
|
|
71
|
+
|
|
70
72
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
71
73
|
this.doCurtainUpdate = new Subject();
|
|
72
74
|
this.curtainUpdateInProgress = false;
|
|
@@ -124,11 +126,11 @@ export class Curtain {
|
|
|
124
126
|
|
|
125
127
|
// Light Sensor Service
|
|
126
128
|
if (device.curtain?.hide_lightsensor) {
|
|
127
|
-
this.
|
|
129
|
+
this.debugLog(`Curtain: ${accessory.displayName} Removing Light Sensor Service`);
|
|
128
130
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
129
131
|
accessory.removeService(this.lightSensorService!);
|
|
130
132
|
} else if (!this.lightSensorService) {
|
|
131
|
-
this.
|
|
133
|
+
this.debugLog(`Curtain: ${accessory.displayName} Add Light Sensor Service`);
|
|
132
134
|
(this.lightSensorService =
|
|
133
135
|
this.accessory.getService(this.platform.Service.LightSensor) ||
|
|
134
136
|
this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`;
|
|
@@ -136,7 +138,7 @@ export class Curtain {
|
|
|
136
138
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
137
139
|
|
|
138
140
|
} else {
|
|
139
|
-
this.
|
|
141
|
+
this.debugLog(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
|
|
@@ -144,20 +146,20 @@ export class Curtain {
|
|
|
144
146
|
this.updateHomeKitCharacteristics();
|
|
145
147
|
|
|
146
148
|
// Start an update interval
|
|
147
|
-
interval(this.
|
|
149
|
+
interval(this.deviceRefreshRate * 1000)
|
|
148
150
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
149
151
|
.subscribe(() => {
|
|
150
152
|
this.refreshStatus();
|
|
151
153
|
});
|
|
152
154
|
|
|
153
155
|
// update slide progress
|
|
154
|
-
interval(this.curtainRefreshRate
|
|
156
|
+
interval(this.curtainRefreshRate * 1000)
|
|
155
157
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
156
158
|
.subscribe(() => {
|
|
157
159
|
if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
|
|
158
160
|
return;
|
|
159
161
|
}
|
|
160
|
-
this.
|
|
162
|
+
this.debugLog(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
|
|
161
163
|
this.refreshStatus();
|
|
162
164
|
});
|
|
163
165
|
|
|
@@ -175,38 +177,54 @@ export class Curtain {
|
|
|
175
177
|
try {
|
|
176
178
|
await this.pushChanges();
|
|
177
179
|
} catch (e: any) {
|
|
178
|
-
this.
|
|
179
|
-
if (this.
|
|
180
|
-
this.
|
|
180
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges`);
|
|
181
|
+
if (this.deviceLogging === 'debug') {
|
|
182
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,`
|
|
181
183
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
182
184
|
}
|
|
183
|
-
if (this.
|
|
184
|
-
this.
|
|
185
|
+
if (this.platform.debugMode) {
|
|
186
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,`
|
|
185
187
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
186
188
|
}
|
|
187
|
-
this.apiError(
|
|
189
|
+
this.apiError();
|
|
188
190
|
}
|
|
189
191
|
this.curtainUpdateInProgress = false;
|
|
190
192
|
});
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
refreshRate() {
|
|
196
|
+
// refreshRate
|
|
197
|
+
if (this.device.refreshRate) {
|
|
198
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
199
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
200
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
201
|
+
}
|
|
202
|
+
// curtainRefreshRate
|
|
201
203
|
if (this.device?.curtain?.refreshRate) {
|
|
202
|
-
this.
|
|
204
|
+
this.curtainRefreshRate = this.device?.curtain?.refreshRate;
|
|
203
205
|
} else {
|
|
204
|
-
this.
|
|
205
|
-
if (this.
|
|
206
|
-
this.
|
|
206
|
+
this.curtainRefreshRate = 5;
|
|
207
|
+
if (this.deviceLogging === 'debug') {
|
|
208
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
|
-
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
logs() {
|
|
214
|
+
if (this.device.logging) {
|
|
215
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
216
|
+
} else if (this.platform.config.options?.logging) {
|
|
217
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
218
|
+
} else {
|
|
219
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private connectBLE() {
|
|
224
|
+
const switchbot = new Switchbot();
|
|
225
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
226
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
227
|
+
return switchbot;
|
|
210
228
|
}
|
|
211
229
|
|
|
212
230
|
private minStep(): number {
|
|
@@ -245,35 +263,35 @@ export class Curtain {
|
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
private async BLEparseStatus() {
|
|
248
|
-
this.
|
|
266
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
|
|
249
267
|
this.setMinMax();
|
|
250
268
|
this.CurrentPosition = 100 - Number(this.position);
|
|
251
|
-
this.
|
|
269
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
252
270
|
if (this.setNewTarget) {
|
|
253
|
-
this.
|
|
271
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
if (this.setNewTarget) {
|
|
257
275
|
this.setMinMax();
|
|
258
276
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
259
|
-
this.
|
|
277
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
260
278
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
261
279
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
262
|
-
this.
|
|
280
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
263
281
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
264
282
|
} else {
|
|
265
|
-
this.
|
|
283
|
+
this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
266
284
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
267
285
|
}
|
|
268
286
|
} else {
|
|
269
|
-
this.
|
|
287
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
270
288
|
if (!this.setNewTarget) {
|
|
271
289
|
// If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
|
|
272
290
|
this.TargetPosition = this.CurrentPosition;
|
|
273
291
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
274
292
|
}
|
|
275
293
|
}
|
|
276
|
-
this.
|
|
294
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
277
295
|
+ ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
278
296
|
|
|
279
297
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
@@ -285,47 +303,47 @@ export class Curtain {
|
|
|
285
303
|
switch (this.lightLevel) {
|
|
286
304
|
case 1:
|
|
287
305
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
288
|
-
this.
|
|
306
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
289
307
|
break;
|
|
290
308
|
case 2:
|
|
291
309
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels);
|
|
292
|
-
this.
|
|
310
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
293
311
|
+ ` Calculation: ${((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels)}`);
|
|
294
312
|
break;
|
|
295
313
|
case 3:
|
|
296
314
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2);
|
|
297
|
-
this.
|
|
315
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
298
316
|
break;
|
|
299
317
|
case 4:
|
|
300
318
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3);
|
|
301
|
-
this.
|
|
319
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
302
320
|
break;
|
|
303
321
|
case 5:
|
|
304
322
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4);
|
|
305
|
-
this.
|
|
323
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
306
324
|
break;
|
|
307
325
|
case 6:
|
|
308
326
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5);
|
|
309
|
-
this.
|
|
327
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
310
328
|
break;
|
|
311
329
|
case 7:
|
|
312
330
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6);
|
|
313
|
-
this.
|
|
331
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
314
332
|
break;
|
|
315
333
|
case 8:
|
|
316
334
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7);
|
|
317
|
-
this.
|
|
335
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
318
336
|
break;
|
|
319
337
|
case 9:
|
|
320
338
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8);
|
|
321
|
-
this.
|
|
339
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
322
340
|
break;
|
|
323
341
|
case 10:
|
|
324
342
|
default:
|
|
325
343
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
326
|
-
this.
|
|
344
|
+
this.debugLog();
|
|
327
345
|
}
|
|
328
|
-
this.
|
|
346
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
329
347
|
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
330
348
|
}
|
|
331
349
|
// Battery
|
|
@@ -335,41 +353,41 @@ export class Curtain {
|
|
|
335
353
|
} else {
|
|
336
354
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
337
355
|
}
|
|
338
|
-
this.
|
|
356
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
339
357
|
}
|
|
340
358
|
|
|
341
359
|
private async openAPIparseStatus() {
|
|
342
360
|
if (this.platform.config.credentials?.openToken) {
|
|
343
|
-
this.
|
|
361
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
344
362
|
// CurrentPosition
|
|
345
363
|
this.setMinMax();
|
|
346
364
|
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
|
|
347
|
-
this.
|
|
365
|
+
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
348
366
|
if (this.setNewTarget) {
|
|
349
|
-
this.
|
|
367
|
+
this.infoLog(`Checking ${this.accessory.displayName} Status ...`);
|
|
350
368
|
}
|
|
351
369
|
|
|
352
370
|
if (this.deviceStatus.body.moving) {
|
|
353
371
|
this.setMinMax();
|
|
354
372
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
355
|
-
this.
|
|
373
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
356
374
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
357
375
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
358
|
-
this.
|
|
376
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
359
377
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
360
378
|
} else {
|
|
361
|
-
this.
|
|
379
|
+
this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
362
380
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
363
381
|
}
|
|
364
382
|
} else {
|
|
365
|
-
this.
|
|
383
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
366
384
|
if (!this.setNewTarget) {
|
|
367
385
|
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
|
|
368
386
|
this.TargetPosition = this.CurrentPosition;
|
|
369
387
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
370
388
|
}
|
|
371
389
|
}
|
|
372
|
-
this.
|
|
390
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
373
391
|
+ ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
374
392
|
|
|
375
393
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
@@ -384,7 +402,7 @@ export class Curtain {
|
|
|
384
402
|
default:
|
|
385
403
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
386
404
|
}
|
|
387
|
-
this.
|
|
405
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
388
406
|
}
|
|
389
407
|
}
|
|
390
408
|
}
|
|
@@ -398,7 +416,7 @@ export class Curtain {
|
|
|
398
416
|
}
|
|
399
417
|
|
|
400
418
|
private async BLERefreshStatus() {
|
|
401
|
-
this.
|
|
419
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
402
420
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
403
421
|
const switchbot = this.connectBLE();
|
|
404
422
|
// Start to monitor advertisement packets
|
|
@@ -413,16 +431,16 @@ export class Curtain {
|
|
|
413
431
|
this.battery = ad.serviceData.battery;
|
|
414
432
|
this.position = ad.serviceData.position;
|
|
415
433
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
416
|
-
this.
|
|
417
|
-
this.
|
|
434
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
435
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, `
|
|
418
436
|
+ `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
419
437
|
|
|
420
438
|
if (this.serviceData) {
|
|
421
439
|
this.connected = true;
|
|
422
|
-
this.
|
|
440
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
423
441
|
} else {
|
|
424
442
|
this.connected = false;
|
|
425
|
-
this.
|
|
443
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
426
444
|
}
|
|
427
445
|
};
|
|
428
446
|
// Wait 10 seconds
|
|
@@ -434,49 +452,49 @@ export class Curtain {
|
|
|
434
452
|
this.parseStatus();
|
|
435
453
|
this.updateHomeKitCharacteristics();
|
|
436
454
|
} else {
|
|
437
|
-
this.
|
|
455
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
438
456
|
if (this.platform.config.credentials?.openToken) {
|
|
439
|
-
this.
|
|
457
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
440
458
|
await this.openAPIRefreshStatus();
|
|
441
459
|
}
|
|
442
460
|
}
|
|
443
461
|
}).catch(async (e: any) => {
|
|
444
|
-
this.
|
|
445
|
-
if (this.
|
|
446
|
-
this.
|
|
462
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
463
|
+
if (this.deviceLogging === 'debug') {
|
|
464
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
447
465
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
448
466
|
}
|
|
449
|
-
if (this.
|
|
450
|
-
this.
|
|
467
|
+
if (this.platform.debugMode) {
|
|
468
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
451
469
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
452
470
|
}
|
|
453
471
|
if (this.platform.config.credentials?.openToken) {
|
|
454
|
-
this.
|
|
472
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
455
473
|
await this.openAPIRefreshStatus();
|
|
456
474
|
}
|
|
457
|
-
this.apiError(
|
|
475
|
+
this.apiError();
|
|
458
476
|
});
|
|
459
477
|
}
|
|
460
478
|
|
|
461
479
|
private async openAPIRefreshStatus() {
|
|
462
480
|
if (this.platform.config.credentials?.openToken) {
|
|
463
|
-
this.
|
|
481
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
464
482
|
try {
|
|
465
483
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
466
|
-
this.
|
|
484
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
467
485
|
this.parseStatus();
|
|
468
486
|
this.updateHomeKitCharacteristics();
|
|
469
487
|
} catch (e: any) {
|
|
470
|
-
this.
|
|
471
|
-
if (this.
|
|
472
|
-
this.
|
|
488
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
489
|
+
if (this.deviceLogging === 'debug') {
|
|
490
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
473
491
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
474
492
|
}
|
|
475
|
-
if (this.
|
|
476
|
-
this.
|
|
493
|
+
if (this.platform.debugMode) {
|
|
494
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
477
495
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
478
496
|
}
|
|
479
|
-
this.apiError(
|
|
497
|
+
this.apiError();
|
|
480
498
|
}
|
|
481
499
|
}
|
|
482
500
|
}
|
|
@@ -497,41 +515,41 @@ export class Curtain {
|
|
|
497
515
|
|
|
498
516
|
private async BLEpushChanges() {
|
|
499
517
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
500
|
-
this.
|
|
518
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
501
519
|
const switchbot = this.connectBLE();
|
|
502
520
|
switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
503
|
-
this.
|
|
521
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
504
522
|
return device_list[0].runToPos(100 - Number(this.TargetPosition));
|
|
505
523
|
}).then(() => {
|
|
506
|
-
this.
|
|
524
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Done.`);
|
|
507
525
|
}).catch(async (e: any) => {
|
|
508
|
-
this.
|
|
509
|
-
if (this.
|
|
510
|
-
this.
|
|
526
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
527
|
+
if (this.deviceLogging === 'debug') {
|
|
528
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
511
529
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
512
530
|
}
|
|
513
|
-
if (this.
|
|
514
|
-
this.
|
|
531
|
+
if (this.platform.debugMode) {
|
|
532
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
515
533
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
516
534
|
}
|
|
517
535
|
if (this.platform.config.credentials?.openToken) {
|
|
518
|
-
this.
|
|
536
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
519
537
|
await this.OpenAPIpushChanges();
|
|
520
538
|
}
|
|
521
|
-
this.apiError(
|
|
539
|
+
this.apiError();
|
|
522
540
|
});
|
|
523
541
|
} else {
|
|
524
|
-
this.
|
|
525
|
-
|
|
542
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
543
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
526
544
|
}
|
|
527
545
|
}
|
|
528
546
|
|
|
529
547
|
private async OpenAPIpushChanges() {
|
|
530
548
|
if (this.platform.config.credentials?.openToken) {
|
|
531
549
|
try {
|
|
532
|
-
this.
|
|
550
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
533
551
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
534
|
-
this.
|
|
552
|
+
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
535
553
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
536
554
|
const payload = {
|
|
537
555
|
commandType: 'command',
|
|
@@ -539,28 +557,28 @@ export class Curtain {
|
|
|
539
557
|
parameter: `0,ff,${adjustedTargetPosition}`,
|
|
540
558
|
} as payload;
|
|
541
559
|
|
|
542
|
-
this.
|
|
560
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
543
561
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
544
562
|
|
|
545
563
|
// Make the API request
|
|
546
564
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
|
|
547
|
-
this.
|
|
565
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
548
566
|
this.statusCode(push);
|
|
549
567
|
} else {
|
|
550
|
-
this.
|
|
551
|
-
|
|
568
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
569
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
552
570
|
}
|
|
553
571
|
} catch (e: any) {
|
|
554
|
-
this.
|
|
555
|
-
if (this.
|
|
556
|
-
this.
|
|
572
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
573
|
+
if (this.deviceLogging === 'debug') {
|
|
574
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
557
575
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
558
576
|
}
|
|
559
|
-
if (this.
|
|
560
|
-
this.
|
|
577
|
+
if (this.platform.debugMode) {
|
|
578
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
561
579
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
562
580
|
}
|
|
563
|
-
this.apiError(
|
|
581
|
+
this.apiError();
|
|
564
582
|
}
|
|
565
583
|
}
|
|
566
584
|
}
|
|
@@ -568,86 +586,77 @@ export class Curtain {
|
|
|
568
586
|
updateHomeKitCharacteristics() {
|
|
569
587
|
this.setMinMax();
|
|
570
588
|
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
571
|
-
this.
|
|
589
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
572
590
|
} else {
|
|
573
591
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
574
|
-
this.
|
|
592
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
575
593
|
}
|
|
576
594
|
if (this.PositionState === undefined) {
|
|
577
|
-
this.
|
|
595
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
578
596
|
} else {
|
|
579
|
-
this.
|
|
597
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
580
598
|
}
|
|
581
599
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
582
|
-
this.
|
|
600
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
583
601
|
} else {
|
|
584
602
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
585
|
-
this.
|
|
603
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
586
604
|
}
|
|
587
605
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
588
606
|
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
589
|
-
this.
|
|
607
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
590
608
|
} else {
|
|
591
609
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
592
|
-
this.
|
|
610
|
+
this.debugLog(`Curtain: ${this.accessory.displayName}`
|
|
593
611
|
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
594
612
|
}
|
|
595
613
|
}
|
|
596
614
|
if (this.device.ble) {
|
|
597
615
|
if (this.BatteryLevel === undefined) {
|
|
598
|
-
this.
|
|
616
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
599
617
|
} else {
|
|
600
618
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
601
|
-
this.
|
|
619
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
602
620
|
}
|
|
603
621
|
if (this.StatusLowBattery === undefined) {
|
|
604
|
-
this.
|
|
622
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
605
623
|
} else {
|
|
606
624
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
607
|
-
this.
|
|
625
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
608
626
|
}
|
|
609
627
|
}
|
|
610
628
|
}
|
|
611
629
|
|
|
612
|
-
public apiError(
|
|
613
|
-
this.
|
|
614
|
-
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
615
|
-
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
616
|
-
if (!this.device.curtain?.hide_lightsensor) {
|
|
617
|
-
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
618
|
-
}
|
|
619
|
-
if (this.device.ble) {
|
|
620
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
621
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
622
|
-
}
|
|
630
|
+
public apiError() {
|
|
631
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
623
632
|
}
|
|
624
633
|
|
|
625
634
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
626
635
|
switch (push.data.statusCode) {
|
|
627
636
|
case 151:
|
|
628
|
-
this.
|
|
637
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
629
638
|
break;
|
|
630
639
|
case 152:
|
|
631
|
-
this.
|
|
640
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device not found.`);
|
|
632
641
|
break;
|
|
633
642
|
case 160:
|
|
634
|
-
this.
|
|
643
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Command is not supported.`);
|
|
635
644
|
break;
|
|
636
645
|
case 161:
|
|
637
|
-
this.
|
|
646
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device is offline.`);
|
|
638
647
|
break;
|
|
639
648
|
case 171:
|
|
640
|
-
this.
|
|
649
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
641
650
|
break;
|
|
642
651
|
case 190:
|
|
643
|
-
this.
|
|
652
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
644
653
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
645
654
|
break;
|
|
646
655
|
case 100:
|
|
647
|
-
this.
|
|
656
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
|
|
648
657
|
break;
|
|
649
658
|
default:
|
|
650
|
-
this.
|
|
659
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Unknown statusCode.`);
|
|
651
660
|
}
|
|
652
661
|
}
|
|
653
662
|
|
|
@@ -655,7 +664,7 @@ export class Curtain {
|
|
|
655
664
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
656
665
|
*/
|
|
657
666
|
TargetPositionSet(value: CharacteristicValue) {
|
|
658
|
-
this.
|
|
667
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
659
668
|
|
|
660
669
|
this.TargetPosition = value;
|
|
661
670
|
|
|
@@ -663,15 +672,15 @@ export class Curtain {
|
|
|
663
672
|
if (value > this.CurrentPosition) {
|
|
664
673
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
665
674
|
this.setNewTarget = true;
|
|
666
|
-
this.
|
|
675
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
667
676
|
} else if (value < this.CurrentPosition) {
|
|
668
677
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
669
678
|
this.setNewTarget = true;
|
|
670
|
-
this.
|
|
679
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
671
680
|
} else {
|
|
672
681
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
673
682
|
this.setNewTarget = false;
|
|
674
|
-
this.
|
|
683
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
675
684
|
}
|
|
676
685
|
this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
677
686
|
this.service.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
@@ -683,7 +692,7 @@ export class Curtain {
|
|
|
683
692
|
clearTimeout(this.setNewTargetTimer);
|
|
684
693
|
if (this.setNewTarget) {
|
|
685
694
|
this.setNewTargetTimer = setTimeout(() => {
|
|
686
|
-
this.
|
|
695
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
687
696
|
this.setNewTarget = false;
|
|
688
697
|
}, 10000);
|
|
689
698
|
}
|
|
@@ -702,4 +711,39 @@ export class Curtain {
|
|
|
702
711
|
}
|
|
703
712
|
}
|
|
704
713
|
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Logging for Device
|
|
717
|
+
*/
|
|
718
|
+
infoLog(...log: any[]) {
|
|
719
|
+
if (this.enablingDeviceLogging()) {
|
|
720
|
+
this.platform.log.info(String(...log));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
warnLog(...log: any[]) {
|
|
725
|
+
if (this.enablingDeviceLogging()) {
|
|
726
|
+
this.platform.log.warn(String(...log));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
errorLog(...log: any[]) {
|
|
731
|
+
if (this.enablingDeviceLogging()) {
|
|
732
|
+
this.platform.log.error(String(...log));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
debugLog(...log: any[]) {
|
|
737
|
+
if (this.enablingDeviceLogging()) {
|
|
738
|
+
if (this.deviceLogging === 'debug') {
|
|
739
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
740
|
+
} else {
|
|
741
|
+
this.platform.log.debug(String(...log));
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
enablingDeviceLogging(): boolean {
|
|
747
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
748
|
+
}
|
|
705
749
|
}
|