@switchbot/homebridge-switchbot 2.0.0-beta.17 → 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 +14 -4
- 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/dist/device/curtain.js
CHANGED
|
@@ -21,6 +21,7 @@ class Curtain {
|
|
|
21
21
|
// default placeholders
|
|
22
22
|
this.logs(device);
|
|
23
23
|
this.refreshRate(device);
|
|
24
|
+
this.openAPI();
|
|
24
25
|
this.scan(device);
|
|
25
26
|
this.config(device);
|
|
26
27
|
this.setupMqtt(device);
|
|
@@ -77,34 +78,34 @@ class Curtain {
|
|
|
77
78
|
.onSet(this.TargetPositionSet.bind(this));
|
|
78
79
|
// Light Sensor Service
|
|
79
80
|
if (device.curtain?.hide_lightsensor) {
|
|
80
|
-
this.debugLog(
|
|
81
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
81
82
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
82
83
|
accessory.removeService(this.lightSensorService);
|
|
83
84
|
}
|
|
84
85
|
else if (!this.lightSensorService) {
|
|
85
|
-
this.debugLog(
|
|
86
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
86
87
|
(this.lightSensorService =
|
|
87
88
|
this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
|
|
88
89
|
`${accessory.displayName} Light Sensor`;
|
|
89
90
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
90
91
|
}
|
|
91
92
|
else {
|
|
92
|
-
this.debugLog(
|
|
93
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
93
94
|
}
|
|
94
95
|
// Battery Service
|
|
95
96
|
if (!device.ble) {
|
|
96
|
-
this.debugLog(
|
|
97
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
97
98
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
98
99
|
accessory.removeService(this.batteryService);
|
|
99
100
|
}
|
|
100
101
|
else if (device.ble && !this.batteryService) {
|
|
101
|
-
this.debugLog(
|
|
102
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
102
103
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
103
104
|
`${accessory.displayName} Battery`;
|
|
104
105
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
105
106
|
}
|
|
106
107
|
else {
|
|
107
|
-
this.debugLog(
|
|
108
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
108
109
|
}
|
|
109
110
|
// Update Homekit
|
|
110
111
|
this.updateHomeKitCharacteristics();
|
|
@@ -121,7 +122,7 @@ class Curtain {
|
|
|
121
122
|
if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
|
-
this.debugLog(
|
|
125
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
|
|
125
126
|
await this.refreshStatus();
|
|
126
127
|
});
|
|
127
128
|
// Watch for Curtain change events
|
|
@@ -135,9 +136,10 @@ class Curtain {
|
|
|
135
136
|
await this.pushChanges();
|
|
136
137
|
}
|
|
137
138
|
catch (e) {
|
|
138
|
-
this.errorLog(
|
|
139
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
139
140
|
if (this.deviceLogging.includes('debug')) {
|
|
140
|
-
this.errorLog(
|
|
141
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
142
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
141
143
|
}
|
|
142
144
|
this.apiError(e);
|
|
143
145
|
}
|
|
@@ -155,7 +157,7 @@ class Curtain {
|
|
|
155
157
|
?.join(':');
|
|
156
158
|
const options = this.device.mqttPubOptions || {};
|
|
157
159
|
this.mqttClient?.publish(`homebridge-switchbot/curtain/${mac}/${topic}`, `${message}`, options);
|
|
158
|
-
this.debugLog(
|
|
160
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${(0, super_stringify_1.default)(options)}`);
|
|
159
161
|
}
|
|
160
162
|
/*
|
|
161
163
|
* Setup MQTT hadler if URL is specifed.
|
|
@@ -164,14 +166,14 @@ class Curtain {
|
|
|
164
166
|
if (device.mqttURL) {
|
|
165
167
|
try {
|
|
166
168
|
this.mqttClient = await (0, async_mqtt_1.connectAsync)(device.mqttURL, device.mqttOptions || {});
|
|
167
|
-
this.debugLog(
|
|
169
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
168
170
|
this.mqttClient.on('error', (e) => {
|
|
169
|
-
this.errorLog(
|
|
171
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
174
|
catch (e) {
|
|
173
175
|
this.mqttClient = null;
|
|
174
|
-
this.errorLog(
|
|
176
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
}
|
|
@@ -187,42 +189,42 @@ class Curtain {
|
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
async BLEparseStatus() {
|
|
190
|
-
this.debugLog(
|
|
192
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
191
193
|
// CurrentPosition
|
|
192
194
|
this.CurrentPosition = 100 - Number(this.position);
|
|
193
195
|
await this.setMinMax();
|
|
194
|
-
this.debugLog(
|
|
196
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
195
197
|
if (this.setNewTarget) {
|
|
196
|
-
this.infoLog(
|
|
198
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
197
199
|
}
|
|
198
200
|
if (this.setNewTarget) {
|
|
199
201
|
await this.setMinMax();
|
|
200
202
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
201
|
-
this.debugLog(
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
202
204
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
203
205
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
204
|
-
this.debugLog(
|
|
206
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
205
207
|
}
|
|
206
208
|
else if (this.TargetPosition < this.CurrentPosition) {
|
|
207
|
-
this.debugLog(
|
|
209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
208
210
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
209
211
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
210
|
-
this.debugLog(
|
|
212
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
211
213
|
}
|
|
212
214
|
else {
|
|
213
|
-
this.debugLog(
|
|
215
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
214
216
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
215
217
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
216
|
-
this.debugLog(
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
else {
|
|
220
|
-
this.debugLog(
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
221
223
|
this.TargetPosition = this.CurrentPosition;
|
|
222
224
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
223
|
-
this.debugLog(
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
224
226
|
}
|
|
225
|
-
this.debugLog(
|
|
227
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
226
228
|
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
227
229
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
228
230
|
this.set_minLux = this.minLux();
|
|
@@ -232,47 +234,48 @@ class Curtain {
|
|
|
232
234
|
switch (this.lightLevel) {
|
|
233
235
|
case 1:
|
|
234
236
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
235
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
236
238
|
break;
|
|
237
239
|
case 2:
|
|
238
240
|
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
239
|
-
this.debugLog(
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
240
242
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`);
|
|
241
243
|
break;
|
|
242
244
|
case 3:
|
|
243
245
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
244
|
-
this.debugLog(
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
245
247
|
break;
|
|
246
248
|
case 4:
|
|
247
249
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
248
|
-
this.debugLog(
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
249
251
|
break;
|
|
250
252
|
case 5:
|
|
251
253
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
252
|
-
this.debugLog(
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
253
255
|
break;
|
|
254
256
|
case 6:
|
|
255
257
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
256
|
-
this.debugLog(
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
257
259
|
break;
|
|
258
260
|
case 7:
|
|
259
261
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
260
|
-
this.debugLog(
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
261
263
|
break;
|
|
262
264
|
case 8:
|
|
263
265
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
264
|
-
this.debugLog(
|
|
266
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
265
267
|
break;
|
|
266
268
|
case 9:
|
|
267
269
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
268
|
-
this.debugLog(
|
|
270
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
269
271
|
break;
|
|
270
272
|
case 10:
|
|
271
273
|
default:
|
|
272
274
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
273
275
|
this.debugLog();
|
|
274
276
|
}
|
|
275
|
-
this.debugLog(
|
|
277
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
278
|
+
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
276
279
|
}
|
|
277
280
|
// Battery
|
|
278
281
|
this.BatteryLevel = Number(this.battery);
|
|
@@ -282,49 +285,50 @@ class Curtain {
|
|
|
282
285
|
else {
|
|
283
286
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
284
287
|
}
|
|
285
|
-
this.debugLog(
|
|
288
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
289
|
+
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
286
290
|
}
|
|
287
291
|
async openAPIparseStatus() {
|
|
288
292
|
if (this.device.ble) {
|
|
289
293
|
this.SwitchToOpenAPI = false;
|
|
290
294
|
}
|
|
291
295
|
if (this.platform.config.credentials?.token) {
|
|
292
|
-
this.debugLog(
|
|
296
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
293
297
|
// CurrentPosition
|
|
294
298
|
this.CurrentPosition = 100 - Number(this.slidePosition);
|
|
295
299
|
await this.setMinMax();
|
|
296
300
|
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
297
301
|
if (this.setNewTarget) {
|
|
298
|
-
this.infoLog(
|
|
302
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
299
303
|
}
|
|
300
304
|
if (this.setNewTarget && this.moving) {
|
|
301
305
|
await this.setMinMax();
|
|
302
306
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
303
|
-
this.debugLog(
|
|
307
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
304
308
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
305
309
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
306
|
-
this.debugLog(
|
|
310
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
307
311
|
}
|
|
308
312
|
else if (this.TargetPosition < this.CurrentPosition) {
|
|
309
|
-
this.debugLog(
|
|
313
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
310
314
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
311
315
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
312
|
-
this.debugLog(
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
313
317
|
}
|
|
314
318
|
else {
|
|
315
|
-
this.debugLog(
|
|
319
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
316
320
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
317
321
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
318
|
-
this.debugLog(
|
|
322
|
+
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
319
323
|
}
|
|
320
324
|
}
|
|
321
325
|
else {
|
|
322
|
-
this.debugLog(
|
|
326
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
323
327
|
this.TargetPosition = this.CurrentPosition;
|
|
324
328
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
325
|
-
this.debugLog(
|
|
329
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
326
330
|
}
|
|
327
|
-
this.debugLog(
|
|
331
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
328
332
|
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
329
333
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
330
334
|
this.set_minLux = this.minLux();
|
|
@@ -338,7 +342,7 @@ class Curtain {
|
|
|
338
342
|
default:
|
|
339
343
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
340
344
|
}
|
|
341
|
-
this.debugLog(
|
|
345
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
}
|
|
@@ -351,14 +355,14 @@ class Curtain {
|
|
|
351
355
|
}
|
|
352
356
|
}
|
|
353
357
|
async BLERefreshStatus() {
|
|
354
|
-
this.debugLog(
|
|
358
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
355
359
|
const switchbot = await this.platform.connectBLE();
|
|
356
360
|
// Convert to BLE Address
|
|
357
361
|
this.device.bleMac = this.device
|
|
358
362
|
.deviceId.match(/.{1,2}/g)
|
|
359
363
|
.join(':')
|
|
360
364
|
.toLowerCase();
|
|
361
|
-
this.debugLog(
|
|
365
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
362
366
|
this.getCustomBLEAddress(switchbot);
|
|
363
367
|
// Start to monitor advertisement packets
|
|
364
368
|
if (switchbot !== false) {
|
|
@@ -374,24 +378,24 @@ class Curtain {
|
|
|
374
378
|
if (this.deviceLogging.includes('debug')) {
|
|
375
379
|
this.infoLog(this.address);
|
|
376
380
|
this.infoLog(this.device.bleMac);
|
|
377
|
-
this.infoLog(
|
|
378
|
-
this.infoLog(
|
|
381
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
382
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
379
383
|
}
|
|
380
384
|
this.serviceData = ad.serviceData;
|
|
381
385
|
this.calibration = ad.serviceData.calibration;
|
|
382
386
|
this.battery = ad.serviceData.battery;
|
|
383
387
|
this.position = ad.serviceData.position;
|
|
384
388
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
385
|
-
this.debugLog(
|
|
386
|
-
this.debugLog(
|
|
389
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
390
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
387
391
|
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
388
392
|
if (this.serviceData) {
|
|
389
393
|
this.connected = true;
|
|
390
|
-
this.debugLog(
|
|
394
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
391
395
|
}
|
|
392
396
|
else {
|
|
393
397
|
this.connected = false;
|
|
394
|
-
this.debugLog(
|
|
398
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
395
399
|
}
|
|
396
400
|
};
|
|
397
401
|
// Wait 2 seconds
|
|
@@ -405,21 +409,22 @@ class Curtain {
|
|
|
405
409
|
this.updateHomeKitCharacteristics();
|
|
406
410
|
}
|
|
407
411
|
else {
|
|
408
|
-
this.errorLog(
|
|
412
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
409
413
|
if (this.platform.config.credentials?.token) {
|
|
410
|
-
this.warnLog(
|
|
414
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
411
415
|
this.SwitchToOpenAPI = true;
|
|
412
416
|
await this.openAPIRefreshStatus();
|
|
413
417
|
}
|
|
414
418
|
}
|
|
415
419
|
})
|
|
416
420
|
.catch(async (e) => {
|
|
417
|
-
this.errorLog(
|
|
421
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
418
422
|
if (this.deviceLogging.includes('debug')) {
|
|
419
|
-
this.errorLog(
|
|
423
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
424
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
420
425
|
}
|
|
421
426
|
if (this.platform.config.credentials?.token) {
|
|
422
|
-
this.warnLog(
|
|
427
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
423
428
|
this.SwitchToOpenAPI = true;
|
|
424
429
|
await this.openAPIRefreshStatus();
|
|
425
430
|
}
|
|
@@ -439,7 +444,7 @@ class Curtain {
|
|
|
439
444
|
});
|
|
440
445
|
// Set an event handler
|
|
441
446
|
switchbot.onadvertisement = (ad) => {
|
|
442
|
-
this.warnLog(
|
|
447
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
443
448
|
};
|
|
444
449
|
await switchbot.wait(10000);
|
|
445
450
|
// Stop to monitor
|
|
@@ -448,23 +453,23 @@ class Curtain {
|
|
|
448
453
|
}
|
|
449
454
|
}
|
|
450
455
|
async BLEconnection(switchbot) {
|
|
451
|
-
this.errorLog(
|
|
456
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
452
457
|
if (this.platform.config.credentials?.token) {
|
|
453
|
-
this.warnLog(
|
|
458
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
454
459
|
this.SwitchToOpenAPI = true;
|
|
455
460
|
await this.openAPIRefreshStatus();
|
|
456
461
|
}
|
|
457
462
|
}
|
|
458
463
|
async openAPIRefreshStatus() {
|
|
459
|
-
if (this.platform.config.credentials?.token) {
|
|
460
|
-
this.debugLog(
|
|
464
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
465
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
461
466
|
try {
|
|
462
467
|
const t = Date.now();
|
|
463
468
|
const nonce = 'requestID';
|
|
464
469
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
465
470
|
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
466
471
|
const sign = signTerm.toString('base64');
|
|
467
|
-
this.debugLog(
|
|
472
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
468
473
|
const options = {
|
|
469
474
|
hostname: settings_1.HostDomain,
|
|
470
475
|
port: 443,
|
|
@@ -479,16 +484,16 @@ class Curtain {
|
|
|
479
484
|
},
|
|
480
485
|
};
|
|
481
486
|
const req = https_1.default.request(options, (res) => {
|
|
482
|
-
this.debugLog(
|
|
487
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
483
488
|
let rawData = '';
|
|
484
489
|
res.on('data', (d) => {
|
|
485
490
|
rawData += d;
|
|
486
|
-
this.debugLog(
|
|
491
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
487
492
|
});
|
|
488
493
|
res.on('end', () => {
|
|
489
494
|
try {
|
|
490
495
|
this.deviceStatus = JSON.parse(rawData);
|
|
491
|
-
this.debugLog(
|
|
496
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
492
497
|
this.slidePosition = this.deviceStatus.body.slidePosition;
|
|
493
498
|
this.moving = this.deviceStatus.body.moving;
|
|
494
499
|
this.brightness = this.deviceStatus.body.brightness;
|
|
@@ -496,23 +501,27 @@ class Curtain {
|
|
|
496
501
|
this.updateHomeKitCharacteristics();
|
|
497
502
|
}
|
|
498
503
|
catch (e) {
|
|
499
|
-
this.errorLog(
|
|
504
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
500
505
|
}
|
|
501
506
|
});
|
|
502
507
|
});
|
|
503
508
|
req.on('error', (e) => {
|
|
504
|
-
this.errorLog(
|
|
509
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
505
510
|
});
|
|
506
511
|
req.end();
|
|
507
512
|
}
|
|
508
513
|
catch (e) {
|
|
509
|
-
this.errorLog(
|
|
514
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
510
515
|
if (this.deviceLogging.includes('debug')) {
|
|
511
|
-
this.errorLog(
|
|
516
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
517
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
512
518
|
}
|
|
513
519
|
this.apiError(e);
|
|
514
520
|
}
|
|
515
521
|
}
|
|
522
|
+
else {
|
|
523
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
524
|
+
}
|
|
516
525
|
}
|
|
517
526
|
async pushChanges() {
|
|
518
527
|
if (this.device.ble) {
|
|
@@ -529,14 +538,14 @@ class Curtain {
|
|
|
529
538
|
}
|
|
530
539
|
async BLEpushChanges() {
|
|
531
540
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
532
|
-
this.debugLog(
|
|
541
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges`);
|
|
533
542
|
const switchbot = await this.platform.connectBLE();
|
|
534
543
|
// Convert to BLE Address
|
|
535
544
|
this.device.bleMac = this.device
|
|
536
545
|
.deviceId.match(/.{1,2}/g)
|
|
537
546
|
.join(':')
|
|
538
547
|
.toLowerCase();
|
|
539
|
-
this.debugLog(
|
|
548
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
540
549
|
if (this.TargetPosition > 50) {
|
|
541
550
|
if (this.device.curtain?.setOpenMode === '1') {
|
|
542
551
|
this.setPositionMode = 1;
|
|
@@ -570,37 +579,38 @@ class Curtain {
|
|
|
570
579
|
return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
|
|
571
580
|
})
|
|
572
581
|
.then(() => {
|
|
573
|
-
this.debugLog(
|
|
582
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
574
583
|
})
|
|
575
584
|
.catch(async (e) => {
|
|
576
|
-
this.errorLog(
|
|
585
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
577
586
|
if (this.deviceLogging.includes('debug')) {
|
|
578
|
-
this.errorLog(
|
|
587
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
588
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
579
589
|
}
|
|
580
590
|
if (this.platform.config.credentials?.token) {
|
|
581
|
-
this.warnLog(
|
|
591
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
582
592
|
await this.openAPIpushChanges();
|
|
583
593
|
}
|
|
584
594
|
this.apiError(e);
|
|
585
595
|
});
|
|
586
596
|
}
|
|
587
597
|
else {
|
|
588
|
-
this.errorLog(
|
|
598
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
589
599
|
if (this.platform.config.credentials?.token) {
|
|
590
|
-
this.warnLog(
|
|
600
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
591
601
|
await this.openAPIpushChanges();
|
|
592
602
|
}
|
|
593
603
|
}
|
|
594
604
|
}
|
|
595
605
|
else {
|
|
596
|
-
this.debugLog(
|
|
606
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
597
607
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
598
608
|
}
|
|
599
609
|
}
|
|
600
610
|
async openAPIpushChanges() {
|
|
601
|
-
if (this.platform.config.credentials?.token) {
|
|
611
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
602
612
|
try {
|
|
603
|
-
this.debugLog(
|
|
613
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
604
614
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
605
615
|
// Make Push On request to the API
|
|
606
616
|
const t = Date.now();
|
|
@@ -610,7 +620,7 @@ class Curtain {
|
|
|
610
620
|
.update(Buffer.from(data, 'utf-8'))
|
|
611
621
|
.digest();
|
|
612
622
|
const sign = signTerm.toString('base64');
|
|
613
|
-
this.debugLog(
|
|
623
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
614
624
|
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
615
625
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
616
626
|
if (this.TargetPosition > 50) {
|
|
@@ -635,7 +645,7 @@ class Curtain {
|
|
|
635
645
|
'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
636
646
|
'commandType': 'command',
|
|
637
647
|
});
|
|
638
|
-
this.infoLog(
|
|
648
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
639
649
|
const options = {
|
|
640
650
|
hostname: settings_1.HostDomain,
|
|
641
651
|
port: 443,
|
|
@@ -651,84 +661,89 @@ class Curtain {
|
|
|
651
661
|
},
|
|
652
662
|
};
|
|
653
663
|
const req = https_1.default.request(options, res => {
|
|
654
|
-
this.debugLog(
|
|
664
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
655
665
|
this.statusCode({ res });
|
|
656
666
|
res.on('data', d => {
|
|
657
|
-
this.debugLog(
|
|
667
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
658
668
|
});
|
|
659
669
|
});
|
|
660
670
|
req.on('error', (e) => {
|
|
661
|
-
this.errorLog(
|
|
671
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
662
672
|
});
|
|
663
673
|
req.write(body);
|
|
664
674
|
req.end();
|
|
665
|
-
this.debugLog(
|
|
675
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
666
676
|
}
|
|
667
677
|
else {
|
|
668
|
-
this.debugLog(
|
|
678
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
669
679
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
670
680
|
}
|
|
671
681
|
}
|
|
672
682
|
catch (e) {
|
|
673
|
-
this.errorLog(
|
|
683
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
674
684
|
if (this.deviceLogging.includes('debug')) {
|
|
675
|
-
this.errorLog(
|
|
685
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
686
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
676
687
|
}
|
|
677
688
|
this.apiError(e);
|
|
678
689
|
}
|
|
679
690
|
}
|
|
691
|
+
else {
|
|
692
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
693
|
+
}
|
|
680
694
|
}
|
|
681
695
|
async updateHomeKitCharacteristics() {
|
|
682
696
|
await this.setMinMax();
|
|
683
697
|
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
684
|
-
this.debugLog(
|
|
698
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
685
699
|
}
|
|
686
700
|
else {
|
|
687
701
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
688
|
-
this.debugLog(
|
|
702
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
689
703
|
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
690
704
|
}
|
|
691
705
|
if (this.PositionState === undefined) {
|
|
692
|
-
this.debugLog(
|
|
706
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
693
707
|
}
|
|
694
708
|
else {
|
|
695
709
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, Number(this.PositionState));
|
|
696
|
-
this.debugLog(
|
|
710
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
697
711
|
this.mqttPublish('PositionState', this.PositionState);
|
|
698
712
|
}
|
|
699
713
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
700
|
-
this.debugLog(
|
|
714
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
701
715
|
}
|
|
702
716
|
else {
|
|
703
717
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
704
|
-
this.debugLog(
|
|
718
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
705
719
|
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
706
720
|
}
|
|
707
721
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
708
722
|
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
709
|
-
this.debugLog(
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
710
724
|
}
|
|
711
725
|
else {
|
|
712
726
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
713
|
-
this.debugLog(
|
|
727
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
728
|
+
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
714
729
|
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
715
730
|
}
|
|
716
731
|
}
|
|
717
732
|
if (this.device.ble) {
|
|
718
733
|
if (this.BatteryLevel === undefined) {
|
|
719
|
-
this.debugLog(
|
|
734
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
720
735
|
}
|
|
721
736
|
else {
|
|
722
737
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
723
|
-
this.debugLog(
|
|
738
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
724
739
|
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
725
740
|
}
|
|
726
741
|
if (this.StatusLowBattery === undefined) {
|
|
727
|
-
this.debugLog(
|
|
742
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
728
743
|
}
|
|
729
744
|
else {
|
|
730
745
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
731
|
-
this.debugLog(
|
|
746
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
732
747
|
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
733
748
|
}
|
|
734
749
|
}
|
|
@@ -749,53 +764,53 @@ class Curtain {
|
|
|
749
764
|
async statusCode({ res }) {
|
|
750
765
|
switch (res.statusCode) {
|
|
751
766
|
case 151:
|
|
752
|
-
this.errorLog(
|
|
767
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
753
768
|
break;
|
|
754
769
|
case 152:
|
|
755
|
-
this.errorLog(
|
|
770
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
756
771
|
break;
|
|
757
772
|
case 160:
|
|
758
|
-
this.errorLog(
|
|
773
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
759
774
|
break;
|
|
760
775
|
case 161:
|
|
761
|
-
this.errorLog(
|
|
776
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
762
777
|
break;
|
|
763
778
|
case 171:
|
|
764
|
-
this.errorLog(
|
|
779
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
765
780
|
break;
|
|
766
781
|
case 190:
|
|
767
|
-
this.errorLog(
|
|
782
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
768
783
|
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
769
784
|
break;
|
|
770
785
|
case 100:
|
|
771
|
-
this.debugLog(
|
|
786
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
772
787
|
break;
|
|
773
788
|
default:
|
|
774
|
-
this.debugLog(
|
|
789
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
775
790
|
}
|
|
776
791
|
}
|
|
777
792
|
/**
|
|
778
793
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
779
794
|
*/
|
|
780
795
|
async TargetPositionSet(value) {
|
|
781
|
-
this.debugLog(
|
|
796
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
782
797
|
this.TargetPosition = value;
|
|
783
798
|
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
784
799
|
await this.setMinMax();
|
|
785
800
|
if (value > this.CurrentPosition) {
|
|
786
801
|
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
|
|
787
802
|
this.setNewTarget = true;
|
|
788
|
-
this.debugLog(
|
|
803
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
789
804
|
}
|
|
790
805
|
else if (value < this.CurrentPosition) {
|
|
791
806
|
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
|
|
792
807
|
this.setNewTarget = true;
|
|
793
|
-
this.debugLog(
|
|
808
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
794
809
|
}
|
|
795
810
|
else {
|
|
796
811
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
797
812
|
this.setNewTarget = false;
|
|
798
|
-
this.debugLog(
|
|
813
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
|
|
799
814
|
}
|
|
800
815
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
|
|
801
816
|
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
|
|
@@ -804,10 +819,10 @@ class Curtain {
|
|
|
804
819
|
* The minimum time depends on the network control latency.
|
|
805
820
|
*/
|
|
806
821
|
clearTimeout(this.setNewTargetTimer);
|
|
807
|
-
this.debugLog(
|
|
822
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.updateRate}`);
|
|
808
823
|
if (this.setNewTarget) {
|
|
809
824
|
this.setNewTargetTimer = setTimeout(() => {
|
|
810
|
-
this.debugLog(
|
|
825
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
811
826
|
this.setNewTarget = false;
|
|
812
827
|
}, this.updateRate * 1000);
|
|
813
828
|
}
|
|
@@ -833,6 +848,9 @@ class Curtain {
|
|
|
833
848
|
if (device.ble) {
|
|
834
849
|
config['ble'] = device.ble;
|
|
835
850
|
}
|
|
851
|
+
if (device.openAPI !== undefined) {
|
|
852
|
+
config['openAPI'] = device.openAPI;
|
|
853
|
+
}
|
|
836
854
|
if (device.logging !== undefined) {
|
|
837
855
|
config['logging'] = device.logging;
|
|
838
856
|
}
|
|
@@ -843,78 +861,90 @@ class Curtain {
|
|
|
843
861
|
config['scanDuration'] = device.scanDuration;
|
|
844
862
|
}
|
|
845
863
|
if (Object.entries(config).length !== 0) {
|
|
846
|
-
this.infoLog(
|
|
864
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
847
865
|
}
|
|
848
866
|
}
|
|
849
867
|
async refreshRate(device) {
|
|
850
868
|
// refreshRate
|
|
851
869
|
if (device.refreshRate) {
|
|
852
870
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
853
|
-
this.debugLog(
|
|
871
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
854
872
|
}
|
|
855
873
|
else if (this.platform.config.options.refreshRate) {
|
|
856
874
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
857
|
-
this.debugLog(
|
|
875
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
858
876
|
}
|
|
859
877
|
// updateRate
|
|
860
878
|
if (device?.curtain?.updateRate) {
|
|
861
879
|
this.updateRate = device?.curtain?.updateRate;
|
|
862
|
-
this.debugLog(
|
|
880
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
|
|
863
881
|
}
|
|
864
882
|
else {
|
|
865
883
|
this.updateRate = 7;
|
|
866
|
-
this.debugLog(
|
|
884
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
async openAPI() {
|
|
888
|
+
if (!this.device.openAPI) {
|
|
889
|
+
this.OpenAPI = true;
|
|
890
|
+
}
|
|
891
|
+
else {
|
|
892
|
+
this.OpenAPI = this.device.openAPI;
|
|
867
893
|
}
|
|
894
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
868
895
|
}
|
|
869
896
|
async scan(device) {
|
|
870
897
|
if (device.scanDuration) {
|
|
871
898
|
if (this.updateRate > device.scanDuration) {
|
|
872
899
|
this.scanDuration = this.updateRate;
|
|
873
|
-
this.warnLog(
|
|
900
|
+
this.warnLog(`${this.device.deviceType}: `
|
|
901
|
+
+ `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
874
902
|
}
|
|
875
903
|
else {
|
|
876
904
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
877
905
|
}
|
|
878
906
|
if (device.ble) {
|
|
879
|
-
this.debugLog(
|
|
907
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
880
908
|
}
|
|
881
909
|
}
|
|
882
910
|
else {
|
|
883
911
|
if (this.updateRate > 1) {
|
|
884
912
|
this.scanDuration = this.updateRate;
|
|
885
|
-
this.warnLog(
|
|
913
|
+
this.warnLog(`${this.device.deviceType}: `
|
|
914
|
+
+ `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`);
|
|
886
915
|
}
|
|
887
916
|
else {
|
|
888
917
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
889
918
|
}
|
|
890
919
|
if (this.device.ble) {
|
|
891
|
-
this.debugLog(
|
|
920
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
892
921
|
}
|
|
893
922
|
}
|
|
894
923
|
}
|
|
895
924
|
async logs(device) {
|
|
896
925
|
if (this.platform.debugMode) {
|
|
897
926
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
898
|
-
this.debugLog(
|
|
927
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
899
928
|
}
|
|
900
929
|
else if (device.logging) {
|
|
901
930
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
902
|
-
this.debugLog(
|
|
931
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
903
932
|
}
|
|
904
933
|
else if (this.platform.config.options?.logging) {
|
|
905
934
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
906
|
-
this.debugLog(
|
|
935
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
907
936
|
}
|
|
908
937
|
else {
|
|
909
938
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
910
|
-
this.debugLog(
|
|
939
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
911
940
|
}
|
|
912
941
|
}
|
|
913
942
|
FirmwareRevision(accessory, device) {
|
|
914
943
|
let FirmwareRevision;
|
|
915
|
-
this.debugLog(
|
|
916
|
-
|
|
917
|
-
this.debugLog(
|
|
944
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
945
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
946
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
947
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
918
948
|
if (accessory.context.FirmwareRevision) {
|
|
919
949
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
920
950
|
}
|