@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- 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 +117 -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 +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- 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 +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -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 +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +4 -1
- 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,72 @@ 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
|
-
|
|
195
|
+
refreshRate() {
|
|
196
|
+
// refreshRate
|
|
197
|
+
if (this.device.refreshRate) {
|
|
198
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
199
|
+
if (this.platform.debugMode) {
|
|
200
|
+
this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
201
|
+
}
|
|
202
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
203
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
204
|
+
if (this.platform.debugMode) {
|
|
205
|
+
this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// curtainRefreshRate
|
|
209
|
+
if (this.device?.curtain?.refreshRate) {
|
|
210
|
+
this.curtainRefreshRate = this.device?.curtain?.refreshRate;
|
|
211
|
+
if (this.platform.debugMode) {
|
|
212
|
+
this.warnLog(`Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
this.curtainRefreshRate = 5;
|
|
216
|
+
if (this.deviceLogging === 'debug') {
|
|
217
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
198
220
|
}
|
|
199
221
|
|
|
200
|
-
|
|
201
|
-
if (this.device
|
|
202
|
-
this.
|
|
222
|
+
logs() {
|
|
223
|
+
if (this.device.logging) {
|
|
224
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
225
|
+
if (this.platform.debugMode) {
|
|
226
|
+
this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
227
|
+
}
|
|
228
|
+
} else if (this.platform.config.options?.logging) {
|
|
229
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
230
|
+
if (this.platform.debugMode) {
|
|
231
|
+
this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
232
|
+
}
|
|
203
233
|
} else {
|
|
204
|
-
this.
|
|
205
|
-
if (this.platform.
|
|
206
|
-
this.
|
|
234
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
235
|
+
if (this.platform.debugMode) {
|
|
236
|
+
this.warnLog('Using Device Standard Logging');
|
|
207
237
|
}
|
|
208
238
|
}
|
|
209
|
-
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private connectBLE() {
|
|
242
|
+
const switchbot = new Switchbot();
|
|
243
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
244
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
245
|
+
return switchbot;
|
|
210
246
|
}
|
|
211
247
|
|
|
212
248
|
private minStep(): number {
|
|
@@ -245,35 +281,35 @@ export class Curtain {
|
|
|
245
281
|
}
|
|
246
282
|
|
|
247
283
|
private async BLEparseStatus() {
|
|
248
|
-
this.
|
|
284
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
|
|
249
285
|
this.setMinMax();
|
|
250
286
|
this.CurrentPosition = 100 - Number(this.position);
|
|
251
|
-
this.
|
|
287
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
252
288
|
if (this.setNewTarget) {
|
|
253
|
-
this.
|
|
289
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
|
|
254
290
|
}
|
|
255
291
|
|
|
256
292
|
if (this.setNewTarget) {
|
|
257
293
|
this.setMinMax();
|
|
258
294
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
259
|
-
this.
|
|
295
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
260
296
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
261
297
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
262
|
-
this.
|
|
298
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
263
299
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
264
300
|
} else {
|
|
265
|
-
this.
|
|
301
|
+
this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
266
302
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
267
303
|
}
|
|
268
304
|
} else {
|
|
269
|
-
this.
|
|
305
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
270
306
|
if (!this.setNewTarget) {
|
|
271
307
|
// If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
|
|
272
308
|
this.TargetPosition = this.CurrentPosition;
|
|
273
309
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
274
310
|
}
|
|
275
311
|
}
|
|
276
|
-
this.
|
|
312
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
277
313
|
+ ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
278
314
|
|
|
279
315
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
@@ -285,47 +321,47 @@ export class Curtain {
|
|
|
285
321
|
switch (this.lightLevel) {
|
|
286
322
|
case 1:
|
|
287
323
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
288
|
-
this.
|
|
324
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
289
325
|
break;
|
|
290
326
|
case 2:
|
|
291
327
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels);
|
|
292
|
-
this.
|
|
328
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
293
329
|
+ ` Calculation: ${((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels)}`);
|
|
294
330
|
break;
|
|
295
331
|
case 3:
|
|
296
332
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2);
|
|
297
|
-
this.
|
|
333
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
298
334
|
break;
|
|
299
335
|
case 4:
|
|
300
336
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3);
|
|
301
|
-
this.
|
|
337
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
302
338
|
break;
|
|
303
339
|
case 5:
|
|
304
340
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4);
|
|
305
|
-
this.
|
|
341
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
306
342
|
break;
|
|
307
343
|
case 6:
|
|
308
344
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5);
|
|
309
|
-
this.
|
|
345
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
310
346
|
break;
|
|
311
347
|
case 7:
|
|
312
348
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6);
|
|
313
|
-
this.
|
|
349
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
314
350
|
break;
|
|
315
351
|
case 8:
|
|
316
352
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7);
|
|
317
|
-
this.
|
|
353
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
318
354
|
break;
|
|
319
355
|
case 9:
|
|
320
356
|
this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8);
|
|
321
|
-
this.
|
|
357
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
322
358
|
break;
|
|
323
359
|
case 10:
|
|
324
360
|
default:
|
|
325
361
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
326
|
-
this.
|
|
362
|
+
this.debugLog();
|
|
327
363
|
}
|
|
328
|
-
this.
|
|
364
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
329
365
|
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
330
366
|
}
|
|
331
367
|
// Battery
|
|
@@ -335,41 +371,41 @@ export class Curtain {
|
|
|
335
371
|
} else {
|
|
336
372
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
337
373
|
}
|
|
338
|
-
this.
|
|
374
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
339
375
|
}
|
|
340
376
|
|
|
341
377
|
private async openAPIparseStatus() {
|
|
342
378
|
if (this.platform.config.credentials?.openToken) {
|
|
343
|
-
this.
|
|
379
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
344
380
|
// CurrentPosition
|
|
345
381
|
this.setMinMax();
|
|
346
382
|
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
|
|
347
|
-
this.
|
|
383
|
+
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
348
384
|
if (this.setNewTarget) {
|
|
349
|
-
this.
|
|
385
|
+
this.infoLog(`Checking ${this.accessory.displayName} Status ...`);
|
|
350
386
|
}
|
|
351
387
|
|
|
352
388
|
if (this.deviceStatus.body.moving) {
|
|
353
389
|
this.setMinMax();
|
|
354
390
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
355
|
-
this.
|
|
391
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
356
392
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
357
393
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
358
|
-
this.
|
|
394
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
359
395
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
360
396
|
} else {
|
|
361
|
-
this.
|
|
397
|
+
this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
362
398
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
363
399
|
}
|
|
364
400
|
} else {
|
|
365
|
-
this.
|
|
401
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
366
402
|
if (!this.setNewTarget) {
|
|
367
403
|
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
|
|
368
404
|
this.TargetPosition = this.CurrentPosition;
|
|
369
405
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
370
406
|
}
|
|
371
407
|
}
|
|
372
|
-
this.
|
|
408
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
373
409
|
+ ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
374
410
|
|
|
375
411
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
@@ -384,7 +420,7 @@ export class Curtain {
|
|
|
384
420
|
default:
|
|
385
421
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
386
422
|
}
|
|
387
|
-
this.
|
|
423
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
388
424
|
}
|
|
389
425
|
}
|
|
390
426
|
}
|
|
@@ -398,7 +434,7 @@ export class Curtain {
|
|
|
398
434
|
}
|
|
399
435
|
|
|
400
436
|
private async BLERefreshStatus() {
|
|
401
|
-
this.
|
|
437
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
402
438
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
403
439
|
const switchbot = this.connectBLE();
|
|
404
440
|
// Start to monitor advertisement packets
|
|
@@ -413,16 +449,16 @@ export class Curtain {
|
|
|
413
449
|
this.battery = ad.serviceData.battery;
|
|
414
450
|
this.position = ad.serviceData.position;
|
|
415
451
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
416
|
-
this.
|
|
417
|
-
this.
|
|
452
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
453
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, `
|
|
418
454
|
+ `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
419
455
|
|
|
420
456
|
if (this.serviceData) {
|
|
421
457
|
this.connected = true;
|
|
422
|
-
this.
|
|
458
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
423
459
|
} else {
|
|
424
460
|
this.connected = false;
|
|
425
|
-
this.
|
|
461
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
426
462
|
}
|
|
427
463
|
};
|
|
428
464
|
// Wait 10 seconds
|
|
@@ -434,49 +470,49 @@ export class Curtain {
|
|
|
434
470
|
this.parseStatus();
|
|
435
471
|
this.updateHomeKitCharacteristics();
|
|
436
472
|
} else {
|
|
437
|
-
this.
|
|
473
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
438
474
|
if (this.platform.config.credentials?.openToken) {
|
|
439
|
-
this.
|
|
475
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
440
476
|
await this.openAPIRefreshStatus();
|
|
441
477
|
}
|
|
442
478
|
}
|
|
443
479
|
}).catch(async (e: any) => {
|
|
444
|
-
this.
|
|
445
|
-
if (this.
|
|
446
|
-
this.
|
|
480
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
481
|
+
if (this.deviceLogging === 'debug') {
|
|
482
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
447
483
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
448
484
|
}
|
|
449
|
-
if (this.
|
|
450
|
-
this.
|
|
485
|
+
if (this.platform.debugMode) {
|
|
486
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
451
487
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
452
488
|
}
|
|
453
489
|
if (this.platform.config.credentials?.openToken) {
|
|
454
|
-
this.
|
|
490
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
455
491
|
await this.openAPIRefreshStatus();
|
|
456
492
|
}
|
|
457
|
-
this.apiError(
|
|
493
|
+
this.apiError();
|
|
458
494
|
});
|
|
459
495
|
}
|
|
460
496
|
|
|
461
497
|
private async openAPIRefreshStatus() {
|
|
462
498
|
if (this.platform.config.credentials?.openToken) {
|
|
463
|
-
this.
|
|
499
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
464
500
|
try {
|
|
465
501
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
466
|
-
this.
|
|
502
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
467
503
|
this.parseStatus();
|
|
468
504
|
this.updateHomeKitCharacteristics();
|
|
469
505
|
} catch (e: any) {
|
|
470
|
-
this.
|
|
471
|
-
if (this.
|
|
472
|
-
this.
|
|
506
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
507
|
+
if (this.deviceLogging === 'debug') {
|
|
508
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
473
509
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
474
510
|
}
|
|
475
|
-
if (this.
|
|
476
|
-
this.
|
|
511
|
+
if (this.platform.debugMode) {
|
|
512
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
477
513
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
478
514
|
}
|
|
479
|
-
this.apiError(
|
|
515
|
+
this.apiError();
|
|
480
516
|
}
|
|
481
517
|
}
|
|
482
518
|
}
|
|
@@ -497,41 +533,41 @@ export class Curtain {
|
|
|
497
533
|
|
|
498
534
|
private async BLEpushChanges() {
|
|
499
535
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
500
|
-
this.
|
|
536
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
501
537
|
const switchbot = this.connectBLE();
|
|
502
538
|
switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
503
|
-
this.
|
|
539
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
504
540
|
return device_list[0].runToPos(100 - Number(this.TargetPosition));
|
|
505
541
|
}).then(() => {
|
|
506
|
-
this.
|
|
542
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Done.`);
|
|
507
543
|
}).catch(async (e: any) => {
|
|
508
|
-
this.
|
|
509
|
-
if (this.
|
|
510
|
-
this.
|
|
544
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
545
|
+
if (this.deviceLogging === 'debug') {
|
|
546
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
511
547
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
512
548
|
}
|
|
513
|
-
if (this.
|
|
514
|
-
this.
|
|
549
|
+
if (this.platform.debugMode) {
|
|
550
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
515
551
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
516
552
|
}
|
|
517
553
|
if (this.platform.config.credentials?.openToken) {
|
|
518
|
-
this.
|
|
554
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
519
555
|
await this.OpenAPIpushChanges();
|
|
520
556
|
}
|
|
521
|
-
this.apiError(
|
|
557
|
+
this.apiError();
|
|
522
558
|
});
|
|
523
559
|
} else {
|
|
524
|
-
this.
|
|
525
|
-
|
|
560
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
561
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
526
562
|
}
|
|
527
563
|
}
|
|
528
564
|
|
|
529
565
|
private async OpenAPIpushChanges() {
|
|
530
566
|
if (this.platform.config.credentials?.openToken) {
|
|
531
567
|
try {
|
|
532
|
-
this.
|
|
568
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
533
569
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
534
|
-
this.
|
|
570
|
+
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
535
571
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
536
572
|
const payload = {
|
|
537
573
|
commandType: 'command',
|
|
@@ -539,28 +575,28 @@ export class Curtain {
|
|
|
539
575
|
parameter: `0,ff,${adjustedTargetPosition}`,
|
|
540
576
|
} as payload;
|
|
541
577
|
|
|
542
|
-
this.
|
|
578
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
543
579
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
544
580
|
|
|
545
581
|
// Make the API request
|
|
546
582
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
|
|
547
|
-
this.
|
|
583
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
548
584
|
this.statusCode(push);
|
|
549
585
|
} else {
|
|
550
|
-
this.
|
|
551
|
-
|
|
586
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
587
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
552
588
|
}
|
|
553
589
|
} catch (e: any) {
|
|
554
|
-
this.
|
|
555
|
-
if (this.
|
|
556
|
-
this.
|
|
590
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
591
|
+
if (this.deviceLogging === 'debug') {
|
|
592
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
557
593
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
558
594
|
}
|
|
559
|
-
if (this.
|
|
560
|
-
this.
|
|
595
|
+
if (this.platform.debugMode) {
|
|
596
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
561
597
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
562
598
|
}
|
|
563
|
-
this.apiError(
|
|
599
|
+
this.apiError();
|
|
564
600
|
}
|
|
565
601
|
}
|
|
566
602
|
}
|
|
@@ -568,86 +604,77 @@ export class Curtain {
|
|
|
568
604
|
updateHomeKitCharacteristics() {
|
|
569
605
|
this.setMinMax();
|
|
570
606
|
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
571
|
-
this.
|
|
607
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
572
608
|
} else {
|
|
573
609
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
574
|
-
this.
|
|
610
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
575
611
|
}
|
|
576
612
|
if (this.PositionState === undefined) {
|
|
577
|
-
this.
|
|
613
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
578
614
|
} else {
|
|
579
|
-
this.
|
|
615
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
580
616
|
}
|
|
581
617
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
582
|
-
this.
|
|
618
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
583
619
|
} else {
|
|
584
620
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
585
|
-
this.
|
|
621
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
586
622
|
}
|
|
587
623
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
588
624
|
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
589
|
-
this.
|
|
625
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
590
626
|
} else {
|
|
591
627
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
592
|
-
this.
|
|
628
|
+
this.debugLog(`Curtain: ${this.accessory.displayName}`
|
|
593
629
|
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
594
630
|
}
|
|
595
631
|
}
|
|
596
632
|
if (this.device.ble) {
|
|
597
633
|
if (this.BatteryLevel === undefined) {
|
|
598
|
-
this.
|
|
634
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
599
635
|
} else {
|
|
600
636
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
601
|
-
this.
|
|
637
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
602
638
|
}
|
|
603
639
|
if (this.StatusLowBattery === undefined) {
|
|
604
|
-
this.
|
|
640
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
605
641
|
} else {
|
|
606
642
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
607
|
-
this.
|
|
643
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
608
644
|
}
|
|
609
645
|
}
|
|
610
646
|
}
|
|
611
647
|
|
|
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
|
-
}
|
|
648
|
+
public apiError() {
|
|
649
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
623
650
|
}
|
|
624
651
|
|
|
625
652
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
626
653
|
switch (push.data.statusCode) {
|
|
627
654
|
case 151:
|
|
628
|
-
this.
|
|
655
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
629
656
|
break;
|
|
630
657
|
case 152:
|
|
631
|
-
this.
|
|
658
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device not found.`);
|
|
632
659
|
break;
|
|
633
660
|
case 160:
|
|
634
|
-
this.
|
|
661
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Command is not supported.`);
|
|
635
662
|
break;
|
|
636
663
|
case 161:
|
|
637
|
-
this.
|
|
664
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device is offline.`);
|
|
638
665
|
break;
|
|
639
666
|
case 171:
|
|
640
|
-
this.
|
|
667
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
641
668
|
break;
|
|
642
669
|
case 190:
|
|
643
|
-
this.
|
|
670
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
644
671
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
645
672
|
break;
|
|
646
673
|
case 100:
|
|
647
|
-
this.
|
|
674
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
|
|
648
675
|
break;
|
|
649
676
|
default:
|
|
650
|
-
this.
|
|
677
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Unknown statusCode.`);
|
|
651
678
|
}
|
|
652
679
|
}
|
|
653
680
|
|
|
@@ -655,7 +682,7 @@ export class Curtain {
|
|
|
655
682
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
656
683
|
*/
|
|
657
684
|
TargetPositionSet(value: CharacteristicValue) {
|
|
658
|
-
this.
|
|
685
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
659
686
|
|
|
660
687
|
this.TargetPosition = value;
|
|
661
688
|
|
|
@@ -663,15 +690,15 @@ export class Curtain {
|
|
|
663
690
|
if (value > this.CurrentPosition) {
|
|
664
691
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
665
692
|
this.setNewTarget = true;
|
|
666
|
-
this.
|
|
693
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
667
694
|
} else if (value < this.CurrentPosition) {
|
|
668
695
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
669
696
|
this.setNewTarget = true;
|
|
670
|
-
this.
|
|
697
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
671
698
|
} else {
|
|
672
699
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
673
700
|
this.setNewTarget = false;
|
|
674
|
-
this.
|
|
701
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
675
702
|
}
|
|
676
703
|
this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
677
704
|
this.service.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
@@ -683,7 +710,7 @@ export class Curtain {
|
|
|
683
710
|
clearTimeout(this.setNewTargetTimer);
|
|
684
711
|
if (this.setNewTarget) {
|
|
685
712
|
this.setNewTargetTimer = setTimeout(() => {
|
|
686
|
-
this.
|
|
713
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
687
714
|
this.setNewTarget = false;
|
|
688
715
|
}, 10000);
|
|
689
716
|
}
|
|
@@ -702,4 +729,39 @@ export class Curtain {
|
|
|
702
729
|
}
|
|
703
730
|
}
|
|
704
731
|
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Logging for Device
|
|
735
|
+
*/
|
|
736
|
+
infoLog(...log: any[]) {
|
|
737
|
+
if (this.enablingDeviceLogging()) {
|
|
738
|
+
this.platform.log.info(String(...log));
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
warnLog(...log: any[]) {
|
|
743
|
+
if (this.enablingDeviceLogging()) {
|
|
744
|
+
this.platform.log.warn(String(...log));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
errorLog(...log: any[]) {
|
|
749
|
+
if (this.enablingDeviceLogging()) {
|
|
750
|
+
this.platform.log.error(String(...log));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
debugLog(...log: any[]) {
|
|
755
|
+
if (this.enablingDeviceLogging()) {
|
|
756
|
+
if (this.deviceLogging === 'debug') {
|
|
757
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
758
|
+
} else {
|
|
759
|
+
this.platform.log.debug(String(...log));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
enablingDeviceLogging(): boolean {
|
|
765
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
766
|
+
}
|
|
705
767
|
}
|