@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +335 -421
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +204 -249
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +107 -233
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +193 -235
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +92 -159
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +288 -370
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +172 -219
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +94 -160
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +95 -157
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +85 -144
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +100 -127
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +172 -259
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +106 -131
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -3
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -3
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -3
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +2 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +2 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +2 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -3
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/dist/device/blindtilt.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
*
|
|
3
3
|
* blindtilt.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { interval, Subject } from 'rxjs';
|
|
6
5
|
import { deviceBase } from './device.js';
|
|
7
6
|
import { BlindTiltMappingMode } from '../utils.js';
|
|
8
|
-
import {
|
|
7
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
|
+
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
9
|
export class BlindTilt extends deviceBase {
|
|
10
10
|
platform;
|
|
11
11
|
// Services
|
|
@@ -65,7 +65,7 @@ export class BlindTilt extends deviceBase {
|
|
|
65
65
|
maxValue: 100,
|
|
66
66
|
validValueRanges: [0, 100],
|
|
67
67
|
}).onGet(() => {
|
|
68
|
-
return this.WindowCovering
|
|
68
|
+
return this.WindowCovering.CurrentPosition ?? 0;
|
|
69
69
|
});
|
|
70
70
|
// Initialize WindowCovering TargetHorizontalTiltAngle Characteristic
|
|
71
71
|
this.WindowCovering.Service
|
|
@@ -108,11 +108,14 @@ export class BlindTilt extends deviceBase {
|
|
|
108
108
|
// Initialize LightSensor Service
|
|
109
109
|
if (device.blindTilt?.hide_lightsensor) {
|
|
110
110
|
if (this.LightSensor?.Service) {
|
|
111
|
-
this.debugLog(
|
|
111
|
+
this.debugLog('Removing Light Sensor Service');
|
|
112
112
|
this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor);
|
|
113
113
|
accessory.removeService(this.LightSensor.Service);
|
|
114
114
|
accessory.context.LightSensor = {};
|
|
115
115
|
}
|
|
116
|
+
else {
|
|
117
|
+
this.debugLog('Light Sensor Service is already removed');
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
120
|
else {
|
|
118
121
|
accessory.context.LightSensor = accessory.context.LightSensor ?? {};
|
|
@@ -135,22 +138,21 @@ export class BlindTilt extends deviceBase {
|
|
|
135
138
|
this.refreshStatus();
|
|
136
139
|
// Update Homekit
|
|
137
140
|
this.updateHomeKitCharacteristics();
|
|
141
|
+
//regisiter webhook event handler
|
|
142
|
+
this.registerWebhook();
|
|
138
143
|
// Start an update interval
|
|
139
144
|
interval(this.deviceRefreshRate * 1000)
|
|
140
145
|
.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
141
146
|
.subscribe(async () => {
|
|
142
147
|
await this.refreshStatus();
|
|
143
148
|
});
|
|
144
|
-
//regisiter webhook event handler
|
|
145
|
-
this.registerWebhook(accessory, device);
|
|
146
149
|
// update slide progress
|
|
147
150
|
interval(this.deviceUpdateRate * 1000)
|
|
148
151
|
.subscribe(async () => {
|
|
149
152
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
150
153
|
return;
|
|
151
154
|
}
|
|
152
|
-
this.debugLog(
|
|
153
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
155
|
+
this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`);
|
|
154
156
|
await this.refreshStatus();
|
|
155
157
|
});
|
|
156
158
|
// Watch for BlindTilt change events
|
|
@@ -164,9 +166,8 @@ export class BlindTilt extends deviceBase {
|
|
|
164
166
|
await this.pushChanges();
|
|
165
167
|
}
|
|
166
168
|
catch (e) {
|
|
167
|
-
this.apiError(e);
|
|
168
|
-
this.errorLog(
|
|
169
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
169
|
+
await this.apiError(e);
|
|
170
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
170
171
|
}
|
|
171
172
|
this.blindTiltUpdateInProgress = false;
|
|
172
173
|
});
|
|
@@ -175,210 +176,121 @@ export class BlindTilt extends deviceBase {
|
|
|
175
176
|
* Parse the device status from the SwitchBotBLE API
|
|
176
177
|
*/
|
|
177
178
|
async BLEparseStatus(serviceData) {
|
|
178
|
-
this.debugLog(
|
|
179
|
+
await this.debugLog('BLEparseStatus');
|
|
179
180
|
// CurrentPosition
|
|
180
|
-
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.
|
|
181
|
+
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.tilt);
|
|
181
182
|
await this.setMinMax();
|
|
182
|
-
this.debugLog(
|
|
183
|
+
await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
183
184
|
if (this.setNewTarget) {
|
|
184
|
-
this.infoLog(
|
|
185
|
+
await this.infoLog('Checking Status ...');
|
|
185
186
|
}
|
|
186
187
|
if (this.setNewTarget && serviceData.inMotion) {
|
|
187
188
|
await this.setMinMax();
|
|
188
189
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
189
|
-
this.debugLog(
|
|
190
|
+
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
190
191
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
191
192
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
192
|
-
this.debugLog(
|
|
193
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
193
|
+
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
194
194
|
}
|
|
195
195
|
else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
196
|
-
this.debugLog(
|
|
196
|
+
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
197
197
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
198
198
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
199
|
-
this.debugLog(
|
|
200
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
199
|
+
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
201
200
|
}
|
|
202
201
|
else {
|
|
203
|
-
this.debugLog(
|
|
204
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
202
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
205
203
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
206
204
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
207
|
-
this.debugLog(
|
|
208
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
205
|
+
await this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState);
|
|
209
206
|
}
|
|
210
207
|
}
|
|
211
208
|
else {
|
|
212
|
-
this.debugLog(
|
|
209
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
213
210
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
214
211
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
215
|
-
this.debugLog(
|
|
212
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
216
213
|
}
|
|
217
|
-
this.debugLog(
|
|
218
|
-
+ `
|
|
219
|
-
|
|
214
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
215
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
216
|
+
// CurrentAmbientLightLevel
|
|
217
|
+
if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
|
|
220
218
|
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
221
219
|
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
222
220
|
const spaceBetweenLevels = 9;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
// Brightness
|
|
227
|
-
switch (serviceData.lightLevel) {
|
|
228
|
-
case 1:
|
|
229
|
-
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
230
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
231
|
-
break;
|
|
232
|
-
case 2:
|
|
233
|
-
this.LightSensor.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
234
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
235
|
-
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
236
|
-
break;
|
|
237
|
-
case 3:
|
|
238
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
239
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
240
|
-
break;
|
|
241
|
-
case 4:
|
|
242
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
243
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
244
|
-
break;
|
|
245
|
-
case 5:
|
|
246
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
247
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
248
|
-
break;
|
|
249
|
-
case 6:
|
|
250
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
251
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
252
|
-
break;
|
|
253
|
-
case 7:
|
|
254
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
255
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
256
|
-
break;
|
|
257
|
-
case 8:
|
|
258
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
259
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
260
|
-
break;
|
|
261
|
-
case 9:
|
|
262
|
-
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
264
|
-
break;
|
|
265
|
-
case 10:
|
|
266
|
-
default:
|
|
267
|
-
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
268
|
-
this.debugLog();
|
|
269
|
-
}
|
|
270
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
271
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
221
|
+
await this.getLightLevel(serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
222
|
+
await this.debugLog(`LightLevel: ${serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
272
223
|
}
|
|
273
|
-
//
|
|
224
|
+
// BatteryLevel
|
|
274
225
|
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
282
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
226
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
227
|
+
// StatusLowBattery
|
|
228
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
229
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
230
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
283
231
|
}
|
|
232
|
+
;
|
|
284
233
|
/**
|
|
285
234
|
* Parse the device status from the SwitchBot OpenAPI
|
|
286
235
|
*/
|
|
287
236
|
async openAPIparseStatus(deviceStatus) {
|
|
288
|
-
this.debugLog(
|
|
289
|
-
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(deviceStatus.body.slidePosition), String(deviceStatus.body.direction));
|
|
290
|
-
this.debugLog(` device: ${deviceStatus.body.slidePosition} => HK: ${homekitPosition}`);
|
|
291
|
-
this.WindowCovering.CurrentPosition = homekitPosition;
|
|
237
|
+
await this.debugLog('openAPIparseStatus');
|
|
292
238
|
// CurrentPosition
|
|
293
|
-
await this.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (this.setNewTarget) {
|
|
301
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
239
|
+
await this.getCurrentPosttionDirection(deviceStatus.direction, deviceStatus.slidePosition);
|
|
240
|
+
if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
|
|
241
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
242
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
243
|
+
const lightLevel = deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
244
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
245
|
+
await this.debugLog(`LightLevel: ${deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
302
246
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
247
|
+
// BatteryLevel
|
|
248
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
249
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
250
|
+
// StatusLowBattery
|
|
251
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
252
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
253
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
254
|
+
// Firmware Version
|
|
255
|
+
const version = deviceStatus.version.toString();
|
|
256
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
257
|
+
if (deviceStatus.version) {
|
|
258
|
+
let deviceVersion;
|
|
259
|
+
if (version?.includes('.') === false) {
|
|
260
|
+
const replace = version?.replace(/^V|-.*$/g, '');
|
|
261
|
+
const match = replace?.match(/.{1,1}/g);
|
|
262
|
+
const blindTiltVersion = match?.join('.') ?? '0.0.0';
|
|
263
|
+
deviceVersion = blindTiltVersion;
|
|
319
264
|
}
|
|
320
265
|
else {
|
|
321
|
-
|
|
322
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
323
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
324
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
325
|
-
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} STOPPED`
|
|
326
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby because device not moving,`
|
|
331
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
332
|
-
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
333
|
-
if (homekitTiltAngle) {
|
|
334
|
-
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
335
|
-
}
|
|
336
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
337
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
338
|
-
}
|
|
339
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},`
|
|
340
|
-
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
|
|
341
|
-
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
342
|
-
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
343
|
-
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
344
|
-
// Brightness
|
|
345
|
-
switch (deviceStatus.body.brightness) {
|
|
346
|
-
case 'dim':
|
|
347
|
-
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
348
|
-
break;
|
|
349
|
-
case 'bright':
|
|
350
|
-
default:
|
|
351
|
-
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
266
|
+
deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
352
267
|
}
|
|
353
|
-
this.
|
|
354
|
-
|
|
268
|
+
this.accessory
|
|
269
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
270
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
271
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
272
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
273
|
+
.updateValue(deviceVersion);
|
|
274
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
275
|
+
await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
355
276
|
}
|
|
277
|
+
}
|
|
278
|
+
async parseStatusWebhook(context) {
|
|
279
|
+
await this.debugLog('parseStatusWebhook');
|
|
280
|
+
await this.debugLog(`(slidePosition, battery, version) = Webhook:(${context.direction}, ${context.slidePosition}, ${context.battery},`
|
|
281
|
+
+ `${context.version}, current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition},`
|
|
282
|
+
+ ` ${this.Battery.BatteryLevel}, ${this.accessory.context.deviceVersion})`);
|
|
283
|
+
// CurrentPosition and CurrentHorizontalTiltAngle
|
|
284
|
+
await this.getCurrentPosttionDirection(context.direction, context.slidePosition);
|
|
356
285
|
// BatteryLevel
|
|
357
|
-
this.Battery.BatteryLevel =
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
365
|
-
this.Battery.BatteryLevel = 100;
|
|
366
|
-
}
|
|
367
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
368
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
286
|
+
this.Battery.BatteryLevel = context.battery;
|
|
287
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
288
|
+
// StatusLowBattery
|
|
289
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
290
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
291
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
369
292
|
// Firmware Version
|
|
370
|
-
const
|
|
371
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
372
|
-
let deviceVersion;
|
|
373
|
-
if (version?.includes('.') === false) {
|
|
374
|
-
const replace = version?.replace(/^V|-.*$/g, '');
|
|
375
|
-
const match = replace?.match(/.{1,1}/g);
|
|
376
|
-
const blindTiltVersion = match?.join('.') ?? '0.0.0';
|
|
377
|
-
deviceVersion = blindTiltVersion;
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
381
|
-
}
|
|
293
|
+
const deviceVersion = context.version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
382
294
|
this.accessory
|
|
383
295
|
.getService(this.hap.Service.AccessoryInformation)
|
|
384
296
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -386,11 +298,14 @@ export class BlindTilt extends deviceBase {
|
|
|
386
298
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
387
299
|
.updateValue(deviceVersion);
|
|
388
300
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
389
|
-
this.debugSuccessLog(
|
|
301
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
390
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Asks the SwitchBot API for the latest device information
|
|
305
|
+
*/
|
|
391
306
|
async refreshStatus() {
|
|
392
307
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
393
|
-
this.errorLog(
|
|
308
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
394
309
|
}
|
|
395
310
|
else if (this.BLE) {
|
|
396
311
|
await this.BLERefreshStatus();
|
|
@@ -400,12 +315,11 @@ export class BlindTilt extends deviceBase {
|
|
|
400
315
|
}
|
|
401
316
|
else {
|
|
402
317
|
await this.offlineOff();
|
|
403
|
-
this.debugWarnLog(
|
|
404
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
318
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
405
319
|
}
|
|
406
320
|
}
|
|
407
321
|
async BLERefreshStatus() {
|
|
408
|
-
this.debugLog(
|
|
322
|
+
await this.debugLog('BLERefreshStatus');
|
|
409
323
|
const switchbot = await this.switchbotBLE();
|
|
410
324
|
if (switchbot === undefined) {
|
|
411
325
|
await this.BLERefreshConnection(switchbot);
|
|
@@ -416,70 +330,60 @@ export class BlindTilt extends deviceBase {
|
|
|
416
330
|
// Start to monitor advertisement packets
|
|
417
331
|
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
418
332
|
// Update HomeKit
|
|
419
|
-
if (serviceData.model
|
|
333
|
+
if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
|
|
420
334
|
await this.BLEparseStatus(serviceData);
|
|
421
335
|
await this.updateHomeKitCharacteristics();
|
|
422
336
|
}
|
|
423
337
|
else {
|
|
424
|
-
this.errorLog(
|
|
338
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
425
339
|
await this.BLERefreshConnection(switchbot);
|
|
426
340
|
}
|
|
427
341
|
})();
|
|
428
342
|
}
|
|
429
343
|
}
|
|
430
344
|
async openAPIRefreshStatus() {
|
|
431
|
-
this.debugLog(
|
|
345
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
432
346
|
try {
|
|
433
347
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
434
348
|
const deviceStatus = await body.json();
|
|
435
|
-
await this.
|
|
349
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
436
350
|
;
|
|
437
|
-
if (
|
|
438
|
-
await this.
|
|
439
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
351
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
352
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
353
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
440
354
|
await this.updateHomeKitCharacteristics();
|
|
441
355
|
}
|
|
442
356
|
else {
|
|
443
|
-
await this.
|
|
357
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
358
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
444
359
|
}
|
|
445
360
|
}
|
|
446
361
|
catch (e) {
|
|
447
|
-
this.apiError(e);
|
|
448
|
-
this.errorLog(
|
|
449
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
362
|
+
await this.apiError(e);
|
|
363
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
450
364
|
}
|
|
451
365
|
}
|
|
452
|
-
async registerWebhook(
|
|
453
|
-
if (device.webhook) {
|
|
454
|
-
this.debugLog(
|
|
366
|
+
async registerWebhook() {
|
|
367
|
+
if (this.device.webhook) {
|
|
368
|
+
await this.debugLog('is listening webhook.');
|
|
455
369
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
456
370
|
try {
|
|
457
|
-
this.debugLog(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const { BatteryLevel } = this.Battery;
|
|
461
|
-
const { CurrentAmbientLightLevel } = this.LightSensor ?? {};
|
|
462
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (slidePosition, battery, lightLevel) = Webhook:(${slidePosition}, ${battery},`
|
|
463
|
-
+ ` ${lightLevel}), current:(${CurrentPosition}, ${BatteryLevel}, ${CurrentAmbientLightLevel})`);
|
|
464
|
-
this.WindowCovering.CurrentPosition = slidePosition;
|
|
465
|
-
this.Battery.BatteryLevel = battery;
|
|
466
|
-
if (!device.blindTilt?.hide_lightsensor) {
|
|
467
|
-
this.LightSensor.CurrentAmbientLightLevel = lightLevel;
|
|
468
|
-
}
|
|
469
|
-
this.updateHomeKitCharacteristics();
|
|
371
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
372
|
+
await this.parseStatusWebhook(context);
|
|
373
|
+
await this.updateHomeKitCharacteristics();
|
|
470
374
|
}
|
|
471
375
|
catch (e) {
|
|
472
|
-
this.errorLog(
|
|
376
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
473
377
|
}
|
|
474
378
|
};
|
|
475
379
|
}
|
|
476
380
|
else {
|
|
477
|
-
this.debugLog(
|
|
381
|
+
await this.debugLog('is not listening webhook.');
|
|
478
382
|
}
|
|
479
383
|
}
|
|
480
384
|
async pushChanges() {
|
|
481
385
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
482
|
-
this.errorLog(
|
|
386
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
483
387
|
}
|
|
484
388
|
else if (this.BLE) {
|
|
485
389
|
await this.BLEpushChanges();
|
|
@@ -489,8 +393,7 @@ export class BlindTilt extends deviceBase {
|
|
|
489
393
|
}
|
|
490
394
|
else {
|
|
491
395
|
await this.offlineOff();
|
|
492
|
-
this.debugWarnLog(
|
|
493
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
396
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
494
397
|
}
|
|
495
398
|
// Refresh the status from the API
|
|
496
399
|
interval(15000)
|
|
@@ -501,18 +404,17 @@ export class BlindTilt extends deviceBase {
|
|
|
501
404
|
});
|
|
502
405
|
}
|
|
503
406
|
async BLEpushChanges() {
|
|
504
|
-
this.debugLog(
|
|
407
|
+
await this.debugLog('BLEpushChanges');
|
|
505
408
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
506
|
-
|
|
507
|
-
|
|
409
|
+
await this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`);
|
|
410
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
508
411
|
await this.convertBLEAddress();
|
|
509
412
|
const { setPositionMode, Mode } = await this.setPerformance();
|
|
510
|
-
this.debugLog(
|
|
413
|
+
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
511
414
|
if (switchbot !== false) {
|
|
512
415
|
switchbot
|
|
513
416
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
514
417
|
.then(async (device_list) => {
|
|
515
|
-
this.infoLog(`${this.accessory.displayName} Target Position: ${this.WindowCovering.TargetPosition}`);
|
|
516
418
|
return await this.retryBLE({
|
|
517
419
|
max: await this.maxRetryBLE(),
|
|
518
420
|
fn: async () => {
|
|
@@ -520,40 +422,37 @@ export class BlindTilt extends deviceBase {
|
|
|
520
422
|
},
|
|
521
423
|
});
|
|
522
424
|
})
|
|
523
|
-
.then(() => {
|
|
524
|
-
this.
|
|
525
|
-
this.
|
|
526
|
-
+ `Target Position: ${this.WindowCovering.TargetPosition} sent over BLE, sent successfully`);
|
|
425
|
+
.then(async () => {
|
|
426
|
+
await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
|
|
427
|
+
await this.updateHomeKitCharacteristics();
|
|
527
428
|
})
|
|
528
429
|
.catch(async (e) => {
|
|
529
|
-
this.apiError(e);
|
|
530
|
-
this.errorLog(
|
|
531
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
430
|
+
await this.apiError(e);
|
|
431
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
532
432
|
await this.BLEPushConnection();
|
|
533
433
|
});
|
|
534
434
|
}
|
|
535
435
|
else {
|
|
536
|
-
this.errorLog(
|
|
436
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
537
437
|
await this.BLEPushConnection();
|
|
538
438
|
}
|
|
539
439
|
}
|
|
540
440
|
else {
|
|
541
|
-
this.debugLog(
|
|
542
|
-
+ `
|
|
441
|
+
await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
442
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
543
443
|
}
|
|
544
444
|
}
|
|
545
445
|
async openAPIpushChanges() {
|
|
546
|
-
this.debugLog(
|
|
446
|
+
await this.debugLog('openAPIpushChanges');
|
|
547
447
|
const hasDifferentAndRelevantHorizontalTiltAngle = this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
548
448
|
&& this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
549
449
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition
|
|
550
450
|
|| hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
|
|
551
451
|
const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition), Number(this.WindowCovering.TargetHorizontalTiltAngle));
|
|
552
|
-
const { Mode } = await this.setPerformance();
|
|
553
|
-
this.debugLog(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
let bodyChange = '';
|
|
452
|
+
const { Mode, setPositionMode } = await this.setPerformance();
|
|
453
|
+
await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`);
|
|
454
|
+
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
455
|
+
let bodyChange;
|
|
557
456
|
if (position === 100) {
|
|
558
457
|
bodyChange = JSON.stringify({
|
|
559
458
|
command: 'fullyOpen',
|
|
@@ -575,13 +474,13 @@ export class BlindTilt extends deviceBase {
|
|
|
575
474
|
commandType: 'command',
|
|
576
475
|
});
|
|
577
476
|
}
|
|
578
|
-
this.debugLog(
|
|
477
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
579
478
|
try {
|
|
580
479
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
581
480
|
const deviceStatus = await body.json();
|
|
582
|
-
await this.
|
|
583
|
-
if (
|
|
584
|
-
await this.
|
|
481
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
482
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
483
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
585
484
|
await this.updateHomeKitCharacteristics();
|
|
586
485
|
}
|
|
587
486
|
else {
|
|
@@ -590,72 +489,64 @@ export class BlindTilt extends deviceBase {
|
|
|
590
489
|
}
|
|
591
490
|
}
|
|
592
491
|
catch (e) {
|
|
593
|
-
this.apiError(e);
|
|
594
|
-
this.errorLog(
|
|
595
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
492
|
+
await this.apiError(e);
|
|
493
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
596
494
|
}
|
|
597
495
|
}
|
|
598
496
|
else {
|
|
599
|
-
this.debugLog(
|
|
600
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}
|
|
601
|
-
|
|
602
|
-
+ `
|
|
497
|
+
await this.debugLog(`No changes (openAPIpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
498
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
499
|
+
await this.debugLog(`No changes (openAPIpushChanges), TargetHorizontalTiltAngle: ${this.WindowCovering.TargetHorizontalTiltAngle},`
|
|
500
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
603
501
|
}
|
|
604
502
|
}
|
|
605
503
|
/**
|
|
606
504
|
* Handle requests to set the value of the "Target Horizontal Tilt" characteristic
|
|
607
505
|
*/
|
|
608
506
|
async TargetHorizontalTiltAngleSet(value) {
|
|
609
|
-
if (this.WindowCovering.TargetHorizontalTiltAngle
|
|
610
|
-
this.debugLog(
|
|
507
|
+
if (this.WindowCovering.TargetHorizontalTiltAngle !== this.accessory.context.TargetHorizontalTiltAngle) {
|
|
508
|
+
await this.debugLog(`Set TargetHorizontalTiltAngle: ${value}`);
|
|
611
509
|
}
|
|
612
510
|
else {
|
|
613
|
-
this.
|
|
511
|
+
await this.debugLog(`No changes, TargetHorizontalTiltAngle: ${value}`);
|
|
614
512
|
}
|
|
615
513
|
//value = value < 0 ? -90 : 90;
|
|
616
514
|
this.WindowCovering.TargetHorizontalTiltAngle = value;
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
this.startUpdatingBlindTiltIfNeeded();
|
|
515
|
+
await this.mqtt('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle);
|
|
516
|
+
await this.startUpdatingBlindTiltIfNeeded();
|
|
621
517
|
}
|
|
622
518
|
/**
|
|
623
519
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
624
520
|
*/
|
|
625
521
|
async TargetPositionSet(value) {
|
|
626
|
-
if (this.WindowCovering.TargetPosition
|
|
627
|
-
this.debugLog(
|
|
522
|
+
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
523
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
628
524
|
}
|
|
629
525
|
else {
|
|
630
|
-
this.
|
|
526
|
+
await this.debugLog(`No changes, TargetPosition: ${value}`);
|
|
631
527
|
}
|
|
632
528
|
this.WindowCovering.TargetPosition = value;
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
this.startUpdatingBlindTiltIfNeeded();
|
|
529
|
+
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
|
|
530
|
+
await this.startUpdatingBlindTiltIfNeeded();
|
|
637
531
|
}
|
|
638
532
|
async startUpdatingBlindTiltIfNeeded() {
|
|
639
533
|
await this.setMinMax();
|
|
640
|
-
this.debugLog('setMinMax');
|
|
534
|
+
await this.debugLog('setMinMax');
|
|
641
535
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
642
536
|
|| this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
|
|
643
537
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
644
538
|
this.setNewTarget = true;
|
|
645
|
-
this.debugLog(
|
|
646
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
539
|
+
await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
647
540
|
}
|
|
648
541
|
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
649
542
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
650
543
|
this.setNewTarget = true;
|
|
651
|
-
this.debugLog(
|
|
652
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
544
|
+
await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
653
545
|
}
|
|
654
546
|
else {
|
|
655
547
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
656
548
|
this.setNewTarget = false;
|
|
657
|
-
this.debugLog(
|
|
658
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
549
|
+
await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
659
550
|
}
|
|
660
551
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
661
552
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
@@ -664,10 +555,10 @@ export class BlindTilt extends deviceBase {
|
|
|
664
555
|
* The minimum time depends on the network control latency.
|
|
665
556
|
*/
|
|
666
557
|
clearTimeout(this.setNewTargetTimer);
|
|
667
|
-
this.debugLog(
|
|
558
|
+
await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
|
|
668
559
|
if (this.setNewTarget) {
|
|
669
|
-
this.setNewTargetTimer = setTimeout(() => {
|
|
670
|
-
this.debugLog(
|
|
560
|
+
this.setNewTargetTimer = setTimeout(async () => {
|
|
561
|
+
await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
|
|
671
562
|
this.setNewTarget = false;
|
|
672
563
|
}, this.deviceUpdateRate * 1000);
|
|
673
564
|
}
|
|
@@ -677,124 +568,36 @@ export class BlindTilt extends deviceBase {
|
|
|
677
568
|
await this.setMinMax();
|
|
678
569
|
// CurrentHorizontalTiltAngle
|
|
679
570
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
680
|
-
|
|
681
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
682
|
-
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
if (this.device.mqttURL) {
|
|
686
|
-
this.mqttPublish('CurrentHorizontalTiltAngle', this.WindowCovering.CurrentHorizontalTiltAngle.toString());
|
|
687
|
-
}
|
|
688
|
-
this.accessory.context.CurrentHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
689
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, Number(this.WindowCovering.CurrentHorizontalTiltAngle));
|
|
690
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
691
|
-
updateCharacteristic CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
692
|
-
}
|
|
571
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentHorizontalTiltAngle, this.WindowCovering.CurrentHorizontalTiltAngle, 'CurrentHorizontalTiltAngle');
|
|
693
572
|
}
|
|
694
573
|
// CurrentPosition
|
|
695
|
-
|
|
696
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
if (this.device.mqttURL) {
|
|
700
|
-
this.mqttPublish('CurrentPosition', this.WindowCovering.CurrentPosition.toString());
|
|
701
|
-
}
|
|
702
|
-
this.accessory.context.CurrentPosition = this.WindowCovering.CurrentPosition;
|
|
703
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.WindowCovering.CurrentPosition));
|
|
704
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
705
|
-
+ ` updateCharacteristic CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
706
|
-
}
|
|
574
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition, this.WindowCovering.CurrentPosition, 'CurrentPosition');
|
|
707
575
|
// PositionState
|
|
708
|
-
|
|
709
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.WindowCovering.PositionState}`);
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
if (this.device.mqttURL) {
|
|
713
|
-
this.mqttPublish('PositionState', this.WindowCovering.PositionState.toString());
|
|
714
|
-
}
|
|
715
|
-
this.accessory.context.PositionState = this.WindowCovering.PositionState;
|
|
716
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
|
|
717
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
718
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
719
|
-
}
|
|
576
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState, this.WindowCovering.PositionState, 'PositionState');
|
|
720
577
|
// TargetPosition
|
|
721
|
-
|
|
722
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
if (this.device.mqttURL) {
|
|
726
|
-
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
727
|
-
}
|
|
728
|
-
this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
|
|
729
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
|
|
730
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
731
|
-
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
732
|
-
}
|
|
578
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition, this.WindowCovering.TargetPosition, 'TargetPosition');
|
|
733
579
|
// CurrentAmbientLightLevel
|
|
734
|
-
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
738
|
-
}
|
|
739
|
-
else {
|
|
740
|
-
if (this.device.mqttURL) {
|
|
741
|
-
this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor.CurrentAmbientLightLevel.toString());
|
|
742
|
-
}
|
|
743
|
-
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
|
|
744
|
-
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
745
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
746
|
-
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
747
|
-
}
|
|
580
|
+
if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
|
|
581
|
+
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel };
|
|
582
|
+
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
|
|
748
583
|
}
|
|
749
584
|
// BatteryLevel
|
|
750
|
-
|
|
751
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
if (this.device.mqttURL) {
|
|
755
|
-
this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
|
|
756
|
-
}
|
|
757
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
758
|
-
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
759
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
760
|
-
}
|
|
585
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel');
|
|
761
586
|
// StatusLowBattery
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
else {
|
|
766
|
-
if (this.device.mqttURL) {
|
|
767
|
-
this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
|
|
768
|
-
}
|
|
769
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
770
|
-
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
771
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
772
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
773
|
-
}
|
|
774
|
-
if (this.Battery.ChargingState === undefined) {
|
|
775
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
776
|
-
}
|
|
777
|
-
else {
|
|
778
|
-
if (this.device.mqttURL) {
|
|
779
|
-
this.mqttPublish('ChargingState', this.Battery.ChargingState.toString());
|
|
780
|
-
}
|
|
781
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
782
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
783
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
784
|
-
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
785
|
-
}
|
|
587
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
588
|
+
// ChargingState
|
|
589
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState');
|
|
786
590
|
}
|
|
787
591
|
async BLEPushConnection() {
|
|
788
592
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
789
|
-
this.warnLog(
|
|
593
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
790
594
|
await this.openAPIpushChanges();
|
|
791
595
|
}
|
|
792
596
|
}
|
|
793
597
|
async BLERefreshConnection(switchbot) {
|
|
794
|
-
this.errorLog(
|
|
795
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
598
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
796
599
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
797
|
-
this.warnLog(
|
|
600
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
798
601
|
await this.openAPIRefreshStatus();
|
|
799
602
|
}
|
|
800
603
|
}
|
|
@@ -842,6 +645,11 @@ export class BlindTilt extends deviceBase {
|
|
|
842
645
|
this.WindowCovering.CurrentPosition = 100;
|
|
843
646
|
}
|
|
844
647
|
}
|
|
648
|
+
if (this.device.history) {
|
|
649
|
+
const motion = this.accessory.getService(this.hap.Service.MotionSensor);
|
|
650
|
+
const state = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0;
|
|
651
|
+
motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state);
|
|
652
|
+
}
|
|
845
653
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
846
654
|
this.WindowCovering.CurrentHorizontalTiltAngle = Number(this.WindowCovering.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
|
|
847
655
|
}
|
|
@@ -864,11 +672,57 @@ export class BlindTilt extends deviceBase {
|
|
|
864
672
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
865
673
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
866
674
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e);
|
|
867
|
-
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
675
|
+
if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
|
|
868
676
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
869
677
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
870
678
|
}
|
|
871
679
|
}
|
|
680
|
+
async getCurrentPosttionDirection(direction, slidePosition) {
|
|
681
|
+
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(slidePosition), String(direction));
|
|
682
|
+
await this.debugLog(`Slide Position: ${slidePosition}`);
|
|
683
|
+
await this.debugLog(`Homekit Position: ${homekitPosition}`);
|
|
684
|
+
this.WindowCovering.CurrentPosition = homekitPosition;
|
|
685
|
+
await this.setMinMax();
|
|
686
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
687
|
+
if (homekitTiltAngle) {
|
|
688
|
+
this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle;
|
|
689
|
+
await this.debugLog(`CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
690
|
+
}
|
|
691
|
+
if (this.setNewTarget) {
|
|
692
|
+
await this.infoLog('Checking Status ...');
|
|
693
|
+
await this.setMinMax();
|
|
694
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
695
|
+
|| (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
696
|
+
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
697
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
698
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
699
|
+
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
700
|
+
}
|
|
701
|
+
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
702
|
+
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
703
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
704
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
705
|
+
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
await this.debugLog(`Standby because reached position, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
709
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
710
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
711
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
await this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
716
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
717
|
+
if (homekitTiltAngle) {
|
|
718
|
+
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
719
|
+
}
|
|
720
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
721
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
722
|
+
}
|
|
723
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
724
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
725
|
+
}
|
|
872
726
|
/**
|
|
873
727
|
* Maps device values to homekit values
|
|
874
728
|
*
|