@switchbot/homebridge-switchbot 1.7.1-beta.9 → 1.8.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 (92) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/config.schema.json +3 -3
  3. package/dist/devices/bots.d.ts +4 -3
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +42 -33
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +4 -3
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +38 -29
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +4 -3
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +42 -34
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +2 -1
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +24 -10
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +1 -0
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +20 -1
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +4 -3
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +46 -34
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +4 -3
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +42 -30
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +4 -3
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +42 -30
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +2 -1
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +19 -12
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +4 -3
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +23 -16
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +2 -1
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +19 -12
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +2 -1
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +19 -12
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +2 -1
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +19 -12
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +3 -2
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +23 -16
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +2 -1
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +19 -12
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +2 -1
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +19 -12
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +2 -1
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +19 -12
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/settings.d.ts +7 -1
  72. package/dist/settings.d.ts.map +1 -1
  73. package/dist/settings.js.map +1 -1
  74. package/package.json +71 -71
  75. package/src/devices/bots.ts +43 -35
  76. package/src/devices/colorbulb.ts +39 -31
  77. package/src/devices/contact.ts +43 -35
  78. package/src/devices/curtains.ts +26 -12
  79. package/src/devices/humidifiers.ts +21 -1
  80. package/src/devices/meters.ts +47 -34
  81. package/src/devices/motion.ts +43 -30
  82. package/src/devices/plugs.ts +43 -30
  83. package/src/irdevices/airconditioners.ts +20 -12
  84. package/src/irdevices/airpurifiers.ts +24 -16
  85. package/src/irdevices/cameras.ts +20 -12
  86. package/src/irdevices/fans.ts +20 -12
  87. package/src/irdevices/lights.ts +20 -12
  88. package/src/irdevices/others.ts +24 -16
  89. package/src/irdevices/tvs.ts +20 -12
  90. package/src/irdevices/vacuumcleaners.ts +20 -12
  91. package/src/irdevices/waterheaters.ts +20 -12
  92. package/src/settings.ts +7 -1
@@ -64,11 +64,11 @@ export class Bot {
64
64
  public device: device & devicesConfig,
65
65
  ) {
66
66
  // default placeholders
67
- this.logs();
68
- this.scan();
69
- this.refreshRate();
67
+ this.logs(device);
68
+ this.scan(device);
69
+ this.refreshRate(device);
70
70
  this.PressOrSwitch();
71
-
71
+ this.config(device);
72
72
  if (this.On === undefined) {
73
73
  this.On = false;
74
74
  this.accessory.context.On = this.On;
@@ -84,10 +84,6 @@ export class Bot {
84
84
  this.BatteryLevel = 100;
85
85
  this.StatusLowBattery = 0;
86
86
 
87
- // Bot Config
88
- this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
89
- + ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`);
90
-
91
87
  // this is subject we use to track when we need to POST changes to the SwitchBot API
92
88
  this.doBotUpdate = new Subject();
93
89
  this.botUpdateInProgress = false;
@@ -467,50 +463,62 @@ export class Bot {
467
463
  accessory.removeService(this.switchService!);
468
464
  }
469
465
 
470
- refreshRate() {
471
- if (this.device.refreshRate) {
472
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
473
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
474
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
475
- }
466
+ config(device: device & devicesConfig) {
467
+ const config: any = device.bot;
468
+ if (device.ble !== undefined) {
469
+ config['ble'] = device.ble;
470
+ }
471
+ if (device.logging !== undefined) {
472
+ config['logging'] = device.logging;
473
+ }
474
+ if (device.refreshRate !== undefined) {
475
+ config['refreshRate'] = device.refreshRate;
476
+ }
477
+ if (device.scanDuration !== undefined) {
478
+ config['scanDuration'] = device.scanDuration;
479
+ }
480
+ if (config !== undefined) {
481
+ this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
482
+ }
483
+ }
484
+
485
+ refreshRate(device: device & devicesConfig) {
486
+ if (device.refreshRate) {
487
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
488
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
476
489
  } else if (this.platform.config.options!.refreshRate) {
477
490
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
478
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
479
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
480
- }
491
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
481
492
  }
482
493
  }
483
494
 
484
- scan() {
485
- if (this.device.scanDuration) {
486
- this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
487
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
488
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
495
+ scan(device: device & devicesConfig) {
496
+ if (device.scanDuration) {
497
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
498
+ if (device.ble) {
499
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
489
500
  }
490
501
  } else {
491
502
  this.scanDuration = this.accessory.context.scanDuration = 1;
492
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
493
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
503
+ if (this.device.ble) {
504
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
494
505
  }
495
506
  }
496
507
  }
497
508
 
498
- logs() {
509
+ logs(device: device & devicesConfig) {
499
510
  if (this.platform.debugMode) {
500
- this.deviceLogging = this.accessory.context.logging = 'debug';
501
- this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
502
- } else if (this.device.logging) {
503
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
504
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
505
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
506
- }
511
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
512
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
513
+ } else if (device.logging) {
514
+ this.deviceLogging = this.accessory.context.logging = device.logging;
515
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
507
516
  } else if (this.platform.config.options?.logging) {
508
517
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
509
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
510
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
511
- }
518
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
512
519
  } else {
513
520
  this.deviceLogging = this.accessory.context.logging = 'standard';
521
+ this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
514
522
  }
515
523
  }
516
524
 
@@ -58,9 +58,10 @@ export class ColorBulb {
58
58
  public device: device & devicesConfig,
59
59
  ) {
60
60
  // default placeholders
61
- this.logs();
62
- this.refreshRate();
63
- this.adaptiveLighting();
61
+ this.logs(device);
62
+ this.refreshRate(device);
63
+ this.adaptiveLighting(device);
64
+ this.config(device);
64
65
  if (this.On === undefined) {
65
66
  this.On = false;
66
67
  } else {
@@ -72,11 +73,6 @@ export class ColorBulb {
72
73
  this.ColorTemperature = 140;
73
74
  this.minKelvin = 2000;
74
75
  this.maxKelvin = 9000;
75
-
76
- // ColorBulb Config
77
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep},`
78
- + ` adaptiveLighting: ${device.colorbulb?.adaptiveLightingShift})`);
79
-
80
76
  // this is subject we use to track when we need to POST changes to the SwitchBot API
81
77
  this.doColorBulbUpdate = new Subject();
82
78
  this.colorBulbUpdateInProgress = false;
@@ -218,42 +214,54 @@ export class ColorBulb {
218
214
  });
219
215
  }
220
216
 
221
- refreshRate() {
222
- if (this.device.refreshRate) {
223
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
224
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
225
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
226
- }
217
+ config(device: device & devicesConfig) {
218
+ const config: any = device.colorbulb;
219
+ if (device.ble !== undefined) {
220
+ config['ble'] = device.ble;
221
+ }
222
+ if (device.logging !== undefined) {
223
+ config['logging'] = device.logging;
224
+ }
225
+ if (device.refreshRate !== undefined) {
226
+ config['refreshRate'] = device.refreshRate;
227
+ }
228
+ if (device.scanDuration !== undefined) {
229
+ config['scanDuration'] = device.scanDuration;
230
+ }
231
+ if (config !== undefined) {
232
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
233
+ }
234
+ }
235
+
236
+ refreshRate(device: device & devicesConfig) {
237
+ if (device.refreshRate) {
238
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
239
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
227
240
  } else if (this.platform.config.options!.refreshRate) {
228
241
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
229
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
230
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
231
- }
242
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
232
243
  }
233
244
  }
234
245
 
235
- logs() {
246
+ logs(device: device & devicesConfig) {
236
247
  if (this.platform.debugMode) {
237
- this.deviceLogging = this.accessory.context.logging = 'debug';
238
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
239
- } else if (this.device.logging) {
240
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
241
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
242
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
243
- }
248
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
249
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
250
+ } else if (device.logging) {
251
+ this.deviceLogging = this.accessory.context.logging = device.logging;
252
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
244
253
  } else if (this.platform.config.options?.logging) {
245
254
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
246
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
247
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
248
- }
255
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
249
256
  } else {
250
257
  this.deviceLogging = this.accessory.context.logging = 'standard';
258
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
251
259
  }
252
260
  }
253
261
 
254
- adaptiveLighting() {
255
- if (this.device.colorbulb?.adaptiveLightingShift) {
256
- this.adaptiveLightingShift = this.device.colorbulb.adaptiveLightingShift;
262
+ adaptiveLighting(device: device & devicesConfig) {
263
+ if (device.colorbulb?.adaptiveLightingShift) {
264
+ this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
257
265
  this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
258
266
  } else {
259
267
  this.adaptiveLightingShift = 0;
@@ -56,16 +56,12 @@ export class Contact {
56
56
  public device: device & devicesConfig,
57
57
  ) {
58
58
  // default placeholders
59
- this.logs();
60
- this.scan();
61
- this.refreshRate();
59
+ this.logs(device);
60
+ this.scan(device);
61
+ this.refreshRate(device);
62
+ this.config(device);
62
63
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
63
64
 
64
- // Contact Config
65
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline},`
66
- + ` hide_lightsensor: ${device.contact?.hide_lightsensor}, hide_motionsensor: ${device.contact?.hide_motionsensor},`
67
- + ` set_minLux: ${this.device.contact?.set_minLux}, set_maxLux: ${this.device.contact?.set_maxLux})`);
68
-
69
65
  // this is subject we use to track when we need to POST changes to the SwitchBot API
70
66
  this.doContactUpdate = new Subject();
71
67
  this.contactUbpdateInProgress = false;
@@ -159,50 +155,62 @@ export class Contact {
159
155
  });
160
156
  }
161
157
 
162
- refreshRate() {
163
- if (this.device.refreshRate) {
164
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
165
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
166
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
167
- }
158
+ config(device: device & devicesConfig) {
159
+ const config: any = device.contact;
160
+ if (device.ble !== undefined) {
161
+ config['ble'] = device.ble;
162
+ }
163
+ if (device.logging !== undefined) {
164
+ config['logging'] = device.logging;
165
+ }
166
+ if (device.refreshRate !== undefined) {
167
+ config['refreshRate'] = device.refreshRate;
168
+ }
169
+ if (device.scanDuration !== undefined) {
170
+ config['scanDuration'] = device.scanDuration;
171
+ }
172
+ if (config !== undefined) {
173
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
174
+ }
175
+ }
176
+
177
+ refreshRate(device: device & devicesConfig) {
178
+ if (device.refreshRate) {
179
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
180
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
168
181
  } else if (this.platform.config.options!.refreshRate) {
169
182
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
170
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
171
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
172
- }
183
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
173
184
  }
174
185
  }
175
186
 
176
- scan() {
177
- if (this.device.scanDuration) {
178
- this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
179
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
180
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
187
+ scan(device: device & devicesConfig) {
188
+ if (device.scanDuration) {
189
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
190
+ if (device.ble) {
191
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
181
192
  }
182
193
  } else {
183
194
  this.scanDuration = this.accessory.context.scanDuration = 1;
184
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
185
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
195
+ if (this.device.ble) {
196
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
186
197
  }
187
198
  }
188
199
  }
189
200
 
190
- logs() {
201
+ logs(device: device & devicesConfig) {
191
202
  if (this.platform.debugMode) {
192
- this.deviceLogging = this.accessory.context.logging = 'debug';
193
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
194
- } else if (this.device.logging) {
195
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
196
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
197
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
198
- }
203
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
204
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
205
+ } else if (device.logging) {
206
+ this.deviceLogging = this.accessory.context.logging = device.logging;
207
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
199
208
  } else if (this.platform.config.options?.logging) {
200
209
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
201
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
202
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
203
- }
210
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
204
211
  } else {
205
212
  this.deviceLogging = this.accessory.context.logging = 'standard';
213
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
206
214
  }
207
215
  }
208
216
 
@@ -43,7 +43,7 @@ export class Curtain {
43
43
 
44
44
  // Config
45
45
  set_minStep!: number;
46
- curtainRefreshRate!: number;
46
+ updateRate!: number;
47
47
  set_minLux!: number;
48
48
  set_maxLux!: number;
49
49
  scanDuration!: number;
@@ -64,16 +64,11 @@ export class Curtain {
64
64
  this.scan();
65
65
  this.setMinMax();
66
66
  this.refreshRate();
67
+ this.config(device);
67
68
  this.CurrentPosition = 0;
68
69
  this.TargetPosition = 0;
69
70
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
70
71
 
71
- // Curtain Config
72
- this.debugLog(`Curtain: ${this.accessory.displayName} Config: (ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},`
73
- + ` hide_lightsensor: ${device.curtain?.hide_lightsensor}, set_minLux: ${device.curtain?.set_minLux}, set_maxLux: `
74
- + `${device.curtain?.set_maxLux}, refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: `
75
- + `${device.curtain?.set_min}, set_minStep: ${device.curtain?.set_minStep})`);
76
-
77
72
  // this is subject we use to track when we need to POST changes to the SwitchBot API
78
73
  this.doCurtainUpdate = new Subject();
79
74
  this.curtainUpdateInProgress = false;
@@ -175,7 +170,7 @@ export class Curtain {
175
170
  });
176
171
 
177
172
  // update slide progress
178
- interval(this.curtainRefreshRate * 1000)
173
+ interval(this.updateRate * 1000)
179
174
  .pipe(skipWhile(() => this.curtainUpdateInProgress))
180
175
  .subscribe(() => {
181
176
  if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
@@ -214,6 +209,25 @@ export class Curtain {
214
209
  });
215
210
  }
216
211
 
212
+ config(device: device & devicesConfig) {
213
+ const config: any = device.curtain;
214
+ if (device.ble !== undefined) {
215
+ config['ble'] = device.ble;
216
+ }
217
+ if (device.logging !== undefined) {
218
+ config['logging'] = device.logging;
219
+ }
220
+ if (device.refreshRate !== undefined) {
221
+ config['refreshRate'] = device.refreshRate;
222
+ }
223
+ if (device.scanDuration !== undefined) {
224
+ config['scanDuration'] = device.scanDuration;
225
+ }
226
+ if (config !== undefined) {
227
+ this.warnLog(`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
228
+ }
229
+ }
230
+
217
231
  refreshRate() {
218
232
  // refreshRate
219
233
  if (this.device.refreshRate) {
@@ -227,14 +241,14 @@ export class Curtain {
227
241
  this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
228
242
  }
229
243
  }
230
- // curtainRefreshRate
231
- if (this.device?.curtain?.refreshRate) {
232
- this.curtainRefreshRate = this.device?.curtain?.refreshRate;
244
+ // updateRate
245
+ if (this.device?.curtain?.updateRate) {
246
+ this.updateRate = this.device?.curtain?.updateRate;
233
247
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
234
248
  this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
235
249
  }
236
250
  } else {
237
- this.curtainRefreshRate = 5;
251
+ this.updateRate = 5;
238
252
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
239
253
  this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
240
254
  }
@@ -59,6 +59,7 @@ export class Humidifier {
59
59
  this.logs();
60
60
  this.scan();
61
61
  this.refreshRate();
62
+ this.config(device);
62
63
  this.CurrentRelativeHumidity = 0;
63
64
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
64
65
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
@@ -153,7 +154,7 @@ export class Humidifier {
153
154
  minStep: 0.1,
154
155
  })
155
156
  .onGet(() => {
156
- return Number.isNaN(this.CurrentTemperature);
157
+ return this.CurrentTemperature;
157
158
  });
158
159
  } else {
159
160
  this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
@@ -197,6 +198,25 @@ export class Humidifier {
197
198
  });
198
199
  }
199
200
 
201
+ config(device: device & devicesConfig) {
202
+ const config: any = device.humidifier;
203
+ if (device.ble !== undefined) {
204
+ config['ble'] = device.ble;
205
+ }
206
+ if (device.logging !== undefined) {
207
+ config['logging'] = device.logging;
208
+ }
209
+ if (device.refreshRate !== undefined) {
210
+ config['refreshRate'] = device.refreshRate;
211
+ }
212
+ if (device.scanDuration !== undefined) {
213
+ config['scanDuration'] = device.scanDuration;
214
+ }
215
+ if (config !== undefined) {
216
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
217
+ }
218
+ }
219
+
200
220
  refreshRate() {
201
221
  if (this.device.refreshRate) {
202
222
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
@@ -55,9 +55,10 @@ export class Meter {
55
55
  public device: device & devicesConfig,
56
56
  ) {
57
57
  // default placeholders
58
- this.logs();
59
- this.scan();
60
- this.refreshRate();
58
+ this.logs(device);
59
+ this.scan(device);
60
+ this.refreshRate(device);
61
+ this.config(device);
61
62
  if (this.CurrentRelativeHumidity === undefined) {
62
63
  this.CurrentRelativeHumidity = 0;
63
64
  } else {
@@ -173,50 +174,62 @@ export class Meter {
173
174
  });
174
175
  }
175
176
 
176
- refreshRate() {
177
- if (this.device.refreshRate) {
178
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
179
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
180
- this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
181
- }
177
+ config(device: device & devicesConfig) {
178
+ const config: any = device.meter;
179
+ if (device.ble !== undefined) {
180
+ config['ble'] = device.ble;
181
+ }
182
+ if (device.logging !== undefined) {
183
+ config['logging'] = device.logging;
184
+ }
185
+ if (device.refreshRate !== undefined) {
186
+ config['refreshRate'] = device.refreshRate;
187
+ }
188
+ if (device.scanDuration !== undefined) {
189
+ config['scanDuration'] = device.scanDuration;
190
+ }
191
+ if (config !== undefined) {
192
+ this.warnLog(`Meter: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
193
+ }
194
+ }
195
+
196
+ refreshRate(device: device & devicesConfig) {
197
+ if (device.refreshRate) {
198
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
199
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
182
200
  } else if (this.platform.config.options!.refreshRate) {
183
201
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
184
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
185
- this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
186
- }
202
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
187
203
  }
188
204
  }
189
205
 
190
- scan() {
191
- if (this.device.scanDuration) {
192
- this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
193
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
194
- this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
206
+ scan(device: device & devicesConfig) {
207
+ if (device.scanDuration) {
208
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
209
+ if (device.ble) {
210
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
195
211
  }
196
212
  } else {
197
213
  this.scanDuration = this.accessory.context.scanDuration = 1;
198
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
199
- this.warnLog(`Meter: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
214
+ if (this.device.ble) {
215
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
200
216
  }
201
217
  }
202
218
  }
203
219
 
204
- logs() {
220
+ logs(device: device & devicesConfig) {
205
221
  if (this.platform.debugMode) {
206
- this.deviceLogging = this.accessory.context.logging = 'debug';
207
- this.warnLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
208
- } else if (this.device.logging) {
209
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
210
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
211
- this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
212
- }
222
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
223
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
224
+ } else if (device.logging) {
225
+ this.deviceLogging = this.accessory.context.logging = device.logging;
226
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
213
227
  } else if (this.platform.config.options?.logging) {
214
228
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
215
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
216
- this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
217
- }
229
+ this.debugLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
218
230
  } else {
219
231
  this.deviceLogging = this.accessory.context.logging = 'standard';
232
+ this.debugLog(`Meter: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
220
233
  }
221
234
  }
222
235
 
@@ -408,16 +421,16 @@ export class Meter {
408
421
  }
409
422
  if (this.device.ble) {
410
423
  if (this.BatteryLevel === undefined) {
411
- this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
424
+ this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
412
425
  } else {
413
426
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
414
- this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
427
+ this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
415
428
  }
416
429
  if (this.StatusLowBattery === undefined) {
417
- this.debugLog(`Bot: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
430
+ this.debugLog(`Meter: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
418
431
  } else {
419
432
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
420
- this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
433
+ this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
421
434
  }
422
435
  }
423
436
  }