@switchbot/homebridge-switchbot 1.1.1-beta.7 → 1.2.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +67 -28
  3. package/config.schema.json +46 -43
  4. package/dist/devices/bots.d.ts +2 -0
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +118 -68
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +19 -3
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +190 -31
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/contact.d.ts +2 -0
  13. package/dist/devices/contact.d.ts.map +1 -1
  14. package/dist/devices/contact.js +22 -5
  15. package/dist/devices/contact.js.map +1 -1
  16. package/dist/devices/curtains.d.ts +5 -3
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +76 -26
  19. package/dist/devices/curtains.js.map +1 -1
  20. package/dist/devices/humidifiers.d.ts +2 -0
  21. package/dist/devices/humidifiers.d.ts.map +1 -1
  22. package/dist/devices/humidifiers.js +84 -27
  23. package/dist/devices/humidifiers.js.map +1 -1
  24. package/dist/devices/indoorcam.d.ts +2 -0
  25. package/dist/devices/indoorcam.d.ts.map +1 -1
  26. package/dist/devices/indoorcam.js +23 -7
  27. package/dist/devices/indoorcam.js.map +1 -1
  28. package/dist/devices/meters.d.ts +2 -0
  29. package/dist/devices/meters.d.ts.map +1 -1
  30. package/dist/devices/meters.js +21 -3
  31. package/dist/devices/meters.js.map +1 -1
  32. package/dist/devices/motion.d.ts +2 -0
  33. package/dist/devices/motion.d.ts.map +1 -1
  34. package/dist/devices/motion.js +21 -3
  35. package/dist/devices/motion.js.map +1 -1
  36. package/dist/devices/plugs.d.ts +2 -0
  37. package/dist/devices/plugs.d.ts.map +1 -1
  38. package/dist/devices/plugs.js +23 -7
  39. package/dist/devices/plugs.js.map +1 -1
  40. package/dist/irdevices/airconditioners.d.ts +2 -0
  41. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  42. package/dist/irdevices/airconditioners.js +14 -5
  43. package/dist/irdevices/airconditioners.js.map +1 -1
  44. package/dist/irdevices/airpurifiers.d.ts +2 -0
  45. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  46. package/dist/irdevices/airpurifiers.js +14 -5
  47. package/dist/irdevices/airpurifiers.js.map +1 -1
  48. package/dist/irdevices/cameras.d.ts +2 -0
  49. package/dist/irdevices/cameras.d.ts.map +1 -1
  50. package/dist/irdevices/cameras.js +14 -5
  51. package/dist/irdevices/cameras.js.map +1 -1
  52. package/dist/irdevices/fans.d.ts +2 -0
  53. package/dist/irdevices/fans.d.ts.map +1 -1
  54. package/dist/irdevices/fans.js +13 -5
  55. package/dist/irdevices/fans.js.map +1 -1
  56. package/dist/irdevices/lights.d.ts +2 -0
  57. package/dist/irdevices/lights.d.ts.map +1 -1
  58. package/dist/irdevices/lights.js +14 -5
  59. package/dist/irdevices/lights.js.map +1 -1
  60. package/dist/irdevices/others.d.ts +2 -0
  61. package/dist/irdevices/others.d.ts.map +1 -1
  62. package/dist/irdevices/others.js +20 -11
  63. package/dist/irdevices/others.js.map +1 -1
  64. package/dist/irdevices/tvs.d.ts +2 -0
  65. package/dist/irdevices/tvs.d.ts.map +1 -1
  66. package/dist/irdevices/tvs.js +14 -4
  67. package/dist/irdevices/tvs.js.map +1 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts +2 -0
  69. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  70. package/dist/irdevices/vacuumcleaners.js +14 -5
  71. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  72. package/dist/irdevices/waterheaters.d.ts +2 -0
  73. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  74. package/dist/irdevices/waterheaters.js +14 -5
  75. package/dist/irdevices/waterheaters.js.map +1 -1
  76. package/dist/platform.d.ts +1 -0
  77. package/dist/platform.d.ts.map +1 -1
  78. package/dist/platform.js +35 -26
  79. package/dist/platform.js.map +1 -1
  80. package/dist/settings.d.ts +4 -0
  81. package/dist/settings.d.ts.map +1 -1
  82. package/dist/settings.js +557 -1
  83. package/dist/settings.js.map +1 -1
  84. package/package.json +6 -6
  85. package/src/devices/bots.ts +118 -69
  86. package/src/devices/colorbulb.ts +218 -33
  87. package/src/devices/contact.ts +23 -5
  88. package/src/devices/curtains.ts +80 -31
  89. package/src/devices/humidifiers.ts +85 -29
  90. package/src/devices/indoorcam.ts +24 -7
  91. package/src/devices/meters.ts +22 -3
  92. package/src/devices/motion.ts +22 -3
  93. package/src/devices/plugs.ts +24 -7
  94. package/src/irdevices/airconditioners.ts +15 -5
  95. package/src/irdevices/airpurifiers.ts +15 -5
  96. package/src/irdevices/cameras.ts +15 -5
  97. package/src/irdevices/fans.ts +13 -5
  98. package/src/irdevices/lights.ts +15 -5
  99. package/src/irdevices/others.ts +21 -11
  100. package/src/irdevices/tvs.ts +15 -4
  101. package/src/irdevices/vacuumcleaners.ts +15 -5
  102. package/src/irdevices/waterheaters.ts +15 -5
  103. package/src/platform.ts +36 -26
  104. package/src/settings.ts +557 -1
@@ -34,6 +34,10 @@ export class Contact {
34
34
  doorState!: serviceData['doorState'];
35
35
  lightLevel!: serviceData['lightLevel'];
36
36
 
37
+ // Config
38
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
39
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
40
+
37
41
  // Updates
38
42
  contactUbpdateInProgress!: boolean;
39
43
  doContactUpdate!: Subject<void>;
@@ -163,7 +167,7 @@ export class Contact {
163
167
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
164
168
  break;
165
169
  default:
166
- this.platform.log.error('timeout no closed');
170
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
167
171
  }
168
172
  if (this.device.contact?.hide_lightsensor) {// Light Level
169
173
  switch (this.lightLevel) {
@@ -256,7 +260,15 @@ export class Contact {
256
260
  this.parseStatus();
257
261
  this.updateHomeKitCharacteristics();
258
262
  }).catch(async (e: any) => {
259
- this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
263
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
264
+ if (this.deviceDebug) {
265
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
266
+ + ` Error Message: ${JSON.stringify(e.message)}`);
267
+ }
268
+ if (this.debugDebug) {
269
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
270
+ + ` Error: ${JSON.stringify(e)}`);
271
+ }
260
272
  if (this.platform.config.credentials?.openToken) {
261
273
  this.platform.log.warn(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
262
274
  await this.openAPIRefreshStatus();
@@ -273,9 +285,15 @@ export class Contact {
273
285
  this.parseStatus();
274
286
  this.updateHomeKitCharacteristics();
275
287
  } catch (e: any) {
276
- this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed to refresh status.`
277
- + ` Error Message: ${JSON.stringify(e.message)}`);
278
- this.platform.debug(`Contact Sensor: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
288
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
289
+ if (this.deviceDebug) {
290
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
291
+ + ` Error Message: ${JSON.stringify(e.message)}`);
292
+ }
293
+ if (this.debugDebug) {
294
+ this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
295
+ + ` Error: ${JSON.stringify(e)}`);
296
+ }
279
297
  this.apiError(e);
280
298
  }
281
299
  }
@@ -25,9 +25,6 @@ export class Curtain {
25
25
  setNewTargetTimer!: NodeJS.Timeout;
26
26
 
27
27
  // BLE Others
28
- set_minLux!: number;
29
- set_maxLux!: number;
30
- spaceBetweenLevels!: number;
31
28
  switchbot!: switchbot;
32
29
  serviceData!: serviceData;
33
30
  calibration: serviceData['calibration'];
@@ -38,6 +35,11 @@ export class Curtain {
38
35
  // Config
39
36
  set_minStep!: number;
40
37
  refreshRate!: number;
38
+ set_minLux!: number;
39
+ set_maxLux!: number;
40
+ spaceBetweenLevels!: number;
41
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
42
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
41
43
 
42
44
  // Updates
43
45
  curtainUpdateInProgress!: boolean;
@@ -168,9 +170,15 @@ export class Curtain {
168
170
  try {
169
171
  await this.pushChanges();
170
172
  } catch (e: any) {
171
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed to pushChanges,`
172
- + ` Error Message: ${JSON.stringify(e.message)}`);
173
- this.platform.debug(`Curtain: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
173
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges`);
174
+ if (this.deviceDebug) {
175
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
176
+ + ` Error Message: ${JSON.stringify(e.message)}`);
177
+ }
178
+ if (this.debugDebug) {
179
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
180
+ + ` Error: ${JSON.stringify(e)}`);
181
+ }
174
182
  this.apiError(e);
175
183
  }
176
184
  this.curtainUpdateInProgress = false;
@@ -237,6 +245,7 @@ export class Curtain {
237
245
 
238
246
  private async BLEparseStatus() {
239
247
  this.platform.debug(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
248
+ this.setMinMax();
240
249
  this.CurrentPosition = 100 - Number(this.position);
241
250
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
242
251
  if (this.setNewTarget) {
@@ -332,6 +341,7 @@ export class Curtain {
332
341
  if (this.platform.config.credentials?.openToken) {
333
342
  this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
334
343
  // CurrentPosition
344
+ this.setMinMax();
335
345
  this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
336
346
  this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
337
347
  if (this.setNewTarget) {
@@ -412,7 +422,15 @@ export class Curtain {
412
422
  this.parseStatus();
413
423
  this.updateHomeKitCharacteristics();
414
424
  }).catch(async (e: any) => {
415
- this.platform.log.error(`Curtain: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
425
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
426
+ if (this.deviceDebug) {
427
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
428
+ + ` Error Message: ${JSON.stringify(e.message)}`);
429
+ }
430
+ if (this.debugDebug) {
431
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
432
+ + ` Error: ${JSON.stringify(e)}`);
433
+ }
416
434
  if (this.platform.config.credentials?.openToken) {
417
435
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
418
436
  await this.openAPIRefreshStatus();
@@ -429,8 +447,15 @@ export class Curtain {
429
447
  this.parseStatus();
430
448
  this.updateHomeKitCharacteristics();
431
449
  } catch (e: any) {
432
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed to refresh status, Error Message ${JSON.stringify(e.message)}`);
433
- this.platform.debug(`Curtain: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
450
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
451
+ if (this.deviceDebug) {
452
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
453
+ + ` Error Message: ${JSON.stringify(e.message)}`);
454
+ }
455
+ if (this.debugDebug) {
456
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
457
+ + ` Error: ${JSON.stringify(e)}`);
458
+ }
434
459
  this.apiError(e);
435
460
  }
436
461
  }
@@ -454,31 +479,53 @@ export class Curtain {
454
479
  }).then(() => {
455
480
  this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
456
481
  }).catch(async (e: any) => {
457
- this.platform.log.error(`Curtain: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
458
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
459
- await this.OpenAPIpushChanges();
482
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
483
+ if (this.deviceDebug) {
484
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
485
+ + ` Error Message: ${JSON.stringify(e.message)}`);
486
+ }
487
+ if (this.debugDebug) {
488
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
489
+ + ` Error: ${JSON.stringify(e)}`);
490
+ }
491
+ if (this.platform.config.credentials?.openToken) {
492
+ this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
493
+ await this.OpenAPIpushChanges();
494
+ }
460
495
  });
461
496
  }
462
497
 
463
498
  private async OpenAPIpushChanges() {
464
499
  if (this.platform.config.credentials?.openToken) {
465
- this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
466
- if (this.TargetPosition !== this.CurrentPosition) {
467
- this.platform.debug(`Pushing ${this.TargetPosition}`);
468
- const adjustedTargetPosition = 100 - Number(this.TargetPosition);
469
- const payload = {
470
- commandType: 'command',
471
- command: 'setPosition',
472
- parameter: `0,ff,${adjustedTargetPosition}`,
473
- } as payload;
474
-
475
- this.platform.log.info(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
476
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
477
-
478
- // Make the API request
479
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
480
- this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
481
- this.statusCode(push);
500
+ try {
501
+ this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
502
+ if (this.TargetPosition !== this.CurrentPosition) {
503
+ this.platform.debug(`Pushing ${this.TargetPosition}`);
504
+ const adjustedTargetPosition = 100 - Number(this.TargetPosition);
505
+ const payload = {
506
+ commandType: 'command',
507
+ command: 'setPosition',
508
+ parameter: `0,ff,${adjustedTargetPosition}`,
509
+ } as payload;
510
+
511
+ this.platform.log.info(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
512
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
513
+
514
+ // Make the API request
515
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
516
+ this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
517
+ this.statusCode(push);
518
+ }
519
+ } catch (e: any) {
520
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
521
+ if (this.deviceDebug) {
522
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
523
+ + ` Error Message: ${JSON.stringify(e.message)}`);
524
+ }
525
+ if (this.debugDebug) {
526
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
527
+ + ` Error: ${JSON.stringify(e)}`);
528
+ }
482
529
  }
483
530
  }
484
531
  }
@@ -558,8 +605,8 @@ export class Curtain {
558
605
  this.platform.log.error(`Curtain: ${this.accessory.displayName} Hub Device is offline.`);
559
606
  break;
560
607
  case 190:
561
- // eslint-disable-next-line max-len
562
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server. Or command fomrat is invalid.`);
608
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
609
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
563
610
  break;
564
611
  case 100:
565
612
  this.platform.debug(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
@@ -611,11 +658,13 @@ export class Curtain {
611
658
  if (this.device.curtain?.set_min) {
612
659
  if (this.CurrentPosition <= this.device.curtain?.set_min) {
613
660
  this.CurrentPosition = 0;
661
+ this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
614
662
  }
615
663
  }
616
664
  if (this.device.curtain?.set_max) {
617
665
  if (this.CurrentPosition >= this.device.curtain?.set_max) {
618
666
  this.CurrentPosition = 100;
667
+ this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
619
668
  }
620
669
  }
621
670
  }
@@ -35,6 +35,8 @@ export class Humidifier {
35
35
 
36
36
  // Config
37
37
  set_minStep?: number;
38
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
39
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
38
40
 
39
41
  // Updates
40
42
  humidifierUpdateInProgress!: boolean;
@@ -171,9 +173,15 @@ export class Humidifier {
171
173
  try {
172
174
  await this.pushChanges();
173
175
  } catch (e: any) {
174
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed to pushChanges,`
175
- + ` Error Message: ${JSON.stringify(e.message)}`);
176
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
176
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
177
+ if (this.deviceDebug) {
178
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
179
+ + ` Error Message: ${JSON.stringify(e.message)}`);
180
+ }
181
+ if (this.debugDebug) {
182
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
183
+ + ` Error: ${JSON.stringify(e)}`);
184
+ }
177
185
  this.apiError(e);
178
186
  }
179
187
  this.humidifierUpdateInProgress = false;
@@ -319,7 +327,15 @@ export class Humidifier {
319
327
  this.parseStatus();
320
328
  this.updateHomeKitCharacteristics();
321
329
  }).catch(async (e: any) => {
322
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
330
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
331
+ if (this.deviceDebug) {
332
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
333
+ + ` Error Message: ${JSON.stringify(e.message)}`);
334
+ }
335
+ if (this.debugDebug) {
336
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
337
+ + ` Error: ${JSON.stringify(e)}`);
338
+ }
323
339
  if (this.platform.config.credentials?.openToken) {
324
340
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
325
341
  await this.openAPIRefreshStatus();
@@ -340,8 +356,15 @@ export class Humidifier {
340
356
  this.platform.debug(this.deviceStatus);
341
357
  }
342
358
  } catch (e: any) {
343
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Failed to update status. Error Message: ${JSON.stringify(e.message)}`);
344
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
359
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
360
+ if (this.deviceDebug) {
361
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
362
+ + ` Error Message: ${JSON.stringify(e.message)}`);
363
+ }
364
+ if (this.debugDebug) {
365
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
366
+ + ` Error: ${JSON.stringify(e)}`);
367
+ }
345
368
  this.apiError(e);
346
369
  }
347
370
  }
@@ -368,7 +391,15 @@ export class Humidifier {
368
391
  }).then(() => {
369
392
  this.platform.device(`Humidifier: ${this.accessory.displayName} Done.`);
370
393
  }).catch(async (e: any) => {
371
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
394
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
395
+ if (this.deviceDebug) {
396
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
397
+ + ` Error Message: ${JSON.stringify(e.message)}`);
398
+ }
399
+ if (this.debugDebug) {
400
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
401
+ + ` Error: ${JSON.stringify(e)}`);
402
+ }
372
403
  if (this.platform.config.credentials?.openToken) {
373
404
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
374
405
  await this.OpenAPIpushChanges();
@@ -384,20 +415,33 @@ export class Humidifier {
384
415
  this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
385
416
  this.Active === this.platform.Characteristic.Active.ACTIVE
386
417
  ) {
387
- this.platform.debug(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
388
- const payload = {
389
- commandType: 'command',
390
- command: 'setMode',
391
- parameter: `${this.RelativeHumidityHumidifierThreshold}`,
392
- } as payload;
393
-
394
- this.platform.log.info(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
395
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
396
-
397
- // Make the API request
398
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
399
- this.platform.debug(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
400
- this.statusCode(push);
418
+ try {
419
+ this.platform.debug(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
420
+ const payload = {
421
+ commandType: 'command',
422
+ command: 'setMode',
423
+ parameter: `${this.RelativeHumidityHumidifierThreshold}`,
424
+ } as payload;
425
+
426
+ this.platform.log.info(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
427
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
428
+
429
+ // Make the API request
430
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
431
+ this.platform.debug(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
432
+ this.statusCode(push);
433
+ } catch (e: any) {
434
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
435
+ if (this.deviceDebug) {
436
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
437
+ + ` Error Message: ${JSON.stringify(e.message)}`);
438
+ }
439
+ if (this.debugDebug) {
440
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
441
+ + ` Error: ${JSON.stringify(e)}`);
442
+ }
443
+ this.apiError(e);
444
+ }
401
445
  } else if (
402
446
  this.TargetHumidifierDehumidifierState ===
403
447
  this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
@@ -436,9 +480,15 @@ export class Humidifier {
436
480
  this.statusCode(push);
437
481
  }
438
482
  } catch (e: any) {
439
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed to pushAutoChanges,`
440
- + ` Error Message: ${JSON.stringify(e.message)}`);
441
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
483
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
484
+ if (this.deviceDebug) {
485
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
486
+ + ` Error Message: ${JSON.stringify(e.message)}`);
487
+ }
488
+ if (this.debugDebug) {
489
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
490
+ + ` Error: ${JSON.stringify(e)}`);
491
+ }
442
492
  this.apiError(e);
443
493
  }
444
494
  }
@@ -465,9 +515,15 @@ export class Humidifier {
465
515
  this.statusCode(push);
466
516
  }
467
517
  } catch (e: any) {
468
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed to pushActiveChanges,`
469
- + ` Error Message: ${JSON.stringify(e.message)}`);
470
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
518
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
519
+ if (this.deviceDebug) {
520
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
521
+ + ` Error Message: ${JSON.stringify(e.message)}`);
522
+ }
523
+ if (this.debugDebug) {
524
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
525
+ + ` Error: ${JSON.stringify(e)}`);
526
+ }
471
527
  this.apiError(e);
472
528
  }
473
529
  }
@@ -561,8 +617,8 @@ export class Humidifier {
561
617
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} Hub Device is offline.`);
562
618
  break;
563
619
  case 190:
564
- // eslint-disable-next-line max-len
565
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server. Or command fomrat is invalid.`);
620
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
621
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
566
622
  break;
567
623
  case 100:
568
624
  this.platform.debug(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
@@ -16,6 +16,10 @@ export class IndoorCam {
16
16
  // OpenAPI Others
17
17
  deviceStatus!: deviceStatusResponse;
18
18
 
19
+ // Config
20
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
21
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
22
+
19
23
  // Updates
20
24
  cameraUpdateInProgress!: boolean;
21
25
  doCameraUpdate!: Subject<void>;
@@ -88,9 +92,15 @@ export class IndoorCam {
88
92
  try {
89
93
  await this.pushChanges();
90
94
  } catch (e: any) {
91
- this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed to pushChanges,`
92
- + ` Error Message: ${JSON.stringify(e.message)}`);
93
- this.platform.debug(`Indoor Cam: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
95
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed pushChanges`);
96
+ if (this.deviceDebug) {
97
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed pushChanges,`
98
+ + ` Error Message: ${JSON.stringify(e.message)}`);
99
+ }
100
+ if (this.debugDebug) {
101
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed pushChanges,`
102
+ + ` Error: ${JSON.stringify(e)}`);
103
+ }
94
104
  this.apiError(e);
95
105
  }
96
106
  this.cameraUpdateInProgress = false;
@@ -116,8 +126,15 @@ export class IndoorCam {
116
126
  this.parseStatus();
117
127
  this.updateHomeKitCharacteristics();
118
128
  } catch (e: any) {
119
- this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed to refreshStatus, Error Message: ${JSON.stringify(e.message)}`);
120
- this.platform.debug(`Indoor Cam: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
129
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
130
+ if (this.deviceDebug) {
131
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
132
+ + ` Error Message: ${JSON.stringify(e.message)}`);
133
+ }
134
+ if (this.debugDebug) {
135
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
136
+ + ` Error: ${JSON.stringify(e)}`);
137
+ }
121
138
  this.apiError(e);
122
139
  }
123
140
  }
@@ -188,8 +205,8 @@ export class IndoorCam {
188
205
  this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} Hub Device is offline.`);
189
206
  break;
190
207
  case 190:
191
- // eslint-disable-next-line max-len
192
- this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} Device internal error due to device states not synchronized with server. Or command fomrat is invalid.`);
208
+ this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
209
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
193
210
  break;
194
211
  case 100:
195
212
  this.platform.debug(`Indoor Cam: ${this.accessory.displayName} Command successfully sent.`);
@@ -35,6 +35,10 @@ export class Meter {
35
35
  fahrenheit!: serviceData['fahrenheit'];
36
36
  temperature!: serviceData['temperature'];
37
37
 
38
+ // Config
39
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
40
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
41
+
38
42
  // Updates
39
43
  meterUpdateInProgress!: boolean;
40
44
  doMeterUpdate: Subject<void>;
@@ -274,7 +278,15 @@ export class Meter {
274
278
  this.parseStatus();
275
279
  this.updateHomeKitCharacteristics();
276
280
  }).catch(async (e: any) => {
277
- this.platform.log.error(`Meter: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
281
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
282
+ if (this.deviceDebug) {
283
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
284
+ + ` Error Message: ${JSON.stringify(e.message)}`);
285
+ }
286
+ if (this.debugDebug) {
287
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
288
+ + ` Error: ${JSON.stringify(e)}`);
289
+ }
278
290
  if (this.platform.config.credentials?.openToken) {
279
291
  this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
280
292
  await this.openAPIRefreshStatus();
@@ -291,8 +303,15 @@ export class Meter {
291
303
  this.parseStatus();
292
304
  this.updateHomeKitCharacteristics();
293
305
  } catch (e: any) {
294
- this.platform.log.error(`Meter: ${this.accessory.displayName} failed to refresh status, Error Message: ${JSON.stringify(e.message)}`);
295
- this.platform.debug(`Meter: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
306
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
307
+ if (this.deviceDebug) {
308
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
309
+ + ` Error Message: ${JSON.stringify(e.message)}`);
310
+ }
311
+ if (this.debugDebug) {
312
+ this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
313
+ + ` Error: ${JSON.stringify(e)}`);
314
+ }
296
315
  this.apiError(e);
297
316
  }
298
317
  }
@@ -31,6 +31,10 @@ export class Motion {
31
31
  movement!: serviceData['movement'];
32
32
  lightLevel!: serviceData['lightLevel'];
33
33
 
34
+ // Config
35
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
36
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
37
+
34
38
  // Updates
35
39
  motionUbpdateInProgress!: boolean;
36
40
  doMotionUpdate!: Subject<void>;
@@ -193,7 +197,15 @@ export class Motion {
193
197
  this.parseStatus();
194
198
  this.updateHomeKitCharacteristics();
195
199
  }).catch(async (e: any) => {
196
- this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} BLE Connection Failed: ${e.message}`);
200
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
201
+ if (this.deviceDebug) {
202
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
203
+ + ` Error Message: ${JSON.stringify(e.message)}`);
204
+ }
205
+ if (this.debugDebug) {
206
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
207
+ + ` Error: ${JSON.stringify(e)}`);
208
+ }
197
209
  if (this.platform.config.credentials?.openToken) {
198
210
  this.platform.log.warn(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
199
211
  await this.openAPIRefreshStatus();
@@ -210,8 +222,15 @@ export class Motion {
210
222
  this.parseStatus();
211
223
  this.updateHomeKitCharacteristics();
212
224
  } catch (e: any) {
213
- this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed to refreshStatus, Error Message: ${JSON.stringify(e.message)}`);
214
- this.platform.debug(`Motion Sensor: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
225
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
226
+ if (this.deviceDebug) {
227
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
228
+ + ` Error Message: ${JSON.stringify(e.message)}`);
229
+ }
230
+ if (this.debugDebug) {
231
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
232
+ + ` Error: ${JSON.stringify(e)}`);
233
+ }
215
234
  this.apiError(e);
216
235
  }
217
236
  }
@@ -16,6 +16,10 @@ export class Plug {
16
16
  // OpenAPI Others
17
17
  deviceStatus!: deviceStatusResponse;
18
18
 
19
+ // Config
20
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
21
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
22
+
19
23
  // Updates
20
24
  plugUpdateInProgress!: boolean;
21
25
  doPlugUpdate!: Subject<void>;
@@ -88,9 +92,15 @@ export class Plug {
88
92
  try {
89
93
  await this.pushChanges();
90
94
  } catch (e: any) {
91
- this.platform.log.error(`Plug: ${this.accessory.displayName} failed to pushChanges,`
92
- + ` Error Message: ${JSON.stringify(e.message)}`);
93
- this.platform.debug(`Plug: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
95
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed pushChanges`);
96
+ if (this.deviceDebug) {
97
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed pushChanges,`
98
+ + ` Error Message: ${JSON.stringify(e.message)}`);
99
+ }
100
+ if (this.debugDebug) {
101
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed pushChanges,`
102
+ + ` Error: ${JSON.stringify(e)}`);
103
+ }
94
104
  this.apiError(e);
95
105
  }
96
106
  this.plugUpdateInProgress = false;
@@ -115,8 +125,15 @@ export class Plug {
115
125
  this.parseStatus();
116
126
  this.updateHomeKitCharacteristics();
117
127
  } catch (e: any) {
118
- this.platform.log.error(`Plug: ${this.accessory.displayName} failed to refreshStatus, Error Message: ${JSON.stringify(e.message)}`);
119
- this.platform.debug(`Plug: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`);
128
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
129
+ if (this.deviceDebug) {
130
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
131
+ + ` Error Message: ${JSON.stringify(e.message)}`);
132
+ }
133
+ if (this.debugDebug) {
134
+ this.platform.log.error(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
135
+ + ` Error: ${JSON.stringify(e)}`);
136
+ }
120
137
  this.apiError(e);
121
138
  }
122
139
  }
@@ -186,8 +203,8 @@ export class Plug {
186
203
  this.platform.log.error(`Plug: ${this.accessory.displayName} Hub Device is offline.`);
187
204
  break;
188
205
  case 190:
189
- // eslint-disable-next-line max-len
190
- this.platform.log.error(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server. Or command fomrat is invalid.`);
206
+ this.platform.log.error(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
207
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
191
208
  break;
192
209
  case 100:
193
210
  this.platform.debug(`Plug: ${this.accessory.displayName} Command successfully sent.`);