@switchbot/homebridge-switchbot 1.1.1-beta.9 → 1.2.1-beta.2

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 (73) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +67 -28
  3. package/config.schema.json +46 -43
  4. package/dist/devices/bots.d.ts +1 -1
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +22 -22
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +7 -3
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +112 -29
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/curtains.d.ts +5 -5
  13. package/dist/devices/curtains.d.ts.map +1 -1
  14. package/dist/devices/curtains.js +10 -7
  15. package/dist/devices/curtains.js.map +1 -1
  16. package/dist/devices/humidifiers.d.ts.map +1 -1
  17. package/dist/devices/humidifiers.js +0 -1
  18. package/dist/devices/humidifiers.js.map +1 -1
  19. package/dist/devices/indoorcam.d.ts.map +1 -1
  20. package/dist/devices/indoorcam.js +0 -1
  21. package/dist/devices/indoorcam.js.map +1 -1
  22. package/dist/devices/plugs.d.ts.map +1 -1
  23. package/dist/devices/plugs.js +0 -1
  24. package/dist/devices/plugs.js.map +1 -1
  25. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  26. package/dist/irdevices/airconditioners.js +0 -1
  27. package/dist/irdevices/airconditioners.js.map +1 -1
  28. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  29. package/dist/irdevices/airpurifiers.js +0 -1
  30. package/dist/irdevices/airpurifiers.js.map +1 -1
  31. package/dist/irdevices/cameras.d.ts.map +1 -1
  32. package/dist/irdevices/cameras.js +0 -1
  33. package/dist/irdevices/cameras.js.map +1 -1
  34. package/dist/irdevices/fans.d.ts.map +1 -1
  35. package/dist/irdevices/fans.js +0 -1
  36. package/dist/irdevices/fans.js.map +1 -1
  37. package/dist/irdevices/lights.d.ts.map +1 -1
  38. package/dist/irdevices/lights.js +0 -1
  39. package/dist/irdevices/lights.js.map +1 -1
  40. package/dist/irdevices/others.d.ts.map +1 -1
  41. package/dist/irdevices/others.js +0 -1
  42. package/dist/irdevices/others.js.map +1 -1
  43. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  44. package/dist/irdevices/vacuumcleaners.js +2 -3
  45. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  46. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  47. package/dist/irdevices/waterheaters.js +0 -1
  48. package/dist/irdevices/waterheaters.js.map +1 -1
  49. package/dist/platform.d.ts.map +1 -1
  50. package/dist/platform.js +34 -25
  51. package/dist/platform.js.map +1 -1
  52. package/dist/settings.d.ts +4 -0
  53. package/dist/settings.d.ts.map +1 -1
  54. package/dist/settings.js +557 -1
  55. package/dist/settings.js.map +1 -1
  56. package/package.json +10 -12
  57. package/src/devices/bots.ts +24 -23
  58. package/src/devices/colorbulb.ts +130 -29
  59. package/src/devices/curtains.ts +17 -12
  60. package/src/devices/humidifiers.ts +0 -1
  61. package/src/devices/indoorcam.ts +0 -1
  62. package/src/devices/plugs.ts +0 -1
  63. package/src/irdevices/airconditioners.ts +0 -1
  64. package/src/irdevices/airpurifiers.ts +0 -1
  65. package/src/irdevices/cameras.ts +0 -1
  66. package/src/irdevices/fans.ts +0 -1
  67. package/src/irdevices/lights.ts +0 -1
  68. package/src/irdevices/others.ts +0 -1
  69. package/src/irdevices/vacuumcleaners.ts +2 -3
  70. package/src/irdevices/waterheaters.ts +0 -1
  71. package/src/platform.ts +34 -25
  72. package/src/settings.ts +557 -1
  73. package/src/colorbulb.json +0 -22
@@ -17,7 +17,7 @@ export class Bot {
17
17
  private batteryService?: Service;
18
18
 
19
19
  // Characteristic Values
20
- SwitchOn!: CharacteristicValue;
20
+ On!: CharacteristicValue;
21
21
  BatteryLevel!: CharacteristicValue;
22
22
  StatusLowBattery!: CharacteristicValue;
23
23
 
@@ -49,7 +49,7 @@ export class Bot {
49
49
  + ` deviceType: ${device.bot?.deviceType})`);
50
50
 
51
51
  // default placeholders
52
- this.SwitchOn = false;
52
+ this.On = false;
53
53
  this.BatteryLevel = 100;
54
54
  this.StatusLowBattery = 1;
55
55
 
@@ -173,7 +173,9 @@ export class Bot {
173
173
  if (this.mode) {
174
174
  this.platform.device(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}`);
175
175
  }
176
- this.SwitchOn = Boolean(this.state);
176
+ this.On = Boolean(this.state);
177
+ this.platform.log.error(`Bot: ${this.accessory.displayName} On: ${JSON.stringify(this.On)}`);
178
+
177
179
  this.BatteryLevel = Number(this.battery);
178
180
  if (this.BatteryLevel < 10) {
179
181
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
@@ -183,16 +185,16 @@ export class Bot {
183
185
  if (Number.isNaN(this.BatteryLevel)) {
184
186
  this.BatteryLevel = 100;
185
187
  }
186
- this.platform.debug(`Bot: ${this.accessory.displayName} On: ${this.SwitchOn}, BatteryLevel: ${this.BatteryLevel}`);
188
+ this.platform.debug(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
187
189
  }
188
190
 
189
191
  private async openAPIparseStatus() {
190
192
  if (this.platform.config.credentials?.openToken) {
191
193
  this.platform.debug(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
192
194
  if (this.device.bot?.mode === 'press') {
193
- this.SwitchOn = false;
195
+ this.On = false;
194
196
  }
195
- this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.SwitchOn}`);
197
+ this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.On}`);
196
198
  }
197
199
  }
198
200
 
@@ -314,7 +316,7 @@ export class Bot {
314
316
  if (this.device.bot?.mode === 'press') {
315
317
  this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
316
318
  switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
317
- this.platform.log.info(`Bot: ${this.accessory.displayName}, On: ${this.SwitchOn}`);
319
+ this.platform.log.info(`Bot: ${this.accessory.displayName}, On: ${this.On}`);
318
320
  return device_list[0].press({ id: this.device.bleMac });
319
321
  }).then(() => {
320
322
  this.platform.device(`Bot: ${this.accessory.displayName} Done.`);
@@ -336,7 +338,7 @@ export class Bot {
336
338
  } else if (this.device.bot?.mode === 'switch') {
337
339
  this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
338
340
  switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
339
- this.platform.log.info(`Bot: ${this.accessory.displayName} On: ${this.SwitchOn}`);
341
+ this.platform.log.info(`Bot: ${this.accessory.displayName} On: ${this.On}`);
340
342
  return this.turnOnOff(device_list);
341
343
  }).then(() => {
342
344
  this.platform.device(`Bot: ${this.accessory.displayName} Done.`);
@@ -361,7 +363,7 @@ export class Bot {
361
363
  }
362
364
 
363
365
  private turnOnOff(device_list: any) {
364
- if (this.SwitchOn) {
366
+ if (this.On) {
365
367
  return device_list[0].turnOn({ id: this.device.bleMac });
366
368
  } else {
367
369
  return device_list[0].turnOff({ id: this.device.bleMac });
@@ -377,18 +379,18 @@ export class Bot {
377
379
  parameter: 'default',
378
380
  } as payload;
379
381
 
380
- if (this.device.bot?.mode === 'switch' && this.SwitchOn) {
382
+ if (this.device.bot?.mode === 'switch' && this.On) {
381
383
  payload.command = 'turnOn';
382
- this.SwitchOn = true;
383
- this.platform.debug(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.SwitchOn}`);
384
- } else if (this.device.bot?.mode === 'switch' && !this.SwitchOn) {
384
+ this.On = true;
385
+ this.platform.debug(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
386
+ } else if (this.device.bot?.mode === 'switch' && !this.On) {
385
387
  payload.command = 'turnOff';
386
- this.SwitchOn = false;
387
- this.platform.debug(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.SwitchOn}`);
388
+ this.On = false;
389
+ this.platform.debug(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
388
390
  } else if (this.device.bot?.mode === 'press') {
389
391
  payload.command = 'press';
390
392
  this.platform.debug(`Bot: ${this.accessory.displayName} Press Mode`);
391
- this.SwitchOn = false;
393
+ this.On = false;
392
394
  } else {
393
395
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
394
396
  }
@@ -418,15 +420,15 @@ export class Bot {
418
420
  * Updates the status for each of the HomeKit Characteristics
419
421
  */
420
422
  updateHomeKitCharacteristics() {
421
- if (this.SwitchOn === undefined) {
422
- this.platform.debug(`Bot: ${this.accessory.displayName} On: ${this.SwitchOn}`);
423
+ if (this.On === undefined) {
424
+ this.platform.debug(`Bot: ${this.accessory.displayName} On: ${this.On}`);
423
425
  } else {
424
426
  if (this.device.bot?.deviceType === 'switch') {
425
- this.switchService!.updateCharacteristic(this.platform.Characteristic.On, this.SwitchOn);
427
+ this.switchService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
426
428
  } else {
427
- this.outletService!.updateCharacteristic(this.platform.Characteristic.On, this.SwitchOn);
429
+ this.outletService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
428
430
  }
429
- this.platform.device(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.SwitchOn}`);
431
+ this.platform.device(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
430
432
  }
431
433
  if (this.device.ble) {
432
434
  if (this.BatteryLevel === undefined) {
@@ -474,7 +476,6 @@ export class Bot {
474
476
  this.platform.log.error(`Bot: ${this.accessory.displayName} Hub Device is offline.`);
475
477
  break;
476
478
  case 190:
477
- // eslint-disable-next-line max-len
478
479
  this.platform.log.error(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
479
480
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
480
481
  break;
@@ -491,7 +492,7 @@ export class Bot {
491
492
  */
492
493
  private handleOnSet(value: CharacteristicValue) {
493
494
  this.platform.debug(`Bot: ${this.accessory.displayName} On: ${value}`);
494
- this.SwitchOn = value;
495
+ this.On = value;
495
496
  this.doBotUpdate.next();
496
497
  }
497
498
  }
@@ -2,10 +2,8 @@ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
- import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload } from '../settings';
5
+ import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs } from '../settings';
6
6
  import { AxiosResponse } from 'axios';
7
- import hsvToRgb from '@fantasy-color/hsv-to-rgb';
8
- import rgbToHsv from '@fantasy-color/rgb-to-hsv';
9
7
 
10
8
  /**
11
9
  * Platform Accessory
@@ -187,16 +185,40 @@ export class ColorBulb {
187
185
  default:
188
186
  this.On = false;
189
187
  }
190
- this.platform.debug(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
191
- this.Brightness = Number(this.deviceStatus.body.brightness);
192
-
188
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
193
189
 
194
- rgbToHsv({red: 60, green: 32, blue: 23});
190
+ // Brightness
191
+ this.Brightness = Number(this.deviceStatus.body.brightness);
192
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
193
+
194
+ // Color, Hue & Brightness
195
+ if (this.deviceStatus.body.color) {
196
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.deviceStatus.body.color)}`);
197
+ const [red, green, blue] = this.deviceStatus.body.color!.split(':');
198
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
199
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
200
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
201
+
202
+ const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
203
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
204
+
205
+ // Hue
206
+ this.Hue = hue;
207
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
208
+
209
+ // Saturation
210
+ this.Saturation = saturation;
211
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
212
+ }
195
213
 
214
+ // ColorTemperature
215
+ if (this.deviceStatus.body.colorTemperature) {
216
+ // Convert mired to kelvin to nearest 100 (Govee seems to need this)
217
+ const mired = Math.round(1000000 / this.deviceStatus.body.colorTemperature);
196
218
 
197
- //this.Hue = this.deviceStatus.body.color;
198
- //this.Saturation = this.deviceStatus.body.color;
199
- this.ColorTemperature = Number(this.deviceStatus.body.colorTemperature);
219
+ this.ColorTemperature = Number(mired);
220
+ this.platform.log.warn(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
221
+ }
200
222
  }
201
223
 
202
224
  async refreshStatus() {
@@ -221,32 +243,97 @@ export class ColorBulb {
221
243
 
222
244
  /**
223
245
  * Pushes the requested changes to the SwitchBot API
224
- * deviceType commandType Command command parameter Description
225
- * Color Bulb - "command" "turnOff" "default" = set to OFF state
226
- * Color Bulb - "command" "turnOn" "default" = set to ON state
246
+ * deviceType commandType Command command parameter Description
247
+ * Color Bulb - "command" "turnOff" "default" = set to OFF state
248
+ * Color Bulb - "command" "turnOn" "default" = set to ON state
249
+ * Color Bulb - "command" "toggle" "default" = toggle state
250
+ * Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
251
+ * Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
252
+ * Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
227
253
  */
228
254
  async pushChanges() {
229
255
  try {
230
- // eslint-disable-next-line max-len
231
- this.platform.log.warn(JSON.stringify(hsvToRgb({ hue: Number(this.Hue), saturation: Number(this.Saturation), value: Number(this.Brightness) })));
232
- const payload = {
233
- commandType: 'command',
234
- parameter: 'default',
235
- } as payload;
256
+ // Push On Update
257
+ if (this.On) {
258
+ const payload = {
259
+ commandType: 'command',
260
+ parameter: 'default',
261
+ } as payload;
262
+
263
+ if (this.On) {
264
+ payload.command = 'turnOn';
265
+ } else {
266
+ payload.command = 'turnOff';
267
+ }
236
268
 
269
+ this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
270
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
271
+
272
+ // Make the API request
273
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
274
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
275
+ this.statusCode(push);
276
+ }
277
+
278
+ // Push Brightness Update
237
279
  if (this.On) {
238
- payload.command = 'turnOn';
239
- } else {
240
- payload.command = 'turnOff';
280
+ const payload = {
281
+ commandType: 'command',
282
+ command: 'setBrightness',
283
+ parameter: `{${this.Brightness}}`,
284
+ } as payload;
285
+
286
+ this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
287
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
288
+
289
+ // Make the API request
290
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
291
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
292
+ this.statusCode(push);
241
293
  }
242
294
 
243
- this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
244
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
295
+ // Push ColorTemperature Update
296
+ if (this.On) {
297
+ const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
298
+
299
+ const payload = {
300
+ commandType: 'command',
301
+ command: 'setColorTemperature',
302
+ parameter: `{${kelvin}}`,
303
+ } as payload;
304
+
305
+ this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
306
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
307
+
308
+ // Make the API request
309
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
310
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
311
+ this.statusCode(push);
312
+ }
313
+
314
+ // Push Hue & Saturation Update
315
+ if (this.On) {
316
+ this.platform.log.warn(JSON.stringify(this.Hue));
317
+ this.platform.log.warn(JSON.stringify(this.Saturation));
318
+
319
+ const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
320
+ this.platform.log.error(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
321
+
322
+ const payload = {
323
+ commandType: 'command',
324
+ command: 'setColor',
325
+ parameter: `{${red}}:{${green}}:{${blue}}`,
326
+ } as payload;
327
+
328
+ this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
329
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
330
+
331
+ // Make the API request
332
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
333
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
334
+ this.statusCode(push);
335
+ }
245
336
 
246
- // Make the API request
247
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
248
- this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
249
- this.statusCode(push);
250
337
  } catch (e: any) {
251
338
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
252
339
  if (this.deviceDebug) {
@@ -279,11 +366,25 @@ export class ColorBulb {
279
366
  this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.ColorTemperature);
280
367
  this.platform.debug(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
281
368
  }
369
+ if (this.Hue === undefined) {
370
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
371
+ } else {
372
+ this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
373
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
374
+ }
375
+ if (this.Saturation === undefined) {
376
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
377
+ } else {
378
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
379
+ this.platform.debug(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
380
+ }
282
381
  }
283
382
 
284
383
  public apiError(e: any) {
285
384
  this.service.updateCharacteristic(this.platform.Characteristic.On, e);
385
+ this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
286
386
  this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
387
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
287
388
  this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
288
389
  }
289
390
 
@@ -305,7 +406,6 @@ export class ColorBulb {
305
406
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} Hub Device is offline.`);
306
407
  break;
307
408
  case 190:
308
- // eslint-disable-next-line max-len
309
409
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
310
410
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
311
411
  break;
@@ -367,3 +467,4 @@ export class ColorBulb {
367
467
  this.doColorBulbUpdate.next();
368
468
  }
369
469
  }
470
+
@@ -21,13 +21,8 @@ export class Curtain {
21
21
 
22
22
  // OpenAPI Others
23
23
  deviceStatus!: deviceStatusResponse;
24
- setNewTarget!: boolean;
25
- setNewTargetTimer!: NodeJS.Timeout;
26
24
 
27
25
  // BLE Others
28
- set_minLux!: number;
29
- set_maxLux!: number;
30
- spaceBetweenLevels!: number;
31
26
  switchbot!: switchbot;
32
27
  serviceData!: serviceData;
33
28
  calibration: serviceData['calibration'];
@@ -35,9 +30,16 @@ export class Curtain {
35
30
  position: serviceData['position'];
36
31
  lightLevel: serviceData['lightLevel'];
37
32
 
33
+ // Target
34
+ setNewTarget!: boolean;
35
+ setNewTargetTimer!: NodeJS.Timeout;
36
+
38
37
  // Config
39
38
  set_minStep!: number;
40
39
  refreshRate!: number;
40
+ set_minLux!: number;
41
+ set_maxLux!: number;
42
+ spaceBetweenLevels!: number;
41
43
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
42
44
  private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
43
45
 
@@ -245,14 +247,15 @@ export class Curtain {
245
247
 
246
248
  private async BLEparseStatus() {
247
249
  this.platform.debug(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
250
+ this.setMinMax();
248
251
  this.CurrentPosition = 100 - Number(this.position);
252
+ this.setMinMax();
249
253
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
250
254
  if (this.setNewTarget) {
251
255
  this.platform.log.info(`Curtain: ${this.accessory.displayName} Checking Status ...`);
252
256
  }
253
257
 
254
258
  if (this.setNewTarget) {
255
- this.setMinMax();
256
259
  if (this.TargetPosition > this.CurrentPosition) {
257
260
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
258
261
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -340,14 +343,15 @@ export class Curtain {
340
343
  if (this.platform.config.credentials?.openToken) {
341
344
  this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
342
345
  // CurrentPosition
346
+ this.setMinMax();
343
347
  this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
348
+ this.setMinMax();
344
349
  this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
345
350
  if (this.setNewTarget) {
346
351
  this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
347
352
  }
348
353
 
349
354
  if (this.deviceStatus.body.moving) {
350
- this.setMinMax();
351
355
  if (this.TargetPosition > this.CurrentPosition) {
352
356
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
353
357
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -417,6 +421,7 @@ export class Curtain {
417
421
  }).then(() => {
418
422
  // Stop to monitor
419
423
  switchbot.stopScan();
424
+ this.setMinMax();
420
425
  this.parseStatus();
421
426
  this.updateHomeKitCharacteristics();
422
427
  }).catch(async (e: any) => {
@@ -432,6 +437,7 @@ export class Curtain {
432
437
  if (this.platform.config.credentials?.openToken) {
433
438
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
434
439
  await this.openAPIRefreshStatus();
440
+ this.apiError(e);
435
441
  }
436
442
  });
437
443
  }
@@ -442,6 +448,7 @@ export class Curtain {
442
448
  try {
443
449
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
444
450
  this.platform.debug(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
+ this.setMinMax();
445
452
  this.parseStatus();
446
453
  this.updateHomeKitCharacteristics();
447
454
  } catch (e: any) {
@@ -603,7 +610,6 @@ export class Curtain {
603
610
  this.platform.log.error(`Curtain: ${this.accessory.displayName} Hub Device is offline.`);
604
611
  break;
605
612
  case 190:
606
- // eslint-disable-next-line max-len
607
613
  this.platform.log.error(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
608
614
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
609
615
  break;
@@ -623,19 +629,18 @@ export class Curtain {
623
629
 
624
630
  this.TargetPosition = value;
625
631
 
626
- this.setMinMax();
627
632
  if (value > this.CurrentPosition) {
628
633
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
629
634
  this.setNewTarget = true;
630
- //this.setMinMax();
635
+ this.setMinMax();
631
636
  } else if (value < this.CurrentPosition) {
632
637
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
633
638
  this.setNewTarget = true;
634
- //this.setMinMax();
639
+ this.setMinMax();
635
640
  } else {
636
641
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
637
642
  this.setNewTarget = false;
638
- //this.setMinMax();
643
+ this.setMinMax();
639
644
  }
640
645
  this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
641
646
 
@@ -617,7 +617,6 @@ export class Humidifier {
617
617
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} Hub Device is offline.`);
618
618
  break;
619
619
  case 190:
620
- // eslint-disable-next-line max-len
621
620
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
622
621
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
623
622
  break;
@@ -205,7 +205,6 @@ export class IndoorCam {
205
205
  this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} Hub Device is offline.`);
206
206
  break;
207
207
  case 190:
208
- // eslint-disable-next-line max-len
209
208
  this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
210
209
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
211
210
  break;
@@ -203,7 +203,6 @@ export class Plug {
203
203
  this.platform.log.error(`Plug: ${this.accessory.displayName} Hub Device is offline.`);
204
204
  break;
205
205
  case 190:
206
- // eslint-disable-next-line max-len
207
206
  this.platform.log.error(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
208
207
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
209
208
  break;
@@ -373,7 +373,6 @@ export class AirConditioner {
373
373
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} Hub Device is offline.`);
374
374
  break;
375
375
  case 190:
376
- // eslint-disable-next-line max-len
377
376
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
378
377
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
379
378
  break;
@@ -242,7 +242,6 @@ export class AirPurifier {
242
242
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} Hub Device is offline.`);
243
243
  break;
244
244
  case 190:
245
- // eslint-disable-next-line max-len
246
245
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
247
246
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
248
247
  break;
@@ -142,7 +142,6 @@ export class Camera {
142
142
  this.platform.log.error(`Camera: ${this.accessory.displayName} Hub Device is offline.`);
143
143
  break;
144
144
  case 190:
145
- // eslint-disable-next-line max-len
146
145
  this.platform.log.error(`Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
147
146
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
148
147
  break;
@@ -264,7 +264,6 @@ export class Fan {
264
264
  this.platform.log.error(`Fan: ${this.accessory.displayName} Hub Device is offline.`);
265
265
  break;
266
266
  case 190:
267
- // eslint-disable-next-line max-len
268
267
  this.platform.log.error(`Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
269
268
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
270
269
  break;
@@ -176,7 +176,6 @@ export class Light {
176
176
  this.platform.log.error(`Light: ${this.accessory.displayName} Hub Device is offline.`);
177
177
  break;
178
178
  case 190:
179
- // eslint-disable-next-line max-len
180
179
  this.platform.log.error(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
181
180
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
182
181
  break;
@@ -163,7 +163,6 @@ export class Others {
163
163
  this.platform.log.error(`Other: ${this.accessory.displayName} Hub Device is offline.`);
164
164
  break;
165
165
  case 190:
166
- // eslint-disable-next-line max-len
167
166
  this.platform.log.error(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
168
167
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
169
168
  break;
@@ -142,9 +142,8 @@ export class VacuumCleaner {
142
142
  this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline.`);
143
143
  break;
144
144
  case 190:
145
- // eslint-disable-next-line max-len
146
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
147
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
145
+ this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
146
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
148
147
  break;
149
148
  case 100:
150
149
  this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
@@ -156,7 +156,6 @@ export class WaterHeater {
156
156
  this.platform.log.error(`Water Heater: ${this.accessory.displayName} Hub Device is offline.`);
157
157
  break;
158
158
  case 190:
159
- // eslint-disable-next-line max-len
160
159
  this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
161
160
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
162
161
  break;