@switchbot/homebridge-switchbot 2.0.0-beta.18 → 2.0.0-beta.19
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 +1 -1
- package/config.schema.json +11 -2
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/device/curtain.ts
CHANGED
|
@@ -50,6 +50,7 @@ export class Curtain {
|
|
|
50
50
|
setNewTargetTimer!: NodeJS.Timeout;
|
|
51
51
|
|
|
52
52
|
// Config
|
|
53
|
+
OpenAPI?: boolean;
|
|
53
54
|
set_minStep!: number;
|
|
54
55
|
updateRate!: number;
|
|
55
56
|
set_minLux!: number;
|
|
@@ -71,6 +72,7 @@ export class Curtain {
|
|
|
71
72
|
// default placeholders
|
|
72
73
|
this.logs(device);
|
|
73
74
|
this.refreshRate(device);
|
|
75
|
+
this.openAPI();
|
|
74
76
|
this.scan(device);
|
|
75
77
|
this.config(device);
|
|
76
78
|
this.setupMqtt(device);
|
|
@@ -138,33 +140,33 @@ export class Curtain {
|
|
|
138
140
|
|
|
139
141
|
// Light Sensor Service
|
|
140
142
|
if (device.curtain?.hide_lightsensor) {
|
|
141
|
-
this.debugLog(
|
|
143
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
142
144
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
143
145
|
accessory.removeService(this.lightSensorService!);
|
|
144
146
|
} else if (!this.lightSensorService) {
|
|
145
|
-
this.debugLog(
|
|
147
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
146
148
|
(this.lightSensorService =
|
|
147
149
|
this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
|
|
148
150
|
`${accessory.displayName} Light Sensor`;
|
|
149
151
|
|
|
150
152
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
151
153
|
} else {
|
|
152
|
-
this.debugLog(
|
|
154
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
// Battery Service
|
|
156
158
|
if (!device.ble) {
|
|
157
|
-
this.debugLog(
|
|
159
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
158
160
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
159
161
|
accessory.removeService(this.batteryService!);
|
|
160
162
|
} else if (device.ble && !this.batteryService) {
|
|
161
|
-
this.debugLog(
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
162
164
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
163
165
|
`${accessory.displayName} Battery`;
|
|
164
166
|
|
|
165
167
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
166
168
|
} else {
|
|
167
|
-
this.debugLog(
|
|
169
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
// Update Homekit
|
|
@@ -184,7 +186,7 @@ export class Curtain {
|
|
|
184
186
|
if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
|
|
185
187
|
return;
|
|
186
188
|
}
|
|
187
|
-
this.debugLog(
|
|
189
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
|
|
188
190
|
await this.refreshStatus();
|
|
189
191
|
});
|
|
190
192
|
|
|
@@ -201,9 +203,10 @@ export class Curtain {
|
|
|
201
203
|
try {
|
|
202
204
|
await this.pushChanges();
|
|
203
205
|
} catch (e: any) {
|
|
204
|
-
this.errorLog(
|
|
206
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
205
207
|
if (this.deviceLogging.includes('debug')) {
|
|
206
|
-
this.errorLog(
|
|
208
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
209
|
+
+ ` Error Message: ${superStringify(e.message)}`);
|
|
207
210
|
}
|
|
208
211
|
this.apiError(e);
|
|
209
212
|
}
|
|
@@ -222,7 +225,7 @@ export class Curtain {
|
|
|
222
225
|
?.join(':');
|
|
223
226
|
const options = this.device.mqttPubOptions || {};
|
|
224
227
|
this.mqttClient?.publish(`homebridge-switchbot/curtain/${mac}/${topic}`, `${message}`, options);
|
|
225
|
-
this.debugLog(
|
|
228
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${superStringify(options)}`);
|
|
226
229
|
}
|
|
227
230
|
|
|
228
231
|
/*
|
|
@@ -232,13 +235,13 @@ export class Curtain {
|
|
|
232
235
|
if (device.mqttURL) {
|
|
233
236
|
try {
|
|
234
237
|
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
235
|
-
this.debugLog(
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
236
239
|
this.mqttClient.on('error', (e: Error) => {
|
|
237
|
-
this.errorLog(
|
|
240
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
238
241
|
});
|
|
239
242
|
} catch (e) {
|
|
240
243
|
this.mqttClient = null;
|
|
241
|
-
this.errorLog(
|
|
244
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
}
|
|
@@ -255,41 +258,41 @@ export class Curtain {
|
|
|
255
258
|
}
|
|
256
259
|
|
|
257
260
|
async BLEparseStatus(): Promise<void> {
|
|
258
|
-
this.debugLog(
|
|
261
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
259
262
|
// CurrentPosition
|
|
260
263
|
this.CurrentPosition = 100 - Number(this.position);
|
|
261
264
|
await this.setMinMax();
|
|
262
|
-
this.debugLog(
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
263
266
|
if (this.setNewTarget) {
|
|
264
|
-
this.infoLog(
|
|
267
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
if (this.setNewTarget) {
|
|
268
271
|
await this.setMinMax();
|
|
269
272
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
270
|
-
this.debugLog(
|
|
273
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
271
274
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
272
275
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
273
|
-
this.debugLog(
|
|
276
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
274
277
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
275
|
-
this.debugLog(
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
276
279
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
277
280
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
278
|
-
this.debugLog(
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
279
282
|
} else {
|
|
280
|
-
this.debugLog(
|
|
283
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
281
284
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
282
285
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
283
|
-
this.debugLog(
|
|
286
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
284
287
|
}
|
|
285
288
|
} else {
|
|
286
|
-
this.debugLog(
|
|
289
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
287
290
|
this.TargetPosition = this.CurrentPosition;
|
|
288
291
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
289
|
-
this.debugLog(
|
|
292
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
290
293
|
}
|
|
291
294
|
this.debugLog(
|
|
292
|
-
|
|
295
|
+
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
293
296
|
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
294
297
|
);
|
|
295
298
|
|
|
@@ -302,42 +305,42 @@ export class Curtain {
|
|
|
302
305
|
switch (this.lightLevel) {
|
|
303
306
|
case 1:
|
|
304
307
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
305
|
-
this.debugLog(
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
306
309
|
break;
|
|
307
310
|
case 2:
|
|
308
311
|
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
309
312
|
this.debugLog(
|
|
310
|
-
|
|
313
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
311
314
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
312
315
|
);
|
|
313
316
|
break;
|
|
314
317
|
case 3:
|
|
315
318
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
316
|
-
this.debugLog(
|
|
319
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
317
320
|
break;
|
|
318
321
|
case 4:
|
|
319
322
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
320
|
-
this.debugLog(
|
|
323
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
321
324
|
break;
|
|
322
325
|
case 5:
|
|
323
326
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
324
|
-
this.debugLog(
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
325
328
|
break;
|
|
326
329
|
case 6:
|
|
327
330
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
328
|
-
this.debugLog(
|
|
331
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
329
332
|
break;
|
|
330
333
|
case 7:
|
|
331
334
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
332
|
-
this.debugLog(
|
|
335
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
333
336
|
break;
|
|
334
337
|
case 8:
|
|
335
338
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
336
|
-
this.debugLog(
|
|
339
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
337
340
|
break;
|
|
338
341
|
case 9:
|
|
339
342
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
340
|
-
this.debugLog(
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
341
344
|
break;
|
|
342
345
|
case 10:
|
|
343
346
|
default:
|
|
@@ -345,7 +348,8 @@ export class Curtain {
|
|
|
345
348
|
this.debugLog();
|
|
346
349
|
}
|
|
347
350
|
this.debugLog(
|
|
348
|
-
|
|
351
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
352
|
+
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
349
353
|
);
|
|
350
354
|
}
|
|
351
355
|
// Battery
|
|
@@ -355,7 +359,8 @@ export class Curtain {
|
|
|
355
359
|
} else {
|
|
356
360
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
357
361
|
}
|
|
358
|
-
this.debugLog(
|
|
362
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
363
|
+
+` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
359
364
|
}
|
|
360
365
|
|
|
361
366
|
async openAPIparseStatus(): Promise<void> {
|
|
@@ -363,41 +368,41 @@ export class Curtain {
|
|
|
363
368
|
this.SwitchToOpenAPI = false;
|
|
364
369
|
}
|
|
365
370
|
if (this.platform.config.credentials?.token) {
|
|
366
|
-
this.debugLog(
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
367
372
|
// CurrentPosition
|
|
368
373
|
this.CurrentPosition = 100 - Number(this.slidePosition);
|
|
369
374
|
await this.setMinMax();
|
|
370
375
|
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
371
376
|
if (this.setNewTarget) {
|
|
372
|
-
this.infoLog(
|
|
377
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
373
378
|
}
|
|
374
379
|
|
|
375
380
|
if (this.setNewTarget && this.moving) {
|
|
376
381
|
await this.setMinMax();
|
|
377
382
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
378
|
-
this.debugLog(
|
|
383
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
379
384
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
380
385
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
381
|
-
this.debugLog(
|
|
386
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
382
387
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
383
|
-
this.debugLog(
|
|
388
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
384
389
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
385
390
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
386
|
-
this.debugLog(
|
|
391
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
387
392
|
} else {
|
|
388
|
-
this.debugLog(
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
389
394
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
390
395
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
391
|
-
this.debugLog(
|
|
396
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
392
397
|
}
|
|
393
398
|
} else {
|
|
394
|
-
this.debugLog(
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
395
400
|
this.TargetPosition = this.CurrentPosition;
|
|
396
401
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
397
|
-
this.debugLog(
|
|
402
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
398
403
|
}
|
|
399
404
|
this.debugLog(
|
|
400
|
-
|
|
405
|
+
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
401
406
|
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
402
407
|
);
|
|
403
408
|
|
|
@@ -413,7 +418,7 @@ export class Curtain {
|
|
|
413
418
|
default:
|
|
414
419
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
415
420
|
}
|
|
416
|
-
this.debugLog(
|
|
421
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
417
422
|
}
|
|
418
423
|
}
|
|
419
424
|
}
|
|
@@ -427,14 +432,14 @@ export class Curtain {
|
|
|
427
432
|
}
|
|
428
433
|
|
|
429
434
|
async BLERefreshStatus(): Promise<void> {
|
|
430
|
-
this.debugLog(
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
431
436
|
const switchbot = await this.platform.connectBLE();
|
|
432
437
|
// Convert to BLE Address
|
|
433
438
|
this.device.bleMac = this.device
|
|
434
439
|
.deviceId!.match(/.{1,2}/g)!
|
|
435
440
|
.join(':')
|
|
436
441
|
.toLowerCase();
|
|
437
|
-
this.debugLog(
|
|
442
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
438
443
|
this.getCustomBLEAddress(switchbot);
|
|
439
444
|
// Start to monitor advertisement packets
|
|
440
445
|
if (switchbot !== false) {
|
|
@@ -450,26 +455,26 @@ export class Curtain {
|
|
|
450
455
|
if (this.deviceLogging.includes('debug')) {
|
|
451
456
|
this.infoLog(this.address);
|
|
452
457
|
this.infoLog(this.device.bleMac);
|
|
453
|
-
this.infoLog(
|
|
454
|
-
this.infoLog(
|
|
458
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
459
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
455
460
|
}
|
|
456
461
|
this.serviceData = ad.serviceData;
|
|
457
462
|
this.calibration = ad.serviceData.calibration;
|
|
458
463
|
this.battery = ad.serviceData.battery;
|
|
459
464
|
this.position = ad.serviceData.position;
|
|
460
465
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
461
|
-
this.debugLog(
|
|
466
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
462
467
|
this.debugLog(
|
|
463
|
-
|
|
468
|
+
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
464
469
|
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
465
470
|
);
|
|
466
471
|
|
|
467
472
|
if (this.serviceData) {
|
|
468
473
|
this.connected = true;
|
|
469
|
-
this.debugLog(
|
|
474
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
470
475
|
} else {
|
|
471
476
|
this.connected = false;
|
|
472
|
-
this.debugLog(
|
|
477
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
473
478
|
}
|
|
474
479
|
};
|
|
475
480
|
// Wait 2 seconds
|
|
@@ -482,23 +487,24 @@ export class Curtain {
|
|
|
482
487
|
this.parseStatus();
|
|
483
488
|
this.updateHomeKitCharacteristics();
|
|
484
489
|
} else {
|
|
485
|
-
this.errorLog(
|
|
490
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
486
491
|
if (this.platform.config.credentials?.token) {
|
|
487
|
-
this.warnLog(
|
|
492
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
488
493
|
this.SwitchToOpenAPI = true;
|
|
489
494
|
await this.openAPIRefreshStatus();
|
|
490
495
|
}
|
|
491
496
|
}
|
|
492
497
|
})
|
|
493
498
|
.catch(async (e: any) => {
|
|
494
|
-
this.errorLog(
|
|
499
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
495
500
|
if (this.deviceLogging.includes('debug')) {
|
|
496
501
|
this.errorLog(
|
|
497
|
-
|
|
502
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
503
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
498
504
|
);
|
|
499
505
|
}
|
|
500
506
|
if (this.platform.config.credentials?.token) {
|
|
501
|
-
this.warnLog(
|
|
507
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
502
508
|
this.SwitchToOpenAPI = true;
|
|
503
509
|
await this.openAPIRefreshStatus();
|
|
504
510
|
}
|
|
@@ -518,7 +524,7 @@ export class Curtain {
|
|
|
518
524
|
});
|
|
519
525
|
// Set an event handler
|
|
520
526
|
switchbot.onadvertisement = (ad: any) => {
|
|
521
|
-
this.warnLog(
|
|
527
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
522
528
|
};
|
|
523
529
|
await switchbot.wait(10000);
|
|
524
530
|
// Stop to monitor
|
|
@@ -528,24 +534,24 @@ export class Curtain {
|
|
|
528
534
|
}
|
|
529
535
|
|
|
530
536
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
531
|
-
this.errorLog(
|
|
537
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
532
538
|
if (this.platform.config.credentials?.token) {
|
|
533
|
-
this.warnLog(
|
|
539
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
534
540
|
this.SwitchToOpenAPI = true;
|
|
535
541
|
await this.openAPIRefreshStatus();
|
|
536
542
|
}
|
|
537
543
|
}
|
|
538
544
|
|
|
539
545
|
async openAPIRefreshStatus(): Promise<void> {
|
|
540
|
-
if (this.platform.config.credentials?.token) {
|
|
541
|
-
this.debugLog(
|
|
546
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
547
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
542
548
|
try {
|
|
543
549
|
const t = Date.now();
|
|
544
550
|
const nonce = 'requestID';
|
|
545
551
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
546
552
|
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
547
553
|
const sign = signTerm.toString('base64');
|
|
548
|
-
this.debugLog(
|
|
554
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
549
555
|
const options = {
|
|
550
556
|
hostname: HostDomain,
|
|
551
557
|
port: 443,
|
|
@@ -560,40 +566,43 @@ export class Curtain {
|
|
|
560
566
|
},
|
|
561
567
|
};
|
|
562
568
|
const req = https.request(options, (res) => {
|
|
563
|
-
this.debugLog(
|
|
569
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
564
570
|
let rawData = '';
|
|
565
571
|
res.on('data', (d) => {
|
|
566
572
|
rawData += d;
|
|
567
|
-
this.debugLog(
|
|
573
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
568
574
|
});
|
|
569
575
|
|
|
570
576
|
res.on('end', () => {
|
|
571
577
|
try {
|
|
572
578
|
this.deviceStatus = JSON.parse(rawData);
|
|
573
|
-
this.debugLog(
|
|
579
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
574
580
|
this.slidePosition = this.deviceStatus.body.slidePosition;
|
|
575
581
|
this.moving = this.deviceStatus.body.moving;
|
|
576
582
|
this.brightness = this.deviceStatus.body.brightness;
|
|
577
583
|
this.parseStatus();
|
|
578
584
|
this.updateHomeKitCharacteristics();
|
|
579
585
|
} catch (e: any) {
|
|
580
|
-
this.errorLog(
|
|
586
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
581
587
|
}
|
|
582
588
|
});
|
|
583
589
|
});
|
|
584
590
|
req.on('error', (e: any) => {
|
|
585
|
-
this.errorLog(
|
|
591
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
586
592
|
});
|
|
587
593
|
req.end();
|
|
588
594
|
} catch (e: any) {
|
|
589
|
-
this.errorLog(
|
|
595
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
590
596
|
if (this.deviceLogging.includes('debug')) {
|
|
591
597
|
this.errorLog(
|
|
592
|
-
|
|
598
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
599
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
593
600
|
);
|
|
594
601
|
}
|
|
595
602
|
this.apiError(e);
|
|
596
603
|
}
|
|
604
|
+
} else {
|
|
605
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
597
606
|
}
|
|
598
607
|
}
|
|
599
608
|
|
|
@@ -612,14 +621,14 @@ export class Curtain {
|
|
|
612
621
|
|
|
613
622
|
async BLEpushChanges(): Promise<void> {
|
|
614
623
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
615
|
-
this.debugLog(
|
|
624
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges`);
|
|
616
625
|
const switchbot = await this.platform.connectBLE();
|
|
617
626
|
// Convert to BLE Address
|
|
618
627
|
this.device.bleMac = this.device
|
|
619
628
|
.deviceId!.match(/.{1,2}/g)!
|
|
620
629
|
.join(':')
|
|
621
630
|
.toLowerCase();
|
|
622
|
-
this.debugLog(
|
|
631
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
623
632
|
if (this.TargetPosition > 50) {
|
|
624
633
|
if (this.device.curtain?.setOpenMode === '1') {
|
|
625
634
|
this.setPositionMode = 1;
|
|
@@ -650,40 +659,41 @@ export class Curtain {
|
|
|
650
659
|
return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
|
|
651
660
|
})
|
|
652
661
|
.then(() => {
|
|
653
|
-
this.debugLog(
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
654
663
|
})
|
|
655
664
|
.catch(async (e: any) => {
|
|
656
|
-
this.errorLog(
|
|
665
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
657
666
|
if (this.deviceLogging.includes('debug')) {
|
|
658
667
|
this.errorLog(
|
|
659
|
-
|
|
668
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
669
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
660
670
|
);
|
|
661
671
|
}
|
|
662
672
|
if (this.platform.config.credentials?.token) {
|
|
663
|
-
this.warnLog(
|
|
673
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
664
674
|
await this.openAPIpushChanges();
|
|
665
675
|
}
|
|
666
676
|
this.apiError(e);
|
|
667
677
|
});
|
|
668
678
|
} else {
|
|
669
|
-
this.errorLog(
|
|
679
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
670
680
|
if (this.platform.config.credentials?.token) {
|
|
671
|
-
this.warnLog(
|
|
681
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
672
682
|
await this.openAPIpushChanges();
|
|
673
683
|
}
|
|
674
684
|
}
|
|
675
685
|
} else {
|
|
676
686
|
this.debugLog(
|
|
677
|
-
|
|
687
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
678
688
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
679
689
|
);
|
|
680
690
|
}
|
|
681
691
|
}
|
|
682
692
|
|
|
683
693
|
async openAPIpushChanges(): Promise<void> {
|
|
684
|
-
if (this.platform.config.credentials?.token) {
|
|
694
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
685
695
|
try {
|
|
686
|
-
this.debugLog(
|
|
696
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
687
697
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
688
698
|
// Make Push On request to the API
|
|
689
699
|
const t = Date.now();
|
|
@@ -693,7 +703,7 @@ export class Curtain {
|
|
|
693
703
|
.update(Buffer.from(data, 'utf-8'))
|
|
694
704
|
.digest();
|
|
695
705
|
const sign = signTerm.toString('base64');
|
|
696
|
-
this.debugLog(
|
|
706
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
697
707
|
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
698
708
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
699
709
|
if (this.TargetPosition > 50) {
|
|
@@ -715,7 +725,7 @@ export class Curtain {
|
|
|
715
725
|
'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
716
726
|
'commandType': 'command',
|
|
717
727
|
});
|
|
718
|
-
this.infoLog(
|
|
728
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
719
729
|
const options = {
|
|
720
730
|
hostname: HostDomain,
|
|
721
731
|
port: 443,
|
|
@@ -731,81 +741,85 @@ export class Curtain {
|
|
|
731
741
|
},
|
|
732
742
|
};
|
|
733
743
|
const req = https.request(options, res => {
|
|
734
|
-
this.debugLog(
|
|
744
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
735
745
|
this.statusCode({ res });
|
|
736
746
|
res.on('data', d => {
|
|
737
|
-
this.debugLog(
|
|
747
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
738
748
|
});
|
|
739
749
|
});
|
|
740
750
|
req.on('error', (e: any) => {
|
|
741
|
-
this.errorLog(
|
|
751
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
742
752
|
});
|
|
743
753
|
req.write(body);
|
|
744
754
|
req.end();
|
|
745
|
-
this.debugLog(
|
|
755
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
746
756
|
} else {
|
|
747
757
|
this.debugLog(
|
|
748
|
-
|
|
758
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
749
759
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
750
760
|
);
|
|
751
761
|
}
|
|
752
762
|
} catch (e: any) {
|
|
753
|
-
this.errorLog(
|
|
763
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
754
764
|
if (this.deviceLogging.includes('debug')) {
|
|
755
765
|
this.errorLog(
|
|
756
|
-
|
|
766
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
767
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
757
768
|
);
|
|
758
769
|
}
|
|
759
770
|
this.apiError(e);
|
|
760
771
|
}
|
|
772
|
+
} else {
|
|
773
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
761
774
|
}
|
|
762
775
|
}
|
|
763
776
|
|
|
764
777
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
765
778
|
await this.setMinMax();
|
|
766
779
|
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
767
|
-
this.debugLog(
|
|
780
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
768
781
|
} else {
|
|
769
782
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
770
|
-
this.debugLog(
|
|
783
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
771
784
|
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
772
785
|
}
|
|
773
786
|
if (this.PositionState === undefined) {
|
|
774
|
-
this.debugLog(
|
|
787
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
775
788
|
} else {
|
|
776
789
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, Number(this.PositionState));
|
|
777
|
-
this.debugLog(
|
|
790
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
778
791
|
this.mqttPublish('PositionState', this.PositionState);
|
|
779
792
|
}
|
|
780
793
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
781
|
-
this.debugLog(
|
|
794
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
782
795
|
} else {
|
|
783
796
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
784
|
-
this.debugLog(
|
|
797
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
785
798
|
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
786
799
|
}
|
|
787
800
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
788
801
|
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
789
|
-
this.debugLog(
|
|
802
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
790
803
|
} else {
|
|
791
804
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
792
|
-
this.debugLog(
|
|
805
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
806
|
+
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
793
807
|
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
794
808
|
}
|
|
795
809
|
}
|
|
796
810
|
if (this.device.ble) {
|
|
797
811
|
if (this.BatteryLevel === undefined) {
|
|
798
|
-
this.debugLog(
|
|
812
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
799
813
|
} else {
|
|
800
814
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
801
|
-
this.debugLog(
|
|
815
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
802
816
|
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
803
817
|
}
|
|
804
818
|
if (this.StatusLowBattery === undefined) {
|
|
805
|
-
this.debugLog(
|
|
819
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
806
820
|
} else {
|
|
807
821
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
808
|
-
this.debugLog(
|
|
822
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
809
823
|
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
810
824
|
}
|
|
811
825
|
}
|
|
@@ -828,31 +842,31 @@ export class Curtain {
|
|
|
828
842
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
829
843
|
switch (res.statusCode) {
|
|
830
844
|
case 151:
|
|
831
|
-
this.errorLog(
|
|
845
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
832
846
|
break;
|
|
833
847
|
case 152:
|
|
834
|
-
this.errorLog(
|
|
848
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
835
849
|
break;
|
|
836
850
|
case 160:
|
|
837
|
-
this.errorLog(
|
|
851
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
838
852
|
break;
|
|
839
853
|
case 161:
|
|
840
|
-
this.errorLog(
|
|
854
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
841
855
|
break;
|
|
842
856
|
case 171:
|
|
843
|
-
this.errorLog(
|
|
857
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
844
858
|
break;
|
|
845
859
|
case 190:
|
|
846
860
|
this.errorLog(
|
|
847
|
-
|
|
861
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
848
862
|
` Or command: ${superStringify(res)} format is invalid`,
|
|
849
863
|
);
|
|
850
864
|
break;
|
|
851
865
|
case 100:
|
|
852
|
-
this.debugLog(
|
|
866
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
853
867
|
break;
|
|
854
868
|
default:
|
|
855
|
-
this.debugLog(
|
|
869
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
856
870
|
}
|
|
857
871
|
}
|
|
858
872
|
|
|
@@ -860,7 +874,7 @@ export class Curtain {
|
|
|
860
874
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
861
875
|
*/
|
|
862
876
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
863
|
-
this.debugLog(
|
|
877
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
864
878
|
|
|
865
879
|
this.TargetPosition = value;
|
|
866
880
|
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
@@ -869,15 +883,15 @@ export class Curtain {
|
|
|
869
883
|
if (value > this.CurrentPosition) {
|
|
870
884
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
871
885
|
this.setNewTarget = true;
|
|
872
|
-
this.debugLog(
|
|
886
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
873
887
|
} else if (value < this.CurrentPosition) {
|
|
874
888
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
875
889
|
this.setNewTarget = true;
|
|
876
|
-
this.debugLog(
|
|
890
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
877
891
|
} else {
|
|
878
892
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
879
893
|
this.setNewTarget = false;
|
|
880
|
-
this.debugLog(
|
|
894
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
881
895
|
}
|
|
882
896
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
883
897
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
@@ -887,10 +901,10 @@ export class Curtain {
|
|
|
887
901
|
* The minimum time depends on the network control latency.
|
|
888
902
|
*/
|
|
889
903
|
clearTimeout(this.setNewTargetTimer);
|
|
890
|
-
this.debugLog(
|
|
904
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.updateRate}`);
|
|
891
905
|
if (this.setNewTarget) {
|
|
892
906
|
this.setNewTargetTimer = setTimeout(() => {
|
|
893
|
-
this.debugLog(
|
|
907
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
894
908
|
this.setNewTarget = false;
|
|
895
909
|
}, this.updateRate * 1000);
|
|
896
910
|
}
|
|
@@ -918,6 +932,9 @@ export class Curtain {
|
|
|
918
932
|
if (device.ble) {
|
|
919
933
|
config['ble'] = device.ble;
|
|
920
934
|
}
|
|
935
|
+
if (device.openAPI !== undefined) {
|
|
936
|
+
config['openAPI'] = device.openAPI;
|
|
937
|
+
}
|
|
921
938
|
if (device.logging !== undefined) {
|
|
922
939
|
config['logging'] = device.logging;
|
|
923
940
|
}
|
|
@@ -928,7 +945,7 @@ export class Curtain {
|
|
|
928
945
|
config['scanDuration'] = device.scanDuration;
|
|
929
946
|
}
|
|
930
947
|
if (Object.entries(config).length !== 0) {
|
|
931
|
-
this.infoLog(
|
|
948
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
932
949
|
}
|
|
933
950
|
}
|
|
934
951
|
|
|
@@ -936,41 +953,52 @@ export class Curtain {
|
|
|
936
953
|
// refreshRate
|
|
937
954
|
if (device.refreshRate) {
|
|
938
955
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
939
|
-
this.debugLog(
|
|
956
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
940
957
|
} else if (this.platform.config.options!.refreshRate) {
|
|
941
958
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
942
|
-
this.debugLog(
|
|
959
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
943
960
|
}
|
|
944
961
|
// updateRate
|
|
945
962
|
if (device?.curtain?.updateRate) {
|
|
946
963
|
this.updateRate = device?.curtain?.updateRate;
|
|
947
|
-
this.debugLog(
|
|
964
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
|
|
948
965
|
} else {
|
|
949
966
|
this.updateRate = 7;
|
|
950
|
-
this.debugLog(
|
|
967
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
async openAPI() {
|
|
972
|
+
if (!this.device.openAPI) {
|
|
973
|
+
this.OpenAPI = true;
|
|
974
|
+
} else {
|
|
975
|
+
this.OpenAPI = this.device.openAPI;
|
|
951
976
|
}
|
|
977
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
952
978
|
}
|
|
953
979
|
|
|
954
980
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
955
981
|
if (device.scanDuration) {
|
|
956
982
|
if (this.updateRate > device.scanDuration) {
|
|
957
983
|
this.scanDuration = this.updateRate;
|
|
958
|
-
this.warnLog(
|
|
984
|
+
this.warnLog(`${this.device.deviceType}: `
|
|
985
|
+
+ `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
959
986
|
} else {
|
|
960
987
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
961
988
|
}
|
|
962
989
|
if (device.ble) {
|
|
963
|
-
this.debugLog(
|
|
990
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
964
991
|
}
|
|
965
992
|
} else {
|
|
966
993
|
if (this.updateRate > 1) {
|
|
967
994
|
this.scanDuration = this.updateRate;
|
|
968
|
-
this.warnLog(
|
|
995
|
+
this.warnLog(`${this.device.deviceType}: `
|
|
996
|
+
+ `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
969
997
|
} else {
|
|
970
998
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
971
999
|
}
|
|
972
1000
|
if (this.device.ble) {
|
|
973
|
-
this.debugLog(
|
|
1001
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
974
1002
|
}
|
|
975
1003
|
}
|
|
976
1004
|
}
|
|
@@ -978,24 +1006,25 @@ export class Curtain {
|
|
|
978
1006
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
979
1007
|
if (this.platform.debugMode) {
|
|
980
1008
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
981
|
-
this.debugLog(
|
|
1009
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
982
1010
|
} else if (device.logging) {
|
|
983
1011
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
984
|
-
this.debugLog(
|
|
1012
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
985
1013
|
} else if (this.platform.config.options?.logging) {
|
|
986
1014
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
987
|
-
this.debugLog(
|
|
1015
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
988
1016
|
} else {
|
|
989
1017
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
990
|
-
this.debugLog(
|
|
1018
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
991
1019
|
}
|
|
992
1020
|
}
|
|
993
1021
|
|
|
994
1022
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
995
1023
|
let FirmwareRevision: string;
|
|
996
|
-
this.debugLog(
|
|
997
|
-
|
|
998
|
-
this.debugLog(
|
|
1024
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
1025
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
1026
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1027
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
999
1028
|
if (accessory.context.FirmwareRevision) {
|
|
1000
1029
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1001
1030
|
} else if (device.firmware) {
|