@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0
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/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/devices/curtains.ts
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
1
|
+
import * as axios from "axios";
|
|
2
|
+
import * as rxjs from "rxjs";
|
|
3
|
+
import * as platform from "../platform";
|
|
4
|
+
import * as operators from "rxjs/operators";
|
|
5
|
+
import * as homebridge from "homebridge";
|
|
6
|
+
import * as settings from "../settings";
|
|
8
7
|
|
|
9
8
|
export class Curtain {
|
|
10
9
|
// Services
|
|
11
|
-
private service: Service;
|
|
12
|
-
private lightSensorService?: Service;
|
|
13
|
-
private batteryService?: Service;
|
|
10
|
+
private service: homebridge.Service;
|
|
11
|
+
private lightSensorService?: homebridge.Service;
|
|
12
|
+
private batteryService?: homebridge.Service;
|
|
14
13
|
|
|
15
14
|
// Characteristic Values
|
|
16
|
-
CurrentPosition!: CharacteristicValue;
|
|
17
|
-
PositionState!: CharacteristicValue;
|
|
18
|
-
TargetPosition!: CharacteristicValue;
|
|
19
|
-
CurrentAmbientLightLevel?: CharacteristicValue;
|
|
20
|
-
BatteryLevel?: CharacteristicValue;
|
|
21
|
-
StatusLowBattery?: CharacteristicValue;
|
|
15
|
+
CurrentPosition!: homebridge.CharacteristicValue;
|
|
16
|
+
PositionState!: homebridge.CharacteristicValue;
|
|
17
|
+
TargetPosition!: homebridge.CharacteristicValue;
|
|
18
|
+
CurrentAmbientLightLevel?: homebridge.CharacteristicValue;
|
|
19
|
+
BatteryLevel?: homebridge.CharacteristicValue;
|
|
20
|
+
StatusLowBattery?: homebridge.CharacteristicValue;
|
|
22
21
|
|
|
23
22
|
// OpenAPI Others
|
|
24
|
-
deviceStatus!: deviceStatusResponse;
|
|
25
|
-
slidePosition: deviceStatus[
|
|
26
|
-
moving: deviceStatus[
|
|
27
|
-
brightness: deviceStatus[
|
|
23
|
+
deviceStatus!: settings.deviceStatusResponse;
|
|
24
|
+
slidePosition: settings.deviceStatus["slidePosition"];
|
|
25
|
+
moving: settings.deviceStatus["moving"];
|
|
26
|
+
brightness: settings.deviceStatus["brightness"];
|
|
28
27
|
|
|
29
28
|
// BLE Others
|
|
30
29
|
connected?: boolean;
|
|
31
|
-
switchbot!: switchbot;
|
|
32
30
|
SwitchToOpenAPI?: boolean;
|
|
33
|
-
serviceData!: serviceData;
|
|
31
|
+
serviceData!: settings.serviceData;
|
|
34
32
|
spaceBetweenLevels!: number;
|
|
35
|
-
calibration: serviceData[
|
|
36
|
-
battery: serviceData[
|
|
37
|
-
position: serviceData[
|
|
38
|
-
lightLevel: serviceData[
|
|
33
|
+
calibration: settings.serviceData["calibration"];
|
|
34
|
+
battery: settings.serviceData["battery"];
|
|
35
|
+
position: settings.serviceData["position"];
|
|
36
|
+
lightLevel: settings.serviceData["lightLevel"];
|
|
39
37
|
|
|
40
38
|
// Target
|
|
41
39
|
setNewTarget!: boolean;
|
|
@@ -52,12 +50,12 @@ export class Curtain {
|
|
|
52
50
|
|
|
53
51
|
// Updates
|
|
54
52
|
curtainUpdateInProgress!: boolean;
|
|
55
|
-
doCurtainUpdate!: Subject<void>;
|
|
53
|
+
doCurtainUpdate!: rxjs.Subject<void>;
|
|
56
54
|
|
|
57
55
|
constructor(
|
|
58
|
-
private readonly platform: SwitchBotPlatform,
|
|
59
|
-
private accessory: PlatformAccessory,
|
|
60
|
-
public device: device & devicesConfig,
|
|
56
|
+
private readonly platform: platform.SwitchBotPlatform,
|
|
57
|
+
private accessory: homebridge.PlatformAccessory,
|
|
58
|
+
public device: settings.device & settings.devicesConfig,
|
|
61
59
|
) {
|
|
62
60
|
// default placeholders
|
|
63
61
|
this.logs(device);
|
|
@@ -70,7 +68,7 @@ export class Curtain {
|
|
|
70
68
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
71
69
|
|
|
72
70
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
73
|
-
this.doCurtainUpdate = new Subject();
|
|
71
|
+
this.doCurtainUpdate = new rxjs.Subject();
|
|
74
72
|
this.curtainUpdateInProgress = false;
|
|
75
73
|
this.setNewTarget = false;
|
|
76
74
|
|
|
@@ -80,15 +78,22 @@ export class Curtain {
|
|
|
80
78
|
// set accessory information
|
|
81
79
|
accessory
|
|
82
80
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
84
|
-
.setCharacteristic(
|
|
85
|
-
|
|
81
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
82
|
+
.setCharacteristic(
|
|
83
|
+
this.platform.Characteristic.Model,
|
|
84
|
+
"SWITCHBOT-CURTAIN-W0701600",
|
|
85
|
+
)
|
|
86
|
+
.setCharacteristic(
|
|
87
|
+
this.platform.Characteristic.SerialNumber,
|
|
88
|
+
device.deviceId,
|
|
89
|
+
);
|
|
86
90
|
|
|
87
91
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
88
92
|
// you can create multiple services for each accessory
|
|
89
93
|
(this.service =
|
|
90
94
|
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
91
|
-
accessory.addService(this.platform.Service.WindowCovering)),
|
|
95
|
+
accessory.addService(this.platform.Service.WindowCovering)),
|
|
96
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
92
97
|
|
|
93
98
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
94
99
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -96,13 +101,19 @@ export class Curtain {
|
|
|
96
101
|
|
|
97
102
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
98
103
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
99
|
-
this.service.setCharacteristic(
|
|
104
|
+
this.service.setCharacteristic(
|
|
105
|
+
this.platform.Characteristic.Name,
|
|
106
|
+
accessory.displayName,
|
|
107
|
+
);
|
|
100
108
|
|
|
101
109
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
102
110
|
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
103
111
|
|
|
104
112
|
// create handlers for required characteristics
|
|
105
|
-
this.service.setCharacteristic(
|
|
113
|
+
this.service.setCharacteristic(
|
|
114
|
+
this.platform.Characteristic.PositionState,
|
|
115
|
+
this.PositionState,
|
|
116
|
+
);
|
|
106
117
|
|
|
107
118
|
this.service
|
|
108
119
|
.getCharacteristic(this.platform.Characteristic.CurrentPosition)
|
|
@@ -126,82 +137,107 @@ export class Curtain {
|
|
|
126
137
|
|
|
127
138
|
// Light Sensor Service
|
|
128
139
|
if (device.curtain?.hide_lightsensor) {
|
|
129
|
-
this.debugLog(
|
|
130
|
-
|
|
140
|
+
this.debugLog(
|
|
141
|
+
`Curtain: ${accessory.displayName} Removing Light Sensor Service`,
|
|
142
|
+
);
|
|
143
|
+
this.lightSensorService = this.accessory.getService(
|
|
144
|
+
this.platform.Service.LightSensor,
|
|
145
|
+
);
|
|
131
146
|
accessory.removeService(this.lightSensorService!);
|
|
132
147
|
} else if (!this.lightSensorService) {
|
|
133
|
-
this.debugLog(
|
|
148
|
+
this.debugLog(
|
|
149
|
+
`Curtain: ${accessory.displayName} Add Light Sensor Service`,
|
|
150
|
+
);
|
|
134
151
|
(this.lightSensorService =
|
|
135
152
|
this.accessory.getService(this.platform.Service.LightSensor) ||
|
|
136
|
-
this.accessory.addService(this.platform.Service.LightSensor)),
|
|
137
|
-
|
|
138
|
-
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
153
|
+
this.accessory.addService(this.platform.Service.LightSensor)),
|
|
154
|
+
`${accessory.displayName} Light Sensor`;
|
|
139
155
|
|
|
156
|
+
this.lightSensorService.setCharacteristic(
|
|
157
|
+
this.platform.Characteristic.Name,
|
|
158
|
+
`${accessory.displayName} Light Sensor`,
|
|
159
|
+
);
|
|
140
160
|
} else {
|
|
141
|
-
this.debugLog(
|
|
161
|
+
this.debugLog(
|
|
162
|
+
`Curtain: ${accessory.displayName} Light Sensor Service Not Added`,
|
|
163
|
+
);
|
|
142
164
|
}
|
|
143
165
|
|
|
144
166
|
// Battery Service
|
|
145
167
|
if (!device.ble) {
|
|
146
|
-
this.debugLog(
|
|
147
|
-
|
|
168
|
+
this.debugLog(
|
|
169
|
+
`Curtain: ${accessory.displayName} Removing Battery Service`,
|
|
170
|
+
);
|
|
171
|
+
this.batteryService = this.accessory.getService(
|
|
172
|
+
this.platform.Service.Battery,
|
|
173
|
+
);
|
|
148
174
|
accessory.removeService(this.batteryService!);
|
|
149
175
|
} else if (device.ble && !this.batteryService) {
|
|
150
176
|
this.debugLog(`Curtain: ${accessory.displayName} Add Battery Service`);
|
|
151
177
|
(this.batteryService =
|
|
152
178
|
this.accessory.getService(this.platform.Service.Battery) ||
|
|
153
|
-
this.accessory.addService(this.platform.Service.Battery)),
|
|
154
|
-
|
|
155
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
179
|
+
this.accessory.addService(this.platform.Service.Battery)),
|
|
180
|
+
`${accessory.displayName} Battery`;
|
|
156
181
|
|
|
182
|
+
this.batteryService.setCharacteristic(
|
|
183
|
+
this.platform.Characteristic.Name,
|
|
184
|
+
`${accessory.displayName} Battery`,
|
|
185
|
+
);
|
|
157
186
|
} else {
|
|
158
|
-
this.debugLog(
|
|
187
|
+
this.debugLog(
|
|
188
|
+
`Curtain: ${accessory.displayName} Battery Service Not Added`,
|
|
189
|
+
);
|
|
159
190
|
}
|
|
160
191
|
|
|
161
|
-
|
|
162
192
|
// Update Homekit
|
|
163
193
|
this.updateHomeKitCharacteristics();
|
|
164
194
|
|
|
165
195
|
// Start an update interval
|
|
166
|
-
|
|
167
|
-
.
|
|
196
|
+
rxjs
|
|
197
|
+
.interval(this.deviceRefreshRate * 1000)
|
|
198
|
+
.pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
|
|
168
199
|
.subscribe(() => {
|
|
169
200
|
this.refreshStatus();
|
|
170
201
|
});
|
|
171
202
|
|
|
172
203
|
// update slide progress
|
|
173
|
-
|
|
174
|
-
.
|
|
204
|
+
rxjs
|
|
205
|
+
.interval(this.updateRate * 1000)
|
|
206
|
+
.pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
|
|
175
207
|
.subscribe(() => {
|
|
176
|
-
if (
|
|
208
|
+
if (
|
|
209
|
+
this.PositionState ===
|
|
210
|
+
this.platform.Characteristic.PositionState.STOPPED
|
|
211
|
+
) {
|
|
177
212
|
return;
|
|
178
213
|
}
|
|
179
|
-
this.debugLog(
|
|
214
|
+
this.debugLog(
|
|
215
|
+
`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`,
|
|
216
|
+
);
|
|
180
217
|
this.refreshStatus();
|
|
181
218
|
});
|
|
182
219
|
|
|
183
|
-
|
|
184
220
|
// Watch for Curtain change events
|
|
185
221
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
186
222
|
this.doCurtainUpdate
|
|
187
223
|
.pipe(
|
|
188
|
-
tap(() => {
|
|
224
|
+
operators.tap(() => {
|
|
189
225
|
this.curtainUpdateInProgress = true;
|
|
190
226
|
}),
|
|
191
|
-
debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
227
|
+
operators.debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
192
228
|
)
|
|
193
229
|
.subscribe(async () => {
|
|
194
230
|
try {
|
|
195
231
|
await this.pushChanges();
|
|
196
232
|
} catch (e: any) {
|
|
197
|
-
this.errorLog(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
233
|
+
this.errorLog(
|
|
234
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges`,
|
|
235
|
+
);
|
|
236
|
+
if (this.deviceLogging.includes("debug")) {
|
|
237
|
+
this.errorLog(
|
|
238
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges,` +
|
|
239
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
240
|
+
);
|
|
205
241
|
}
|
|
206
242
|
this.apiError(e);
|
|
207
243
|
}
|
|
@@ -225,25 +261,39 @@ export class Curtain {
|
|
|
225
261
|
// CurrentPosition
|
|
226
262
|
this.setMinMax();
|
|
227
263
|
this.CurrentPosition = 100 - Number(this.position);
|
|
228
|
-
this.debugLog(
|
|
264
|
+
this.debugLog(
|
|
265
|
+
`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`,
|
|
266
|
+
);
|
|
229
267
|
if (this.setNewTarget) {
|
|
230
|
-
this.infoLog(
|
|
268
|
+
this.infoLog(
|
|
269
|
+
`Curtain: ${this.accessory.displayName} Checking Status ...`,
|
|
270
|
+
);
|
|
231
271
|
}
|
|
232
272
|
|
|
233
273
|
if (this.setNewTarget) {
|
|
234
274
|
this.setMinMax();
|
|
235
275
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
236
|
-
this.debugLog(
|
|
237
|
-
|
|
276
|
+
this.debugLog(
|
|
277
|
+
`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`,
|
|
278
|
+
);
|
|
279
|
+
this.PositionState =
|
|
280
|
+
this.platform.Characteristic.PositionState.INCREASING;
|
|
238
281
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
239
|
-
this.debugLog(
|
|
240
|
-
|
|
282
|
+
this.debugLog(
|
|
283
|
+
`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`,
|
|
284
|
+
);
|
|
285
|
+
this.PositionState =
|
|
286
|
+
this.platform.Characteristic.PositionState.DECREASING;
|
|
241
287
|
} else {
|
|
242
|
-
this.debugLog(
|
|
288
|
+
this.debugLog(
|
|
289
|
+
`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`,
|
|
290
|
+
);
|
|
243
291
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
244
292
|
}
|
|
245
293
|
} else {
|
|
246
|
-
this.debugLog(
|
|
294
|
+
this.debugLog(
|
|
295
|
+
`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`,
|
|
296
|
+
);
|
|
247
297
|
if (!this.setNewTarget) {
|
|
248
298
|
// If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
|
|
249
299
|
this.TargetPosition = this.CurrentPosition;
|
|
@@ -251,8 +301,10 @@ export class Curtain {
|
|
|
251
301
|
this.debugLog(`Curtain: ${this.accessory.displayName} Stopped`);
|
|
252
302
|
}
|
|
253
303
|
}
|
|
254
|
-
this.debugLog(
|
|
255
|
-
|
|
304
|
+
this.debugLog(
|
|
305
|
+
`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
306
|
+
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
307
|
+
);
|
|
256
308
|
|
|
257
309
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
258
310
|
this.set_minLux = this.minLux();
|
|
@@ -263,57 +315,91 @@ export class Curtain {
|
|
|
263
315
|
switch (this.lightLevel) {
|
|
264
316
|
case 1:
|
|
265
317
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
266
|
-
this.debugLog(
|
|
318
|
+
this.debugLog(
|
|
319
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
320
|
+
);
|
|
267
321
|
break;
|
|
268
322
|
case 2:
|
|
269
|
-
this.CurrentAmbientLightLevel =
|
|
270
|
-
|
|
271
|
-
|
|
323
|
+
this.CurrentAmbientLightLevel =
|
|
324
|
+
(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
325
|
+
this.debugLog(
|
|
326
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
327
|
+
` Calculation: ${
|
|
328
|
+
(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels
|
|
329
|
+
}`,
|
|
330
|
+
);
|
|
272
331
|
break;
|
|
273
332
|
case 3:
|
|
274
|
-
this.CurrentAmbientLightLevel =
|
|
275
|
-
|
|
333
|
+
this.CurrentAmbientLightLevel =
|
|
334
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
335
|
+
this.debugLog(
|
|
336
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
337
|
+
);
|
|
276
338
|
break;
|
|
277
339
|
case 4:
|
|
278
|
-
this.CurrentAmbientLightLevel =
|
|
279
|
-
|
|
340
|
+
this.CurrentAmbientLightLevel =
|
|
341
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
342
|
+
this.debugLog(
|
|
343
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
344
|
+
);
|
|
280
345
|
break;
|
|
281
346
|
case 5:
|
|
282
|
-
this.CurrentAmbientLightLevel =
|
|
283
|
-
|
|
347
|
+
this.CurrentAmbientLightLevel =
|
|
348
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
349
|
+
this.debugLog(
|
|
350
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
351
|
+
);
|
|
284
352
|
break;
|
|
285
353
|
case 6:
|
|
286
|
-
this.CurrentAmbientLightLevel =
|
|
287
|
-
|
|
354
|
+
this.CurrentAmbientLightLevel =
|
|
355
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
356
|
+
this.debugLog(
|
|
357
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
358
|
+
);
|
|
288
359
|
break;
|
|
289
360
|
case 7:
|
|
290
|
-
this.CurrentAmbientLightLevel =
|
|
291
|
-
|
|
361
|
+
this.CurrentAmbientLightLevel =
|
|
362
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
363
|
+
this.debugLog(
|
|
364
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
365
|
+
);
|
|
292
366
|
break;
|
|
293
367
|
case 8:
|
|
294
|
-
this.CurrentAmbientLightLevel =
|
|
295
|
-
|
|
368
|
+
this.CurrentAmbientLightLevel =
|
|
369
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
370
|
+
this.debugLog(
|
|
371
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
372
|
+
);
|
|
296
373
|
break;
|
|
297
374
|
case 9:
|
|
298
|
-
this.CurrentAmbientLightLevel =
|
|
299
|
-
|
|
375
|
+
this.CurrentAmbientLightLevel =
|
|
376
|
+
((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
377
|
+
this.debugLog(
|
|
378
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`,
|
|
379
|
+
);
|
|
300
380
|
break;
|
|
301
381
|
case 10:
|
|
302
382
|
default:
|
|
303
383
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
304
384
|
this.debugLog();
|
|
305
385
|
}
|
|
306
|
-
this.debugLog(
|
|
307
|
-
|
|
386
|
+
this.debugLog(
|
|
387
|
+
`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
388
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
389
|
+
);
|
|
308
390
|
}
|
|
309
391
|
// Battery
|
|
310
392
|
this.BatteryLevel = Number(this.battery);
|
|
311
393
|
if (this.BatteryLevel < 10) {
|
|
312
|
-
this.StatusLowBattery =
|
|
394
|
+
this.StatusLowBattery =
|
|
395
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
313
396
|
} else {
|
|
314
|
-
this.StatusLowBattery =
|
|
397
|
+
this.StatusLowBattery =
|
|
398
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
315
399
|
}
|
|
316
|
-
this.debugLog(
|
|
400
|
+
this.debugLog(
|
|
401
|
+
`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`,
|
|
402
|
+
);
|
|
317
403
|
}
|
|
318
404
|
|
|
319
405
|
private async openAPIparseStatus() {
|
|
@@ -321,52 +407,74 @@ export class Curtain {
|
|
|
321
407
|
this.SwitchToOpenAPI = false;
|
|
322
408
|
}
|
|
323
409
|
if (this.platform.config.credentials?.openToken) {
|
|
324
|
-
this.debugLog(
|
|
410
|
+
this.debugLog(
|
|
411
|
+
`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`,
|
|
412
|
+
);
|
|
325
413
|
// CurrentPosition
|
|
326
414
|
this.setMinMax();
|
|
327
415
|
this.CurrentPosition = 100 - Number(this.slidePosition);
|
|
328
|
-
this.debugLog(
|
|
416
|
+
this.debugLog(
|
|
417
|
+
`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`,
|
|
418
|
+
);
|
|
329
419
|
if (this.setNewTarget) {
|
|
330
|
-
this.infoLog(
|
|
420
|
+
this.infoLog(
|
|
421
|
+
`Curtain: ${this.accessory.displayName} Checking Status ...`,
|
|
422
|
+
);
|
|
331
423
|
}
|
|
332
424
|
|
|
333
425
|
if (this.setNewTarget && this.moving) {
|
|
334
426
|
this.setMinMax();
|
|
335
427
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
336
|
-
this.debugLog(
|
|
337
|
-
|
|
428
|
+
this.debugLog(
|
|
429
|
+
`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `,
|
|
430
|
+
);
|
|
431
|
+
this.PositionState =
|
|
432
|
+
this.platform.Characteristic.PositionState.INCREASING;
|
|
338
433
|
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
339
|
-
this.debugLog(
|
|
340
|
-
|
|
434
|
+
this.debugLog(
|
|
435
|
+
`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `,
|
|
436
|
+
);
|
|
437
|
+
this.PositionState =
|
|
438
|
+
this.platform.Characteristic.PositionState.DECREASING;
|
|
341
439
|
} else {
|
|
342
|
-
this.debugLog(
|
|
343
|
-
|
|
440
|
+
this.debugLog(
|
|
441
|
+
`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`,
|
|
442
|
+
);
|
|
443
|
+
this.PositionState =
|
|
444
|
+
this.platform.Characteristic.PositionState.STOPPED;
|
|
344
445
|
}
|
|
345
446
|
} else {
|
|
346
|
-
this.debugLog(
|
|
447
|
+
this.debugLog(
|
|
448
|
+
`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`,
|
|
449
|
+
);
|
|
347
450
|
if (!this.setNewTarget) {
|
|
348
451
|
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
|
|
349
452
|
this.TargetPosition = this.CurrentPosition;
|
|
350
|
-
this.PositionState =
|
|
453
|
+
this.PositionState =
|
|
454
|
+
this.platform.Characteristic.PositionState.STOPPED;
|
|
351
455
|
this.debugLog(`Curtain: ${this.accessory.displayName} Stopped`);
|
|
352
456
|
}
|
|
353
457
|
}
|
|
354
|
-
this.debugLog(
|
|
355
|
-
|
|
458
|
+
this.debugLog(
|
|
459
|
+
`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
460
|
+
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
461
|
+
);
|
|
356
462
|
|
|
357
463
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
358
464
|
this.set_minLux = this.minLux();
|
|
359
465
|
this.set_maxLux = this.maxLux();
|
|
360
466
|
// Brightness
|
|
361
467
|
switch (this.brightness) {
|
|
362
|
-
case
|
|
468
|
+
case "dim":
|
|
363
469
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
364
470
|
break;
|
|
365
|
-
case
|
|
471
|
+
case "bright":
|
|
366
472
|
default:
|
|
367
473
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
368
474
|
}
|
|
369
|
-
this.debugLog(
|
|
475
|
+
this.debugLog(
|
|
476
|
+
`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
477
|
+
);
|
|
370
478
|
}
|
|
371
479
|
}
|
|
372
480
|
}
|
|
@@ -383,100 +491,122 @@ export class Curtain {
|
|
|
383
491
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
384
492
|
const switchbot = await this.platform.connectBLE();
|
|
385
493
|
// Convert to BLE Address
|
|
386
|
-
this.device.bleMac =
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
494
|
+
this.device.bleMac = this.device
|
|
495
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
496
|
+
.join(":")
|
|
497
|
+
.toLowerCase();
|
|
498
|
+
this.debugLog(
|
|
499
|
+
`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
500
|
+
);
|
|
501
|
+
try {
|
|
502
|
+
await switchbot.discover({
|
|
503
|
+
model: "c",
|
|
504
|
+
quick: false,
|
|
505
|
+
});
|
|
506
|
+
// Start to monitor advertisement packets
|
|
507
|
+
await switchbot.startScan({
|
|
508
|
+
model: "c",
|
|
392
509
|
id: this.device.bleMac,
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// Stop to monitor
|
|
417
|
-
switchbot.stopScan();
|
|
418
|
-
if (this.connected) {
|
|
419
|
-
this.parseStatus();
|
|
420
|
-
this.updateHomeKitCharacteristics();
|
|
510
|
+
});
|
|
511
|
+
// Set an event hander
|
|
512
|
+
switchbot.onadvertisement = (ad: settings.ad) => {
|
|
513
|
+
this.serviceData = ad.serviceData;
|
|
514
|
+
this.calibration = ad.serviceData.calibration;
|
|
515
|
+
this.battery = ad.serviceData.battery;
|
|
516
|
+
this.position = ad.serviceData.position;
|
|
517
|
+
this.lightLevel = ad.serviceData.lightLevel;
|
|
518
|
+
this.debugLog(
|
|
519
|
+
`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(
|
|
520
|
+
ad.serviceData,
|
|
521
|
+
)}`,
|
|
522
|
+
);
|
|
523
|
+
this.debugLog(
|
|
524
|
+
`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
525
|
+
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
if (this.serviceData) {
|
|
529
|
+
this.connected = true;
|
|
530
|
+
this.debugLog(
|
|
531
|
+
`Curtain: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
532
|
+
);
|
|
421
533
|
} else {
|
|
422
|
-
this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
await this.openAPIRefreshStatus();
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}).catch(async (e: any) => {
|
|
430
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
431
|
-
if (this.deviceLogging === 'debug') {
|
|
432
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
433
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
434
|
-
}
|
|
435
|
-
if (this.platform.debugMode) {
|
|
436
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
437
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
534
|
+
this.connected = false;
|
|
535
|
+
this.debugLog(
|
|
536
|
+
`Curtain: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
537
|
+
);
|
|
438
538
|
}
|
|
539
|
+
};
|
|
540
|
+
// Wait 10 seconds
|
|
541
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
542
|
+
// Stop to monitor
|
|
543
|
+
switchbot.stopScan();
|
|
544
|
+
if (this.connected) {
|
|
545
|
+
this.parseStatus();
|
|
546
|
+
this.updateHomeKitCharacteristics();
|
|
547
|
+
} else {
|
|
548
|
+
this.errorLog(
|
|
549
|
+
`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
550
|
+
);
|
|
439
551
|
if (this.platform.config.credentials?.openToken) {
|
|
440
|
-
this.warnLog(
|
|
552
|
+
this.warnLog(
|
|
553
|
+
`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
554
|
+
);
|
|
441
555
|
this.SwitchToOpenAPI = true;
|
|
442
556
|
await this.openAPIRefreshStatus();
|
|
443
557
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
this.
|
|
456
|
-
|
|
558
|
+
}
|
|
559
|
+
} catch (e: any) {
|
|
560
|
+
this.errorLog(
|
|
561
|
+
`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`,
|
|
562
|
+
);
|
|
563
|
+
if (this.deviceLogging.includes("debug")) {
|
|
564
|
+
this.errorLog(
|
|
565
|
+
`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
566
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
if (this.platform.config.credentials?.openToken) {
|
|
570
|
+
this.warnLog(
|
|
571
|
+
`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
572
|
+
);
|
|
573
|
+
this.SwitchToOpenAPI = true;
|
|
574
|
+
await this.openAPIRefreshStatus();
|
|
575
|
+
}
|
|
576
|
+
this.apiError(e);
|
|
457
577
|
}
|
|
458
578
|
}
|
|
459
579
|
|
|
460
580
|
private async openAPIRefreshStatus() {
|
|
461
581
|
if (this.platform.config.credentials?.openToken) {
|
|
462
|
-
this.debugLog(
|
|
582
|
+
this.debugLog(
|
|
583
|
+
`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`,
|
|
584
|
+
);
|
|
463
585
|
try {
|
|
464
|
-
this.deviceStatus = (
|
|
465
|
-
|
|
586
|
+
this.deviceStatus = (
|
|
587
|
+
await this.platform.axios.get(
|
|
588
|
+
`${settings.DeviceURL}/${this.device.deviceId}/status`,
|
|
589
|
+
)
|
|
590
|
+
).data;
|
|
591
|
+
this.debugLog(
|
|
592
|
+
`Curtain: ${
|
|
593
|
+
this.accessory.displayName
|
|
594
|
+
} refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
|
|
595
|
+
);
|
|
466
596
|
this.slidePosition = this.deviceStatus.body.slidePosition;
|
|
467
597
|
this.moving = this.deviceStatus.body.moving;
|
|
468
598
|
this.brightness = this.deviceStatus.body.brightness;
|
|
469
599
|
this.parseStatus();
|
|
470
600
|
this.updateHomeKitCharacteristics();
|
|
471
601
|
} catch (e: any) {
|
|
472
|
-
this.errorLog(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
602
|
+
this.errorLog(
|
|
603
|
+
`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
|
|
604
|
+
);
|
|
605
|
+
if (this.deviceLogging.includes("debug")) {
|
|
606
|
+
this.errorLog(
|
|
607
|
+
`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
608
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
609
|
+
);
|
|
480
610
|
}
|
|
481
611
|
this.apiError(e);
|
|
482
612
|
}
|
|
@@ -489,9 +619,10 @@ export class Curtain {
|
|
|
489
619
|
} else {
|
|
490
620
|
await this.openAPIpushChanges();
|
|
491
621
|
}
|
|
492
|
-
|
|
493
|
-
.
|
|
494
|
-
.pipe(
|
|
622
|
+
rxjs
|
|
623
|
+
.interval(5000)
|
|
624
|
+
.pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
|
|
625
|
+
.pipe(operators.take(1))
|
|
495
626
|
.subscribe(() => {
|
|
496
627
|
this.refreshStatus();
|
|
497
628
|
});
|
|
@@ -502,76 +633,108 @@ export class Curtain {
|
|
|
502
633
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
503
634
|
const switchbot = await this.platform.connectBLE();
|
|
504
635
|
// Convert to BLE Address
|
|
505
|
-
this.device.bleMac =
|
|
506
|
-
|
|
636
|
+
this.device.bleMac = this.device
|
|
637
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
638
|
+
.join(":")
|
|
639
|
+
.toLowerCase();
|
|
640
|
+
this.debugLog(
|
|
641
|
+
`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
642
|
+
);
|
|
507
643
|
if (switchbot !== false) {
|
|
508
|
-
switchbot
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
this.errorLog(
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
644
|
+
switchbot
|
|
645
|
+
.discover({ model: "c", quick: true, id: this.device.bleMac })
|
|
646
|
+
.then((device_list) => {
|
|
647
|
+
this.infoLog(
|
|
648
|
+
`${this.accessory.displayName} Target Position: ${this.TargetPosition}`,
|
|
649
|
+
);
|
|
650
|
+
return device_list[0].runToPos(100 - Number(this.TargetPosition));
|
|
651
|
+
})
|
|
652
|
+
.then(() => {
|
|
653
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} Done.`);
|
|
654
|
+
})
|
|
655
|
+
.catch(async (e: any) => {
|
|
656
|
+
this.errorLog(
|
|
657
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
|
|
658
|
+
);
|
|
659
|
+
if (this.deviceLogging.includes("debug")) {
|
|
660
|
+
this.errorLog(
|
|
661
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
662
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
if (this.platform.config.credentials?.openToken) {
|
|
666
|
+
this.warnLog(
|
|
667
|
+
`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
668
|
+
);
|
|
669
|
+
await this.openAPIpushChanges();
|
|
670
|
+
}
|
|
671
|
+
this.apiError(e);
|
|
672
|
+
});
|
|
529
673
|
} else {
|
|
530
|
-
this.errorLog(
|
|
674
|
+
this.errorLog(
|
|
675
|
+
`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
676
|
+
);
|
|
531
677
|
if (this.platform.config.credentials?.openToken) {
|
|
532
|
-
this.warnLog(
|
|
678
|
+
this.warnLog(
|
|
679
|
+
`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
680
|
+
);
|
|
533
681
|
await this.openAPIpushChanges();
|
|
534
682
|
}
|
|
535
683
|
}
|
|
536
684
|
} else {
|
|
537
|
-
this.debugLog(
|
|
538
|
-
|
|
685
|
+
this.debugLog(
|
|
686
|
+
`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
687
|
+
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
688
|
+
);
|
|
539
689
|
}
|
|
540
690
|
}
|
|
541
691
|
|
|
542
692
|
private async openAPIpushChanges() {
|
|
543
693
|
if (this.platform.config.credentials?.openToken) {
|
|
544
694
|
try {
|
|
545
|
-
this.debugLog(
|
|
695
|
+
this.debugLog(
|
|
696
|
+
`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`,
|
|
697
|
+
);
|
|
546
698
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
547
699
|
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
548
700
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
549
701
|
const payload = {
|
|
550
|
-
commandType:
|
|
551
|
-
command:
|
|
702
|
+
commandType: "command",
|
|
703
|
+
command: "setPosition",
|
|
552
704
|
parameter: `0,ff,${adjustedTargetPosition}`,
|
|
553
|
-
} as payload;
|
|
705
|
+
} as settings.payload;
|
|
554
706
|
|
|
555
|
-
this.infoLog(
|
|
556
|
-
|
|
707
|
+
this.infoLog(
|
|
708
|
+
`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
709
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
710
|
+
);
|
|
557
711
|
|
|
558
712
|
// Make the API request
|
|
559
|
-
const push: any =
|
|
560
|
-
|
|
713
|
+
const push: any = await this.platform.axios.post(
|
|
714
|
+
`${settings.DeviceURL}/${this.device.deviceId!}/commands`,
|
|
715
|
+
payload,
|
|
716
|
+
);
|
|
717
|
+
this.debugLog(
|
|
718
|
+
`Curtain: ${
|
|
719
|
+
this.accessory.displayName
|
|
720
|
+
} pushchanges: ${JSON.stringify(push.data)}`,
|
|
721
|
+
);
|
|
561
722
|
this.statusCode(push);
|
|
562
723
|
} else {
|
|
563
|
-
this.debugLog(
|
|
564
|
-
|
|
724
|
+
this.debugLog(
|
|
725
|
+
`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
726
|
+
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
727
|
+
);
|
|
565
728
|
}
|
|
566
729
|
} catch (e: any) {
|
|
567
|
-
this.errorLog(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
730
|
+
this.errorLog(
|
|
731
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
732
|
+
);
|
|
733
|
+
if (this.deviceLogging.includes("debug")) {
|
|
734
|
+
this.errorLog(
|
|
735
|
+
`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
736
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
737
|
+
);
|
|
575
738
|
}
|
|
576
739
|
this.apiError(e);
|
|
577
740
|
}
|
|
@@ -580,124 +743,223 @@ export class Curtain {
|
|
|
580
743
|
|
|
581
744
|
updateHomeKitCharacteristics() {
|
|
582
745
|
this.setMinMax();
|
|
583
|
-
if (
|
|
584
|
-
this.
|
|
746
|
+
if (
|
|
747
|
+
this.CurrentPosition === undefined ||
|
|
748
|
+
Number.isNaN(this.CurrentPosition)
|
|
749
|
+
) {
|
|
750
|
+
this.debugLog(
|
|
751
|
+
`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`,
|
|
752
|
+
);
|
|
585
753
|
} else {
|
|
586
|
-
this.service.updateCharacteristic(
|
|
587
|
-
|
|
754
|
+
this.service.updateCharacteristic(
|
|
755
|
+
this.platform.Characteristic.CurrentPosition,
|
|
756
|
+
Number(this.CurrentPosition),
|
|
757
|
+
);
|
|
758
|
+
this.debugLog(
|
|
759
|
+
`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`,
|
|
760
|
+
);
|
|
588
761
|
}
|
|
589
762
|
if (this.PositionState === undefined) {
|
|
590
|
-
this.debugLog(
|
|
763
|
+
this.debugLog(
|
|
764
|
+
`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`,
|
|
765
|
+
);
|
|
591
766
|
} else {
|
|
592
|
-
this.debugLog(
|
|
767
|
+
this.debugLog(
|
|
768
|
+
`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`,
|
|
769
|
+
);
|
|
593
770
|
}
|
|
594
|
-
if (
|
|
595
|
-
this.
|
|
771
|
+
if (
|
|
772
|
+
this.TargetPosition === undefined ||
|
|
773
|
+
Number.isNaN(this.TargetPosition)
|
|
774
|
+
) {
|
|
775
|
+
this.debugLog(
|
|
776
|
+
`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`,
|
|
777
|
+
);
|
|
596
778
|
} else {
|
|
597
|
-
this.service.updateCharacteristic(
|
|
598
|
-
|
|
779
|
+
this.service.updateCharacteristic(
|
|
780
|
+
this.platform.Characteristic.TargetPosition,
|
|
781
|
+
Number(this.TargetPosition),
|
|
782
|
+
);
|
|
783
|
+
this.debugLog(
|
|
784
|
+
`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`,
|
|
785
|
+
);
|
|
599
786
|
}
|
|
600
787
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
601
|
-
if (
|
|
602
|
-
this.
|
|
788
|
+
if (
|
|
789
|
+
this.CurrentAmbientLightLevel === undefined ||
|
|
790
|
+
Number.isNaN(this.CurrentAmbientLightLevel)
|
|
791
|
+
) {
|
|
792
|
+
this.debugLog(
|
|
793
|
+
`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
794
|
+
);
|
|
603
795
|
} else {
|
|
604
|
-
this.lightSensorService?.updateCharacteristic(
|
|
605
|
-
|
|
606
|
-
|
|
796
|
+
this.lightSensorService?.updateCharacteristic(
|
|
797
|
+
this.platform.Characteristic.CurrentAmbientLightLevel,
|
|
798
|
+
this.CurrentAmbientLightLevel,
|
|
799
|
+
);
|
|
800
|
+
this.debugLog(
|
|
801
|
+
`Curtain: ${this.accessory.displayName}` +
|
|
802
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
803
|
+
);
|
|
607
804
|
}
|
|
608
805
|
}
|
|
609
806
|
if (this.device.ble) {
|
|
610
807
|
if (this.BatteryLevel === undefined) {
|
|
611
|
-
this.debugLog(
|
|
808
|
+
this.debugLog(
|
|
809
|
+
`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
|
|
810
|
+
);
|
|
612
811
|
} else {
|
|
613
|
-
this.batteryService?.updateCharacteristic(
|
|
614
|
-
|
|
812
|
+
this.batteryService?.updateCharacteristic(
|
|
813
|
+
this.platform.Characteristic.BatteryLevel,
|
|
814
|
+
this.BatteryLevel,
|
|
815
|
+
);
|
|
816
|
+
this.debugLog(
|
|
817
|
+
`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`,
|
|
818
|
+
);
|
|
615
819
|
}
|
|
616
820
|
if (this.StatusLowBattery === undefined) {
|
|
617
|
-
this.debugLog(
|
|
821
|
+
this.debugLog(
|
|
822
|
+
`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`,
|
|
823
|
+
);
|
|
618
824
|
} else {
|
|
619
|
-
this.batteryService?.updateCharacteristic(
|
|
620
|
-
|
|
825
|
+
this.batteryService?.updateCharacteristic(
|
|
826
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
827
|
+
this.StatusLowBattery,
|
|
828
|
+
);
|
|
829
|
+
this.debugLog(
|
|
830
|
+
`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`,
|
|
831
|
+
);
|
|
621
832
|
}
|
|
622
833
|
}
|
|
623
834
|
}
|
|
624
835
|
|
|
625
836
|
public apiError(e: any) {
|
|
626
|
-
this.service.updateCharacteristic(
|
|
627
|
-
|
|
628
|
-
|
|
837
|
+
this.service.updateCharacteristic(
|
|
838
|
+
this.platform.Characteristic.CurrentPosition,
|
|
839
|
+
e,
|
|
840
|
+
);
|
|
841
|
+
this.service.updateCharacteristic(
|
|
842
|
+
this.platform.Characteristic.PositionState,
|
|
843
|
+
e,
|
|
844
|
+
);
|
|
845
|
+
this.service.updateCharacteristic(
|
|
846
|
+
this.platform.Characteristic.TargetPosition,
|
|
847
|
+
e,
|
|
848
|
+
);
|
|
629
849
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
630
|
-
this.lightSensorService?.updateCharacteristic(
|
|
850
|
+
this.lightSensorService?.updateCharacteristic(
|
|
851
|
+
this.platform.Characteristic.CurrentAmbientLightLevel,
|
|
852
|
+
e,
|
|
853
|
+
);
|
|
631
854
|
}
|
|
632
855
|
if (this.device.ble) {
|
|
633
|
-
this.batteryService?.updateCharacteristic(
|
|
634
|
-
|
|
856
|
+
this.batteryService?.updateCharacteristic(
|
|
857
|
+
this.platform.Characteristic.BatteryLevel,
|
|
858
|
+
e,
|
|
859
|
+
);
|
|
860
|
+
this.batteryService?.updateCharacteristic(
|
|
861
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
862
|
+
e,
|
|
863
|
+
);
|
|
635
864
|
}
|
|
636
865
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
637
866
|
}
|
|
638
867
|
|
|
639
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
868
|
+
private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
|
|
640
869
|
switch (push.data.statusCode) {
|
|
641
870
|
case 151:
|
|
642
|
-
this.errorLog(
|
|
871
|
+
this.errorLog(
|
|
872
|
+
`Curtain: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
873
|
+
);
|
|
643
874
|
break;
|
|
644
875
|
case 152:
|
|
645
|
-
this.errorLog(
|
|
876
|
+
this.errorLog(
|
|
877
|
+
`Curtain: ${this.accessory.displayName} Device not found.`,
|
|
878
|
+
);
|
|
646
879
|
break;
|
|
647
880
|
case 160:
|
|
648
|
-
this.errorLog(
|
|
881
|
+
this.errorLog(
|
|
882
|
+
`Curtain: ${this.accessory.displayName} Command is not supported.`,
|
|
883
|
+
);
|
|
649
884
|
break;
|
|
650
885
|
case 161:
|
|
651
|
-
this.errorLog(
|
|
886
|
+
this.errorLog(
|
|
887
|
+
`Curtain: ${this.accessory.displayName} Device is offline.`,
|
|
888
|
+
);
|
|
652
889
|
break;
|
|
653
890
|
case 171:
|
|
654
|
-
this.errorLog(
|
|
891
|
+
this.errorLog(
|
|
892
|
+
`Curtain: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
893
|
+
);
|
|
655
894
|
break;
|
|
656
895
|
case 190:
|
|
657
|
-
this.errorLog(
|
|
658
|
-
|
|
896
|
+
this.errorLog(
|
|
897
|
+
`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
898
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
899
|
+
);
|
|
659
900
|
break;
|
|
660
901
|
case 100:
|
|
661
|
-
this.debugLog(
|
|
902
|
+
this.debugLog(
|
|
903
|
+
`Curtain: ${this.accessory.displayName} Command successfully sent.`,
|
|
904
|
+
);
|
|
662
905
|
break;
|
|
663
906
|
default:
|
|
664
|
-
this.debugLog(
|
|
907
|
+
this.debugLog(
|
|
908
|
+
`Curtain: ${this.accessory.displayName} Unknown statusCode.`,
|
|
909
|
+
);
|
|
665
910
|
}
|
|
666
911
|
}
|
|
667
912
|
|
|
668
913
|
/**
|
|
669
914
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
670
915
|
*/
|
|
671
|
-
TargetPositionSet(value: CharacteristicValue) {
|
|
672
|
-
this.debugLog(
|
|
916
|
+
TargetPositionSet(value: homebridge.CharacteristicValue) {
|
|
917
|
+
this.debugLog(
|
|
918
|
+
`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`,
|
|
919
|
+
);
|
|
673
920
|
|
|
674
921
|
this.TargetPosition = value;
|
|
675
922
|
|
|
676
923
|
this.setMinMax();
|
|
677
924
|
if (value > this.CurrentPosition) {
|
|
678
|
-
this.PositionState =
|
|
925
|
+
this.PositionState =
|
|
926
|
+
this.platform.Characteristic.PositionState.INCREASING;
|
|
679
927
|
this.setNewTarget = true;
|
|
680
|
-
this.debugLog(
|
|
928
|
+
this.debugLog(
|
|
929
|
+
`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`,
|
|
930
|
+
);
|
|
681
931
|
} else if (value < this.CurrentPosition) {
|
|
682
|
-
this.PositionState =
|
|
932
|
+
this.PositionState =
|
|
933
|
+
this.platform.Characteristic.PositionState.DECREASING;
|
|
683
934
|
this.setNewTarget = true;
|
|
684
|
-
this.debugLog(
|
|
935
|
+
this.debugLog(
|
|
936
|
+
`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`,
|
|
937
|
+
);
|
|
685
938
|
} else {
|
|
686
939
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
687
940
|
this.setNewTarget = false;
|
|
688
|
-
this.debugLog(
|
|
941
|
+
this.debugLog(
|
|
942
|
+
`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`,
|
|
943
|
+
);
|
|
689
944
|
}
|
|
690
|
-
this.service.setCharacteristic(
|
|
691
|
-
|
|
945
|
+
this.service.setCharacteristic(
|
|
946
|
+
this.platform.Characteristic.PositionState,
|
|
947
|
+
this.PositionState,
|
|
948
|
+
);
|
|
949
|
+
this.service
|
|
950
|
+
.getCharacteristic(this.platform.Characteristic.PositionState)
|
|
951
|
+
.updateValue(this.PositionState);
|
|
692
952
|
|
|
693
953
|
/**
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
954
|
+
* If Curtain movement time is short, the moving flag from backend is always false.
|
|
955
|
+
* The minimum time depends on the network control latency.
|
|
956
|
+
*/
|
|
697
957
|
clearTimeout(this.setNewTargetTimer);
|
|
698
958
|
if (this.setNewTarget) {
|
|
699
959
|
this.setNewTargetTimer = setTimeout(() => {
|
|
700
|
-
this.debugLog(
|
|
960
|
+
this.debugLog(
|
|
961
|
+
`Curtain: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`,
|
|
962
|
+
);
|
|
701
963
|
this.setNewTarget = false;
|
|
702
964
|
}, 10000);
|
|
703
965
|
}
|
|
@@ -717,78 +979,106 @@ export class Curtain {
|
|
|
717
979
|
}
|
|
718
980
|
}
|
|
719
981
|
|
|
720
|
-
config(device: device & devicesConfig) {
|
|
982
|
+
config(device: settings.device & settings.devicesConfig) {
|
|
721
983
|
let config = {};
|
|
722
984
|
if (device.curtain) {
|
|
723
985
|
config = device.curtain;
|
|
724
986
|
}
|
|
725
987
|
if (device.ble) {
|
|
726
|
-
config[
|
|
988
|
+
config["ble"] = device.ble;
|
|
727
989
|
}
|
|
728
990
|
if (device.logging !== undefined) {
|
|
729
|
-
config[
|
|
991
|
+
config["logging"] = device.logging;
|
|
730
992
|
}
|
|
731
993
|
if (device.refreshRate !== undefined) {
|
|
732
|
-
config[
|
|
994
|
+
config["refreshRate"] = device.refreshRate;
|
|
733
995
|
}
|
|
734
996
|
if (device.scanDuration !== undefined) {
|
|
735
|
-
config[
|
|
997
|
+
config["scanDuration"] = device.scanDuration;
|
|
736
998
|
}
|
|
737
999
|
if (Object.entries(config).length !== 0) {
|
|
738
|
-
this.warnLog(
|
|
1000
|
+
this.warnLog(
|
|
1001
|
+
`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
1002
|
+
config,
|
|
1003
|
+
)}`,
|
|
1004
|
+
);
|
|
739
1005
|
}
|
|
740
1006
|
}
|
|
741
1007
|
|
|
742
|
-
refreshRate(device: device & devicesConfig) {
|
|
1008
|
+
refreshRate(device: settings.device & settings.devicesConfig) {
|
|
743
1009
|
// refreshRate
|
|
744
1010
|
if (device.refreshRate) {
|
|
745
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
746
|
-
|
|
1011
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1012
|
+
device.refreshRate;
|
|
1013
|
+
this.debugLog(
|
|
1014
|
+
`Curtain: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
1015
|
+
);
|
|
747
1016
|
} else if (this.platform.config.options!.refreshRate) {
|
|
748
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
749
|
-
|
|
1017
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1018
|
+
this.platform.config.options!.refreshRate;
|
|
1019
|
+
this.debugLog(
|
|
1020
|
+
`Curtain: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
1021
|
+
);
|
|
750
1022
|
}
|
|
751
1023
|
// updateRate
|
|
752
1024
|
if (device?.curtain?.updateRate) {
|
|
753
1025
|
this.updateRate = device?.curtain?.updateRate;
|
|
754
|
-
this.debugLog(
|
|
1026
|
+
this.debugLog(
|
|
1027
|
+
`Curtain: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`,
|
|
1028
|
+
);
|
|
755
1029
|
} else {
|
|
756
1030
|
this.updateRate = 5;
|
|
757
|
-
this.debugLog(
|
|
1031
|
+
this.debugLog(
|
|
1032
|
+
`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`,
|
|
1033
|
+
);
|
|
758
1034
|
}
|
|
759
1035
|
}
|
|
760
1036
|
|
|
761
|
-
scan(device: device & devicesConfig) {
|
|
1037
|
+
scan(device: settings.device & settings.devicesConfig) {
|
|
762
1038
|
if (device.scanDuration) {
|
|
763
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
1039
|
+
this.scanDuration = this.accessory.context.scanDuration =
|
|
1040
|
+
device.scanDuration;
|
|
764
1041
|
if (device.ble) {
|
|
765
|
-
this.debugLog(
|
|
1042
|
+
this.debugLog(
|
|
1043
|
+
`Curtain: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
1044
|
+
);
|
|
766
1045
|
}
|
|
767
1046
|
} else {
|
|
768
1047
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
769
1048
|
if (this.device.ble) {
|
|
770
|
-
this.debugLog(
|
|
1049
|
+
this.debugLog(
|
|
1050
|
+
`Curtain: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
1051
|
+
);
|
|
771
1052
|
}
|
|
772
1053
|
}
|
|
773
1054
|
}
|
|
774
1055
|
|
|
775
|
-
logs(device: device & devicesConfig) {
|
|
1056
|
+
logs(device: settings.device & settings.devicesConfig) {
|
|
776
1057
|
if (this.platform.debugMode) {
|
|
777
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
778
|
-
this.debugLog(
|
|
1058
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
1059
|
+
this.debugLog(
|
|
1060
|
+
`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
1061
|
+
);
|
|
779
1062
|
} else if (device.logging) {
|
|
780
1063
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
781
|
-
this.debugLog(
|
|
1064
|
+
this.debugLog(
|
|
1065
|
+
`Curtain: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
1066
|
+
);
|
|
782
1067
|
} else if (this.platform.config.options?.logging) {
|
|
783
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
784
|
-
|
|
1068
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
1069
|
+
this.platform.config.options?.logging;
|
|
1070
|
+
this.debugLog(
|
|
1071
|
+
`Curtain: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
1072
|
+
);
|
|
785
1073
|
} else {
|
|
786
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
787
|
-
this.debugLog(
|
|
1074
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
1075
|
+
this.debugLog(
|
|
1076
|
+
`Curtain: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
1077
|
+
);
|
|
788
1078
|
}
|
|
789
1079
|
}
|
|
790
1080
|
|
|
791
|
-
private minStep(device: device & devicesConfig): number {
|
|
1081
|
+
private minStep(device: settings.device & settings.devicesConfig): number {
|
|
792
1082
|
if (device.curtain?.set_minStep) {
|
|
793
1083
|
this.set_minStep = device.curtain?.set_minStep;
|
|
794
1084
|
} else {
|
|
@@ -816,8 +1106,8 @@ export class Curtain {
|
|
|
816
1106
|
}
|
|
817
1107
|
|
|
818
1108
|
/**
|
|
819
|
-
|
|
820
|
-
|
|
1109
|
+
* Logging for Device
|
|
1110
|
+
*/
|
|
821
1111
|
infoLog(...log: any[]) {
|
|
822
1112
|
if (this.enablingDeviceLogging()) {
|
|
823
1113
|
this.platform.log.info(String(...log));
|
|
@@ -838,8 +1128,8 @@ export class Curtain {
|
|
|
838
1128
|
|
|
839
1129
|
debugLog(...log: any[]) {
|
|
840
1130
|
if (this.enablingDeviceLogging()) {
|
|
841
|
-
if (this.deviceLogging ===
|
|
842
|
-
this.platform.log.info(
|
|
1131
|
+
if (this.deviceLogging === "debug") {
|
|
1132
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
843
1133
|
} else {
|
|
844
1134
|
this.platform.log.debug(String(...log));
|
|
845
1135
|
}
|
|
@@ -847,6 +1137,8 @@ export class Curtain {
|
|
|
847
1137
|
}
|
|
848
1138
|
|
|
849
1139
|
enablingDeviceLogging(): boolean {
|
|
850
|
-
return
|
|
1140
|
+
return (
|
|
1141
|
+
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
1142
|
+
);
|
|
851
1143
|
}
|
|
852
1144
|
}
|