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