@switchbot/homebridge-switchbot 1.1.1-beta.8 → 1.2.1-beta.1

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 +12 -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 +91 -39
  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 +7 -5
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +82 -32
  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 +7 -7
  85. package/src/devices/bots.ts +92 -40
  86. package/src/devices/colorbulb.ts +218 -33
  87. package/src/devices/contact.ts +23 -5
  88. package/src/devices/curtains.ts +90 -39
  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
@@ -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,18 @@ 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;
43
+ private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
44
+ private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
41
45
 
42
46
  // Updates
43
47
  curtainUpdateInProgress!: boolean;
@@ -168,9 +172,15 @@ export class Curtain {
168
172
  try {
169
173
  await this.pushChanges();
170
174
  } 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)}`);
175
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges`);
176
+ if (this.deviceDebug) {
177
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
178
+ + ` Error Message: ${JSON.stringify(e.message)}`);
179
+ }
180
+ if (this.debugDebug) {
181
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
182
+ + ` Error: ${JSON.stringify(e)}`);
183
+ }
174
184
  this.apiError(e);
175
185
  }
176
186
  this.curtainUpdateInProgress = false;
@@ -237,14 +247,15 @@ export class Curtain {
237
247
 
238
248
  private async BLEparseStatus() {
239
249
  this.platform.debug(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
250
+ this.setMinMax();
240
251
  this.CurrentPosition = 100 - Number(this.position);
252
+ this.setMinMax();
241
253
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
242
254
  if (this.setNewTarget) {
243
255
  this.platform.log.info(`Curtain: ${this.accessory.displayName} Checking Status ...`);
244
256
  }
245
257
 
246
258
  if (this.setNewTarget) {
247
- this.setMinMax();
248
259
  if (this.TargetPosition > this.CurrentPosition) {
249
260
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
250
261
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -332,14 +343,15 @@ export class Curtain {
332
343
  if (this.platform.config.credentials?.openToken) {
333
344
  this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
334
345
  // CurrentPosition
346
+ this.setMinMax();
335
347
  this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
348
+ this.setMinMax();
336
349
  this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
337
350
  if (this.setNewTarget) {
338
351
  this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
339
352
  }
340
353
 
341
354
  if (this.deviceStatus.body.moving) {
342
- this.setMinMax();
343
355
  if (this.TargetPosition > this.CurrentPosition) {
344
356
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
345
357
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -409,13 +421,23 @@ export class Curtain {
409
421
  }).then(() => {
410
422
  // Stop to monitor
411
423
  switchbot.stopScan();
424
+ this.setMinMax();
412
425
  this.parseStatus();
413
426
  this.updateHomeKitCharacteristics();
414
427
  }).catch(async (e: any) => {
415
- this.platform.log.error(`Curtain: ${this.accessory.displayName} BLE Connection failed, Error Message: ${JSON.stringify(e.message)}`);
428
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
429
+ if (this.deviceDebug) {
430
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
431
+ + ` Error Message: ${JSON.stringify(e.message)}`);
432
+ }
433
+ if (this.debugDebug) {
434
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
435
+ + ` Error: ${JSON.stringify(e)}`);
436
+ }
416
437
  if (this.platform.config.credentials?.openToken) {
417
438
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
418
439
  await this.openAPIRefreshStatus();
440
+ this.apiError(e);
419
441
  }
420
442
  });
421
443
  }
@@ -426,11 +448,19 @@ export class Curtain {
426
448
  try {
427
449
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
428
450
  this.platform.debug(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
+ this.setMinMax();
429
452
  this.parseStatus();
430
453
  this.updateHomeKitCharacteristics();
431
454
  } 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)}`);
455
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
456
+ if (this.deviceDebug) {
457
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
458
+ + ` Error Message: ${JSON.stringify(e.message)}`);
459
+ }
460
+ if (this.debugDebug) {
461
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
462
+ + ` Error: ${JSON.stringify(e)}`);
463
+ }
434
464
  this.apiError(e);
435
465
  }
436
466
  }
@@ -454,31 +484,53 @@ export class Curtain {
454
484
  }).then(() => {
455
485
  this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
456
486
  }).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();
487
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
488
+ if (this.deviceDebug) {
489
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
490
+ + ` Error Message: ${JSON.stringify(e.message)}`);
491
+ }
492
+ if (this.debugDebug) {
493
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
494
+ + ` Error: ${JSON.stringify(e)}`);
495
+ }
496
+ if (this.platform.config.credentials?.openToken) {
497
+ this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
498
+ await this.OpenAPIpushChanges();
499
+ }
460
500
  });
461
501
  }
462
502
 
463
503
  private async OpenAPIpushChanges() {
464
504
  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);
505
+ try {
506
+ this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
507
+ if (this.TargetPosition !== this.CurrentPosition) {
508
+ this.platform.debug(`Pushing ${this.TargetPosition}`);
509
+ const adjustedTargetPosition = 100 - Number(this.TargetPosition);
510
+ const payload = {
511
+ commandType: 'command',
512
+ command: 'setPosition',
513
+ parameter: `0,ff,${adjustedTargetPosition}`,
514
+ } as payload;
515
+
516
+ this.platform.log.info(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
517
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
518
+
519
+ // Make the API request
520
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
521
+ this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
522
+ this.statusCode(push);
523
+ }
524
+ } catch (e: any) {
525
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
526
+ if (this.deviceDebug) {
527
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
528
+ + ` Error Message: ${JSON.stringify(e.message)}`);
529
+ }
530
+ if (this.debugDebug) {
531
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
532
+ + ` Error: ${JSON.stringify(e)}`);
533
+ }
482
534
  }
483
535
  }
484
536
  }
@@ -558,8 +610,8 @@ export class Curtain {
558
610
  this.platform.log.error(`Curtain: ${this.accessory.displayName} Hub Device is offline.`);
559
611
  break;
560
612
  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.`);
613
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
614
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
563
615
  break;
564
616
  case 100:
565
617
  this.platform.debug(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
@@ -577,19 +629,18 @@ export class Curtain {
577
629
 
578
630
  this.TargetPosition = value;
579
631
 
580
- this.setMinMax();
581
632
  if (value > this.CurrentPosition) {
582
633
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
583
634
  this.setNewTarget = true;
584
- //this.setMinMax();
635
+ this.setMinMax();
585
636
  } else if (value < this.CurrentPosition) {
586
637
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
587
638
  this.setNewTarget = true;
588
- //this.setMinMax();
639
+ this.setMinMax();
589
640
  } else {
590
641
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
591
642
  this.setNewTarget = false;
592
- //this.setMinMax();
643
+ this.setMinMax();
593
644
  }
594
645
  this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
595
646
 
@@ -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.`);