@switchbot/homebridge-switchbot 1.5.1-beta.1 → 1.5.1-beta.5

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 (82) hide show
  1. package/CHANGELOG.md +6 -2
  2. package/config.schema.json +9 -0
  3. package/dist/devices/bots.d.ts +2 -0
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +66 -23
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.js +13 -12
  8. package/dist/devices/colorbulb.js.map +1 -1
  9. package/dist/devices/contact.d.ts +2 -0
  10. package/dist/devices/contact.d.ts.map +1 -1
  11. package/dist/devices/contact.js +31 -15
  12. package/dist/devices/contact.js.map +1 -1
  13. package/dist/devices/curtains.d.ts +2 -0
  14. package/dist/devices/curtains.d.ts.map +1 -1
  15. package/dist/devices/curtains.js +34 -18
  16. package/dist/devices/curtains.js.map +1 -1
  17. package/dist/devices/humidifiers.d.ts +2 -0
  18. package/dist/devices/humidifiers.d.ts.map +1 -1
  19. package/dist/devices/humidifiers.js +31 -15
  20. package/dist/devices/humidifiers.js.map +1 -1
  21. package/dist/devices/meters.d.ts +2 -0
  22. package/dist/devices/meters.d.ts.map +1 -1
  23. package/dist/devices/meters.js +30 -14
  24. package/dist/devices/meters.js.map +1 -1
  25. package/dist/devices/motion.d.ts +2 -0
  26. package/dist/devices/motion.d.ts.map +1 -1
  27. package/dist/devices/motion.js +30 -14
  28. package/dist/devices/motion.js.map +1 -1
  29. package/dist/devices/plugs.d.ts +2 -0
  30. package/dist/devices/plugs.d.ts.map +1 -1
  31. package/dist/devices/plugs.js +29 -13
  32. package/dist/devices/plugs.js.map +1 -1
  33. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  34. package/dist/irdevices/airconditioners.js +11 -1
  35. package/dist/irdevices/airconditioners.js.map +1 -1
  36. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  37. package/dist/irdevices/airpurifiers.js +11 -1
  38. package/dist/irdevices/airpurifiers.js.map +1 -1
  39. package/dist/irdevices/cameras.d.ts.map +1 -1
  40. package/dist/irdevices/cameras.js +11 -1
  41. package/dist/irdevices/cameras.js.map +1 -1
  42. package/dist/irdevices/fans.d.ts.map +1 -1
  43. package/dist/irdevices/fans.js +11 -1
  44. package/dist/irdevices/fans.js.map +1 -1
  45. package/dist/irdevices/lights.d.ts.map +1 -1
  46. package/dist/irdevices/lights.js +11 -1
  47. package/dist/irdevices/lights.js.map +1 -1
  48. package/dist/irdevices/others.d.ts +2 -0
  49. package/dist/irdevices/others.d.ts.map +1 -1
  50. package/dist/irdevices/others.js +38 -7
  51. package/dist/irdevices/others.js.map +1 -1
  52. package/dist/irdevices/tvs.d.ts.map +1 -1
  53. package/dist/irdevices/tvs.js +11 -1
  54. package/dist/irdevices/tvs.js.map +1 -1
  55. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  56. package/dist/irdevices/vacuumcleaners.js +11 -1
  57. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  58. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  59. package/dist/irdevices/waterheaters.js +11 -1
  60. package/dist/irdevices/waterheaters.js.map +1 -1
  61. package/dist/settings.d.ts +1 -0
  62. package/dist/settings.d.ts.map +1 -1
  63. package/dist/settings.js.map +1 -1
  64. package/package.json +6 -6
  65. package/src/devices/bots.ts +65 -23
  66. package/src/devices/colorbulb.ts +12 -12
  67. package/src/devices/contact.ts +31 -15
  68. package/src/devices/curtains.ts +35 -19
  69. package/src/devices/humidifiers.ts +31 -15
  70. package/src/devices/meters.ts +30 -14
  71. package/src/devices/motion.ts +30 -14
  72. package/src/devices/plugs.ts +29 -13
  73. package/src/irdevices/airconditioners.ts +10 -1
  74. package/src/irdevices/airpurifiers.ts +10 -1
  75. package/src/irdevices/cameras.ts +10 -1
  76. package/src/irdevices/fans.ts +10 -1
  77. package/src/irdevices/lights.ts +10 -1
  78. package/src/irdevices/others.ts +39 -8
  79. package/src/irdevices/tvs.ts +10 -1
  80. package/src/irdevices/vacuumcleaners.ts +10 -1
  81. package/src/irdevices/waterheaters.ts +10 -1
  82. package/src/settings.ts +1 -0
@@ -36,6 +36,7 @@ export class Bot {
36
36
  battery!: serviceData['battery'];
37
37
 
38
38
  // Config
39
+ scanDuration!: number;
39
40
  deviceLogging!: string;
40
41
  deviceRefreshRate!: number;
41
42
 
@@ -52,6 +53,9 @@ export class Bot {
52
53
  public device: device & devicesConfig,
53
54
  ) {
54
55
  // default placeholders
56
+ this.logs();
57
+ this.scan();
58
+ this.refreshRate();
55
59
  if (this.On === undefined) {
56
60
  this.On = false;
57
61
  this.accessory.context.On = this.On;
@@ -64,10 +68,8 @@ export class Bot {
64
68
  } else {
65
69
  this.doublePress = 1;
66
70
  }
67
- this.refreshRate();
68
- this.logs();
69
71
  this.BatteryLevel = 100;
70
- this.StatusLowBattery = 1;
72
+ this.StatusLowBattery = 0;
71
73
 
72
74
  // Bot Config
73
75
  this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
@@ -184,33 +186,47 @@ export class Bot {
184
186
  refreshRate() {
185
187
  if (this.device.refreshRate) {
186
188
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
187
- if (this.platform.debugMode) {
188
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
189
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
190
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
189
191
  }
190
192
  } else if (this.platform.config.options!.refreshRate) {
191
193
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
192
- if (this.platform.debugMode) {
193
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
194
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
195
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
196
+ }
197
+ }
198
+ }
199
+
200
+ scan() {
201
+ if (this.device.scanDuration) {
202
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
203
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
204
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
205
+ }
206
+ } else {
207
+ this.scanDuration = this.accessory.context.scanDuration = 1;
208
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
209
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
194
210
  }
195
211
  }
196
212
  }
197
213
 
198
214
  logs() {
199
- if (this.device.logging) {
215
+ if (this.platform.debugMode) {
216
+ this.deviceLogging = this.accessory.context.logging = 'debug';
217
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
218
+ } else if (this.device.logging) {
200
219
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
201
- if (this.platform.debugMode) {
202
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
220
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
221
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
203
222
  }
204
223
  } else if (this.platform.config.options?.logging) {
205
224
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
206
- if (this.platform.debugMode) {
207
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
225
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
226
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
208
227
  }
209
228
  } else {
210
229
  this.deviceLogging = this.accessory.context.logging = 'standard';
211
- if (this.platform.debugMode) {
212
- this.warnLog('Using Device Standard Logging');
213
- }
214
230
  }
215
231
  }
216
232
 
@@ -229,10 +245,17 @@ export class Bot {
229
245
  this.debugLog(`Bot: ${this.accessory.displayName} BLE parseStatus`);
230
246
  // BLEmode (true if Switch Mode) | (false if Press Mode)
231
247
  if (this.mode) {
232
- this.On = Boolean(this.state);
233
- this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
248
+ this.OnCached = this.On;
249
+ this.accessory.context.On = this.OnCached;
250
+ if (this.On === undefined) {
251
+ this.On = Boolean(this.state);
252
+ }
253
+ this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`);
234
254
  } else {
235
- this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
255
+ this.On = false;
256
+ this.OnCached = this.On;
257
+ this.accessory.context.On = this.OnCached;
258
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`);
236
259
  }
237
260
 
238
261
  this.BatteryLevel = Number(this.battery);
@@ -252,14 +275,20 @@ export class Bot {
252
275
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
253
276
  if (this.device.bot?.mode === 'press') {
254
277
  this.On = false;
278
+ this.OnCached = this.On;
279
+ this.accessory.context.On = this.OnCached;
255
280
  } else {
256
281
  if (this.deviceStatus.body.power === 'on') {
257
282
  this.On = true;
283
+ this.OnCached = this.On;
284
+ this.accessory.context.On = this.OnCached;
258
285
  } else {
259
286
  this.On = false;
287
+ this.OnCached = this.On;
288
+ this.accessory.context.On = this.OnCached;
260
289
  }
261
290
  }
262
- this.debugLog(`Bot ${this.accessory.displayName} On: ${this.On}`);
291
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
263
292
  }
264
293
  }
265
294
 
@@ -308,8 +337,8 @@ export class Bot {
308
337
  this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
309
338
  }
310
339
  };
311
- // Wait 10 seconds
312
- return switchbot.wait(10000);
340
+ // Wait 2 seconds
341
+ return switchbot.wait(this.scanDuration * 1000);
313
342
  }).then(async () => {
314
343
  // Stop to monitor
315
344
  switchbot.stopScan();
@@ -393,10 +422,21 @@ export class Bot {
393
422
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
394
423
  switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
395
424
  .then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => {
396
- this.infoLog(`Bot: ${this.accessory.displayName}, On: ${this.On}`);
425
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
397
426
  return device_list[0].press({ id: this.device.bleMac });
398
427
  }).then(() => {
399
428
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
429
+ this.On = false;
430
+ this.OnCached = this.On;
431
+ this.accessory.context.On = this.OnCached;
432
+ setTimeout(() => {
433
+ if (this.device.bot?.deviceType === 'switch') {
434
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
435
+ } else {
436
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
437
+ }
438
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
439
+ }, 500);
400
440
  }).catch(async (e: any) => {
401
441
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
402
442
  if (this.deviceLogging === 'debug') {
@@ -420,6 +460,8 @@ export class Bot {
420
460
  return this.turnOnOff(device_list);
421
461
  }).then(() => {
422
462
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
463
+ this.OnCached = this.On;
464
+ this.accessory.context.On = this.OnCached;
423
465
  }).catch(async (e: any) => {
424
466
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
425
467
  if (this.deviceLogging === 'debug') {
@@ -483,7 +525,7 @@ export class Bot {
483
525
 
484
526
  // Make the API request
485
527
  const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
486
- this.debugLog(`Bot ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
528
+ this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
487
529
  this.statusCode(push);
488
530
  this.OnCached = this.On;
489
531
  this.accessory.context.On = this.OnCached;
@@ -200,33 +200,33 @@ export class ColorBulb {
200
200
  refreshRate() {
201
201
  if (this.device.refreshRate) {
202
202
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
203
- if (this.platform.debugMode) {
204
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
203
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
204
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
205
205
  }
206
206
  } else if (this.platform.config.options!.refreshRate) {
207
207
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
208
- if (this.platform.debugMode) {
209
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
208
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
209
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
210
210
  }
211
211
  }
212
212
  }
213
213
 
214
214
  logs() {
215
- if (this.device.logging) {
215
+ if (this.platform.debugMode) {
216
+ this.deviceLogging = this.accessory.context.logging = 'debug';
217
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
218
+ } else if (this.device.logging) {
216
219
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
217
- if (this.platform.debugMode) {
218
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
220
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
221
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
219
222
  }
220
223
  } else if (this.platform.config.options?.logging) {
221
224
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
222
- if (this.platform.debugMode) {
223
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
225
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
226
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
224
227
  }
225
228
  } else {
226
229
  this.deviceLogging = this.accessory.context.logging = 'standard';
227
- if (this.platform.debugMode) {
228
- this.warnLog('Using Device Standard Logging');
229
- }
230
230
  }
231
231
  }
232
232
 
@@ -37,6 +37,7 @@ export class Contact {
37
37
  lightLevel!: serviceData['lightLevel'];
38
38
 
39
39
  // Config
40
+ scanDuration!: number;
40
41
  deviceLogging!: string;
41
42
  deviceRefreshRate!: number;
42
43
 
@@ -50,8 +51,9 @@ export class Contact {
50
51
  public device: device & devicesConfig,
51
52
  ) {
52
53
  // default placeholders
53
- this.refreshRate();
54
54
  this.logs();
55
+ this.scan();
56
+ this.refreshRate();
55
57
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
56
58
 
57
59
  // Contact Config
@@ -146,33 +148,47 @@ export class Contact {
146
148
  refreshRate() {
147
149
  if (this.device.refreshRate) {
148
150
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
149
- if (this.platform.debugMode) {
150
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
151
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
152
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
151
153
  }
152
154
  } else if (this.platform.config.options!.refreshRate) {
153
155
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
154
- if (this.platform.debugMode) {
155
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
156
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
157
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
158
+ }
159
+ }
160
+ }
161
+
162
+ scan() {
163
+ if (this.device.scanDuration) {
164
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
165
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
166
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
167
+ }
168
+ } else {
169
+ this.scanDuration = this.accessory.context.scanDuration = 1;
170
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
171
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
156
172
  }
157
173
  }
158
174
  }
159
175
 
160
176
  logs() {
161
- if (this.device.logging) {
177
+ if (this.platform.debugMode) {
178
+ this.deviceLogging = this.accessory.context.logging = 'debug';
179
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
180
+ } else if (this.device.logging) {
162
181
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
163
- if (this.platform.debugMode) {
164
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
182
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
183
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
165
184
  }
166
185
  } else if (this.platform.config.options?.logging) {
167
186
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
168
- if (this.platform.debugMode) {
169
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
187
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
188
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
170
189
  }
171
190
  } else {
172
191
  this.deviceLogging = this.accessory.context.logging = 'standard';
173
- if (this.platform.debugMode) {
174
- this.warnLog('Using Device Standard Logging');
175
- }
176
192
  }
177
193
  }
178
194
 
@@ -293,8 +309,8 @@ export class Contact {
293
309
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
294
310
  }
295
311
  };
296
- // Wait 10 seconds
297
- return switchbot.wait(10000);
312
+ // Wait 2 seconds
313
+ return switchbot.wait(this.scanDuration * 1000);
298
314
  }).then(async () => {
299
315
  // Stop to monitor
300
316
  switchbot.stopScan();
@@ -4,7 +4,7 @@ import Switchbot from 'node-switchbot';
4
4
  import { interval, Subject } from 'rxjs';
5
5
  import { SwitchBotPlatform } from '../platform';
6
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
- import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
7
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
8
8
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
9
9
 
10
10
  export class Curtain {
@@ -42,6 +42,7 @@ export class Curtain {
42
42
  curtainRefreshRate!: number;
43
43
  set_minLux!: number;
44
44
  set_maxLux!: number;
45
+ scanDuration!: number;
45
46
  deviceLogging!: string;
46
47
  deviceRefreshRate!: number;
47
48
  spaceBetweenLevels!: number;
@@ -56,9 +57,10 @@ export class Curtain {
56
57
  public device: device & devicesConfig,
57
58
  ) {
58
59
  // default placeholders
59
- this.refreshRate();
60
60
  this.logs();
61
+ this.scan();
61
62
  this.setMinMax();
63
+ this.refreshRate();
62
64
  this.CurrentPosition = 0;
63
65
  this.TargetPosition = 0;
64
66
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
@@ -196,45 +198,59 @@ export class Curtain {
196
198
  // refreshRate
197
199
  if (this.device.refreshRate) {
198
200
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
199
- if (this.platform.debugMode) {
200
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
201
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
202
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
201
203
  }
202
204
  } else if (this.platform.config.options!.refreshRate) {
203
205
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
204
- if (this.platform.debugMode) {
205
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
206
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
207
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
206
208
  }
207
209
  }
208
210
  // curtainRefreshRate
209
211
  if (this.device?.curtain?.refreshRate) {
210
212
  this.curtainRefreshRate = this.device?.curtain?.refreshRate;
211
- if (this.platform.debugMode) {
212
- this.warnLog(`Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
213
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
214
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
213
215
  }
214
216
  } else {
215
217
  this.curtainRefreshRate = 5;
216
- if (this.deviceLogging === 'debug') {
218
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
217
219
  this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
218
220
  }
219
221
  }
220
222
  }
221
223
 
224
+ scan() {
225
+ if (this.device.scanDuration) {
226
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
227
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
228
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
229
+ }
230
+ } else {
231
+ this.scanDuration = this.accessory.context.scanDuration = 1;
232
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
233
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
234
+ }
235
+ }
236
+ }
237
+
222
238
  logs() {
223
- if (this.device.logging) {
239
+ if (this.platform.debugMode) {
240
+ this.deviceLogging = this.accessory.context.logging = 'debug';
241
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
242
+ } else if (this.device.logging) {
224
243
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
225
- if (this.platform.debugMode) {
226
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
244
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
245
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
227
246
  }
228
247
  } else if (this.platform.config.options?.logging) {
229
248
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
230
- if (this.platform.debugMode) {
231
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
249
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
250
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
232
251
  }
233
252
  } else {
234
253
  this.deviceLogging = this.accessory.context.logging = 'standard';
235
- if (this.platform.debugMode) {
236
- this.warnLog('Using Device Standard Logging');
237
- }
238
254
  }
239
255
  }
240
256
 
@@ -461,8 +477,8 @@ export class Curtain {
461
477
  this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
462
478
  }
463
479
  };
464
- // Wait 10 seconds
465
- return switchbot.wait(10000);
480
+ // Wait 2 seconds
481
+ return switchbot.wait(this.scanDuration * 1000);
466
482
  }).then(async () => {
467
483
  // Stop to monitor
468
484
  switchbot.stopScan();
@@ -37,6 +37,7 @@ export class Humidifier {
37
37
 
38
38
  // Config
39
39
  set_minStep?: number;
40
+ scanDuration!: number;
40
41
  deviceLogging!: string;
41
42
  deviceRefreshRate!: number;
42
43
 
@@ -50,8 +51,9 @@ export class Humidifier {
50
51
  public device: device & devicesConfig,
51
52
  ) {
52
53
  // default placeholders
53
- this.refreshRate();
54
54
  this.logs();
55
+ this.scan();
56
+ this.refreshRate();
55
57
  this.CurrentRelativeHumidity = 0;
56
58
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
57
59
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
@@ -193,33 +195,47 @@ export class Humidifier {
193
195
  refreshRate() {
194
196
  if (this.device.refreshRate) {
195
197
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
196
- if (this.platform.debugMode) {
197
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
198
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
199
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
198
200
  }
199
201
  } else if (this.platform.config.options!.refreshRate) {
200
202
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
201
- if (this.platform.debugMode) {
202
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
203
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
204
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
205
+ }
206
+ }
207
+ }
208
+
209
+ scan() {
210
+ if (this.device.scanDuration) {
211
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
212
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
213
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
214
+ }
215
+ } else {
216
+ this.scanDuration = this.accessory.context.scanDuration = 1;
217
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
218
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
203
219
  }
204
220
  }
205
221
  }
206
222
 
207
223
  logs() {
208
- if (this.device.logging) {
224
+ if (this.platform.debugMode) {
225
+ this.deviceLogging = this.accessory.context.logging = 'debug';
226
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
227
+ } else if (this.device.logging) {
209
228
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
210
- if (this.platform.debugMode) {
211
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
229
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
230
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
212
231
  }
213
232
  } else if (this.platform.config.options?.logging) {
214
233
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
215
- if (this.platform.debugMode) {
216
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
234
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
235
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
217
236
  }
218
237
  } else {
219
238
  this.deviceLogging = this.accessory.context.logging = 'standard';
220
- if (this.platform.debugMode) {
221
- this.warnLog('Using Device Standard Logging');
222
- }
223
239
  }
224
240
  }
225
241
 
@@ -358,8 +374,8 @@ export class Humidifier {
358
374
  this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
359
375
  }
360
376
  };
361
- // Wait 10 seconds
362
- return switchbot.wait(10000);
377
+ // Wait 2 seconds
378
+ return switchbot.wait(this.scanDuration * 1000);
363
379
  }).then(async () => {
364
380
  // Stop to monitor
365
381
  switchbot.stopScan();
@@ -40,6 +40,7 @@ export class Meter {
40
40
  humidity!: serviceData['humidity'];
41
41
 
42
42
  // Config
43
+ scanDuration!: number;
43
44
  deviceLogging!: string;
44
45
  deviceRefreshRate!: number;
45
46
 
@@ -53,8 +54,9 @@ export class Meter {
53
54
  public device: device & devicesConfig,
54
55
  ) {
55
56
  // default placeholders
56
- this.refreshRate();
57
57
  this.logs();
58
+ this.scan();
59
+ this.refreshRate();
58
60
  if (this.BatteryLevel === undefined) {
59
61
  this.BatteryLevel = 100;
60
62
  } else {
@@ -183,33 +185,47 @@ export class Meter {
183
185
  refreshRate() {
184
186
  if (this.device.refreshRate) {
185
187
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
186
- if (this.platform.debugMode) {
187
- this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
188
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
189
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
188
190
  }
189
191
  } else if (this.platform.config.options!.refreshRate) {
190
192
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
191
- if (this.platform.debugMode) {
192
- this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
193
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
194
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
195
+ }
196
+ }
197
+ }
198
+
199
+ scan() {
200
+ if (this.device.scanDuration) {
201
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
202
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
203
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
204
+ }
205
+ } else {
206
+ this.scanDuration = this.accessory.context.scanDuration = 1;
207
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
208
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
193
209
  }
194
210
  }
195
211
  }
196
212
 
197
213
  logs() {
198
- if (this.device.logging) {
214
+ if (this.platform.debugMode) {
215
+ this.deviceLogging = this.accessory.context.logging = 'debug';
216
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
217
+ } else if (this.device.logging) {
199
218
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
200
- if (this.platform.debugMode) {
201
- this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
219
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
220
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
202
221
  }
203
222
  } else if (this.platform.config.options?.logging) {
204
223
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
205
- if (this.platform.debugMode) {
206
- this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
224
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
225
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
207
226
  }
208
227
  } else {
209
228
  this.deviceLogging = this.accessory.context.logging = 'standard';
210
- if (this.platform.debugMode) {
211
- this.warnLog('Using Device Standard Logging');
212
- }
213
229
  }
214
230
  }
215
231
 
@@ -324,7 +340,7 @@ export class Meter {
324
340
  }
325
341
  };
326
342
  // Wait 10 seconds
327
- return switchbot.wait(10000);
343
+ return switchbot.wait(this.scanDuration * 1000);
328
344
  }).then(async () => {
329
345
  // Stop to monitor
330
346
  switchbot.stopScan();