@switchbot/homebridge-switchbot 1.5.1-beta.2 → 1.6.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 (87) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/config.schema.json +9 -0
  3. package/dist/devices/bots.d.ts +4 -0
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +81 -25
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts.map +1 -1
  8. package/dist/devices/colorbulb.js +4 -9
  9. package/dist/devices/colorbulb.js.map +1 -1
  10. package/dist/devices/contact.d.ts +2 -0
  11. package/dist/devices/contact.d.ts.map +1 -1
  12. package/dist/devices/contact.js +21 -11
  13. package/dist/devices/contact.js.map +1 -1
  14. package/dist/devices/curtains.d.ts +2 -0
  15. package/dist/devices/curtains.d.ts.map +1 -1
  16. package/dist/devices/curtains.js +23 -13
  17. package/dist/devices/curtains.js.map +1 -1
  18. package/dist/devices/humidifiers.d.ts +2 -0
  19. package/dist/devices/humidifiers.d.ts.map +1 -1
  20. package/dist/devices/humidifiers.js +21 -11
  21. package/dist/devices/humidifiers.js.map +1 -1
  22. package/dist/devices/meters.d.ts +2 -0
  23. package/dist/devices/meters.d.ts.map +1 -1
  24. package/dist/devices/meters.js +20 -10
  25. package/dist/devices/meters.js.map +1 -1
  26. package/dist/devices/motion.d.ts +2 -0
  27. package/dist/devices/motion.d.ts.map +1 -1
  28. package/dist/devices/motion.js +20 -10
  29. package/dist/devices/motion.js.map +1 -1
  30. package/dist/devices/plugs.d.ts +2 -0
  31. package/dist/devices/plugs.d.ts.map +1 -1
  32. package/dist/devices/plugs.js +19 -9
  33. package/dist/devices/plugs.js.map +1 -1
  34. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  35. package/dist/irdevices/airconditioners.js +3 -8
  36. package/dist/irdevices/airconditioners.js.map +1 -1
  37. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  38. package/dist/irdevices/airpurifiers.js +3 -8
  39. package/dist/irdevices/airpurifiers.js.map +1 -1
  40. package/dist/irdevices/cameras.d.ts.map +1 -1
  41. package/dist/irdevices/cameras.js +3 -8
  42. package/dist/irdevices/cameras.js.map +1 -1
  43. package/dist/irdevices/fans.d.ts.map +1 -1
  44. package/dist/irdevices/fans.js +3 -8
  45. package/dist/irdevices/fans.js.map +1 -1
  46. package/dist/irdevices/lights.d.ts.map +1 -1
  47. package/dist/irdevices/lights.js +3 -8
  48. package/dist/irdevices/lights.js.map +1 -1
  49. package/dist/irdevices/others.d.ts +2 -0
  50. package/dist/irdevices/others.d.ts.map +1 -1
  51. package/dist/irdevices/others.js +30 -14
  52. package/dist/irdevices/others.js.map +1 -1
  53. package/dist/irdevices/tvs.d.ts.map +1 -1
  54. package/dist/irdevices/tvs.js +3 -8
  55. package/dist/irdevices/tvs.js.map +1 -1
  56. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  57. package/dist/irdevices/vacuumcleaners.js +3 -8
  58. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  59. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  60. package/dist/irdevices/waterheaters.js +3 -8
  61. package/dist/irdevices/waterheaters.js.map +1 -1
  62. package/dist/platform.d.ts.map +1 -1
  63. package/dist/platform.js +0 -5
  64. package/dist/platform.js.map +1 -1
  65. package/dist/settings.d.ts +1 -0
  66. package/dist/settings.d.ts.map +1 -1
  67. package/dist/settings.js.map +1 -1
  68. package/package.json +68 -68
  69. package/src/devices/bots.ts +83 -25
  70. package/src/devices/colorbulb.ts +4 -9
  71. package/src/devices/contact.ts +22 -11
  72. package/src/devices/curtains.ts +24 -13
  73. package/src/devices/humidifiers.ts +22 -11
  74. package/src/devices/meters.ts +21 -10
  75. package/src/devices/motion.ts +21 -10
  76. package/src/devices/plugs.ts +20 -9
  77. package/src/irdevices/airconditioners.ts +3 -8
  78. package/src/irdevices/airpurifiers.ts +3 -8
  79. package/src/irdevices/cameras.ts +3 -8
  80. package/src/irdevices/fans.ts +3 -8
  81. package/src/irdevices/lights.ts +3 -8
  82. package/src/irdevices/others.ts +31 -14
  83. package/src/irdevices/tvs.ts +3 -8
  84. package/src/irdevices/vacuumcleaners.ts +3 -8
  85. package/src/irdevices/waterheaters.ts +3 -8
  86. package/src/platform.ts +0 -5
  87. package/src/settings.ts +1 -0
@@ -36,6 +36,8 @@ export class Bot {
36
36
  battery!: serviceData['battery'];
37
37
 
38
38
  // Config
39
+ botMode!: string;
40
+ scanDuration!: number;
39
41
  deviceLogging!: string;
40
42
  deviceRefreshRate!: number;
41
43
 
@@ -52,8 +54,11 @@ export class Bot {
52
54
  public device: device & devicesConfig,
53
55
  ) {
54
56
  // default placeholders
55
- this.refreshRate();
56
57
  this.logs();
58
+ this.scan();
59
+ this.refreshRate();
60
+ this.PressOrSwitch();
61
+
57
62
  if (this.On === undefined) {
58
63
  this.On = false;
59
64
  this.accessory.context.On = this.On;
@@ -67,7 +72,7 @@ export class Bot {
67
72
  this.doublePress = 1;
68
73
  }
69
74
  this.BatteryLevel = 100;
70
- this.StatusLowBattery = 1;
75
+ this.StatusLowBattery = 0;
71
76
 
72
77
  // Bot Config
73
78
  this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
@@ -195,27 +200,54 @@ export class Bot {
195
200
  }
196
201
  }
197
202
 
203
+ scan() {
204
+ if (this.device.scanDuration) {
205
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
206
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
207
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
208
+ }
209
+ } else {
210
+ this.scanDuration = this.accessory.context.scanDuration = 1;
211
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
212
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
213
+ }
214
+ }
215
+ }
216
+
217
+
218
+
198
219
  logs() {
199
220
  if (this.platform.debugMode) {
200
221
  this.deviceLogging = this.accessory.context.logging = 'debug';
201
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
202
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
203
- }
222
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
204
223
  } else if (this.device.logging) {
205
224
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
206
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
225
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
207
226
  this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
208
227
  }
209
228
  } else if (this.platform.config.options?.logging) {
210
229
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
211
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
230
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
212
231
  this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
213
232
  }
214
233
  } else {
215
234
  this.deviceLogging = this.accessory.context.logging = 'standard';
216
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
217
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Standard Logging`);
218
- }
235
+ }
236
+ }
237
+
238
+ PressOrSwitch() {
239
+ if (!this.device.bot?.mode) {
240
+ this.botMode = 'switch';
241
+ this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
242
+ this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
243
+ } else if (this.device.bot?.mode === 'switch') {
244
+ this.botMode = 'switch';
245
+ this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
246
+ } else if (this.device.bot?.mode === 'press') {
247
+ this.botMode = 'press';
248
+ this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
249
+ } else {
250
+ throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
219
251
  }
220
252
  }
221
253
 
@@ -234,10 +266,17 @@ export class Bot {
234
266
  this.debugLog(`Bot: ${this.accessory.displayName} BLE parseStatus`);
235
267
  // BLEmode (true if Switch Mode) | (false if Press Mode)
236
268
  if (this.mode) {
237
- this.On = Boolean(this.state);
238
- this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
269
+ this.OnCached = this.On;
270
+ this.accessory.context.On = this.OnCached;
271
+ if (this.On === undefined) {
272
+ this.On = Boolean(this.state);
273
+ }
274
+ this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`);
239
275
  } else {
240
- this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
276
+ this.On = false;
277
+ this.OnCached = this.On;
278
+ this.accessory.context.On = this.OnCached;
279
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`);
241
280
  }
242
281
 
243
282
  this.BatteryLevel = Number(this.battery);
@@ -255,13 +294,19 @@ export class Bot {
255
294
  private async openAPIparseStatus() {
256
295
  if (this.platform.config.credentials?.openToken) {
257
296
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
258
- if (this.device.bot?.mode === 'press') {
297
+ if (this.botMode === 'press') {
259
298
  this.On = false;
299
+ this.OnCached = this.On;
300
+ this.accessory.context.On = this.OnCached;
260
301
  } else {
261
302
  if (this.deviceStatus.body.power === 'on') {
262
303
  this.On = true;
304
+ this.OnCached = this.On;
305
+ this.accessory.context.On = this.OnCached;
263
306
  } else {
264
307
  this.On = false;
308
+ this.OnCached = this.On;
309
+ this.accessory.context.On = this.OnCached;
265
310
  }
266
311
  }
267
312
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
@@ -313,8 +358,8 @@ export class Bot {
313
358
  this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
314
359
  }
315
360
  };
316
- // Wait 10 seconds
317
- return switchbot.wait(10000);
361
+ // Wait 2 seconds
362
+ return switchbot.wait(this.scanDuration * 1000);
318
363
  }).then(async () => {
319
364
  // Stop to monitor
320
365
  switchbot.stopScan();
@@ -394,14 +439,25 @@ export class Bot {
394
439
  if (this.On !== this.OnCached) {
395
440
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
396
441
  const switchbot = this.connectBLE();
397
- if (this.device.bot?.mode === 'press') {
398
- this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
442
+ if (this.botMode === 'press') {
443
+ this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
399
444
  switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
400
445
  .then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => {
401
- this.infoLog(`Bot: ${this.accessory.displayName}, On: ${this.On}`);
446
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
402
447
  return device_list[0].press({ id: this.device.bleMac });
403
448
  }).then(() => {
404
449
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
450
+ this.On = false;
451
+ this.OnCached = this.On;
452
+ this.accessory.context.On = this.OnCached;
453
+ setTimeout(() => {
454
+ if (this.device.bot?.deviceType === 'switch') {
455
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
456
+ } else {
457
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
458
+ }
459
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
460
+ }, 500);
405
461
  }).catch(async (e: any) => {
406
462
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
407
463
  if (this.deviceLogging === 'debug') {
@@ -418,13 +474,15 @@ export class Bot {
418
474
  }
419
475
  this.apiError(e);
420
476
  });
421
- } else if (this.device.bot?.mode === 'switch') {
422
- this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
477
+ } else if (this.botMode === 'switch') {
478
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
423
479
  switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
424
480
  this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
425
481
  return this.turnOnOff(device_list);
426
482
  }).then(() => {
427
483
  this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
484
+ this.OnCached = this.On;
485
+ this.accessory.context.On = this.OnCached;
428
486
  }).catch(async (e: any) => {
429
487
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
430
488
  if (this.deviceLogging === 'debug') {
@@ -442,7 +500,7 @@ export class Bot {
442
500
  this.apiError(e);
443
501
  });
444
502
  } else {
445
- this.errorLog(`Bot: ${this.accessory.displayName} Mode Not Set, mode: ${this.device.bot?.mode}`);
503
+ throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
446
504
  }
447
505
  }
448
506
  this.OnCached = this.On;
@@ -467,15 +525,15 @@ export class Bot {
467
525
  parameter: 'default',
468
526
  } as payload;
469
527
 
470
- if (this.device.bot?.mode === 'switch' && this.On) {
528
+ if (this.botMode === 'switch' && this.On) {
471
529
  payload.command = 'turnOn';
472
530
  this.On = true;
473
531
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
474
- } else if (this.device.bot?.mode === 'switch' && !this.On) {
532
+ } else if (this.botMode === 'switch' && !this.On) {
475
533
  payload.command = 'turnOff';
476
534
  this.On = false;
477
535
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
478
- } else if (this.device.bot?.mode === 'press') {
536
+ } else if (this.botMode === 'press') {
479
537
  payload.command = 'press';
480
538
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
481
539
  this.On = false;
@@ -53,8 +53,8 @@ export class ColorBulb {
53
53
  public device: device & devicesConfig,
54
54
  ) {
55
55
  // default placeholders
56
- this.refreshRate();
57
56
  this.logs();
57
+ this.refreshRate();
58
58
  if (this.On === undefined) {
59
59
  this.On = false;
60
60
  } else {
@@ -214,24 +214,19 @@ export class ColorBulb {
214
214
  logs() {
215
215
  if (this.platform.debugMode) {
216
216
  this.deviceLogging = this.accessory.context.logging = 'debug';
217
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
218
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
219
- }
217
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
220
218
  } else if (this.device.logging) {
221
219
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
222
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
220
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
223
221
  this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
224
222
  }
225
223
  } else if (this.platform.config.options?.logging) {
226
224
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
227
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
225
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
228
226
  this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
229
227
  }
230
228
  } else {
231
229
  this.deviceLogging = this.accessory.context.logging = 'standard';
232
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
233
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Standard Logging`);
234
- }
235
230
  }
236
231
  }
237
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
@@ -157,27 +159,36 @@ export class Contact {
157
159
  }
158
160
  }
159
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}`);
172
+ }
173
+ }
174
+ }
175
+
160
176
  logs() {
161
177
  if (this.platform.debugMode) {
162
178
  this.deviceLogging = this.accessory.context.logging = 'debug';
163
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
164
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
165
- }
179
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
166
180
  } else if (this.device.logging) {
167
181
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
168
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
182
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
169
183
  this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
170
184
  }
171
185
  } else if (this.platform.config.options?.logging) {
172
186
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
173
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
187
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
174
188
  this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
175
189
  }
176
190
  } else {
177
191
  this.deviceLogging = this.accessory.context.logging = 'standard';
178
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
179
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Standard Logging`);
180
- }
181
192
  }
182
193
  }
183
194
 
@@ -298,8 +309,8 @@ export class Contact {
298
309
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
299
310
  }
300
311
  };
301
- // Wait 10 seconds
302
- return switchbot.wait(10000);
312
+ // Wait 2 seconds
313
+ return switchbot.wait(this.scanDuration * 1000);
303
314
  }).then(async () => {
304
315
  // Stop to monitor
305
316
  switchbot.stopScan();
@@ -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;
@@ -219,27 +221,36 @@ export class Curtain {
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
239
  if (this.platform.debugMode) {
224
240
  this.deviceLogging = this.accessory.context.logging = 'debug';
225
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
226
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
227
- }
241
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
228
242
  } else if (this.device.logging) {
229
243
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
230
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
231
- 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}`);
232
246
  }
233
247
  } else if (this.platform.config.options?.logging) {
234
248
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
235
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
236
- 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}`);
237
251
  }
238
252
  } else {
239
253
  this.deviceLogging = this.accessory.context.logging = 'standard';
240
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
241
- this.warnLog('Using Device Standard Logging');
242
- }
243
254
  }
244
255
  }
245
256
 
@@ -466,8 +477,8 @@ export class Curtain {
466
477
  this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
467
478
  }
468
479
  };
469
- // Wait 10 seconds
470
- return switchbot.wait(10000);
480
+ // Wait 2 seconds
481
+ return switchbot.wait(this.scanDuration * 1000);
471
482
  }).then(async () => {
472
483
  // Stop to monitor
473
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;
@@ -204,27 +206,36 @@ export class Humidifier {
204
206
  }
205
207
  }
206
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}`);
219
+ }
220
+ }
221
+ }
222
+
207
223
  logs() {
208
224
  if (this.platform.debugMode) {
209
225
  this.deviceLogging = this.accessory.context.logging = 'debug';
210
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
211
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
212
- }
226
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
213
227
  } else if (this.device.logging) {
214
228
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
215
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
229
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
216
230
  this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
217
231
  }
218
232
  } else if (this.platform.config.options?.logging) {
219
233
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
220
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
234
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
221
235
  this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
222
236
  }
223
237
  } else {
224
238
  this.deviceLogging = this.accessory.context.logging = 'standard';
225
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
226
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Standard Logging`);
227
- }
228
239
  }
229
240
  }
230
241
 
@@ -363,8 +374,8 @@ export class Humidifier {
363
374
  this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
364
375
  }
365
376
  };
366
- // Wait 10 seconds
367
- return switchbot.wait(10000);
377
+ // Wait 2 seconds
378
+ return switchbot.wait(this.scanDuration * 1000);
368
379
  }).then(async () => {
369
380
  // Stop to monitor
370
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 {
@@ -194,27 +196,36 @@ export class Meter {
194
196
  }
195
197
  }
196
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}`);
209
+ }
210
+ }
211
+ }
212
+
197
213
  logs() {
198
214
  if (this.platform.debugMode) {
199
215
  this.deviceLogging = this.accessory.context.logging = 'debug';
200
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
201
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
202
- }
216
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
203
217
  } else if (this.device.logging) {
204
218
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
205
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
219
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
206
220
  this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
207
221
  }
208
222
  } else if (this.platform.config.options?.logging) {
209
223
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
210
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
224
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
211
225
  this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
212
226
  }
213
227
  } else {
214
228
  this.deviceLogging = this.accessory.context.logging = 'standard';
215
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
216
- this.warnLog(`Meter: ${this.accessory.displayName} Using Device Standard Logging`);
217
- }
218
229
  }
219
230
  }
220
231
 
@@ -329,7 +340,7 @@ export class Meter {
329
340
  }
330
341
  };
331
342
  // Wait 10 seconds
332
- return switchbot.wait(10000);
343
+ return switchbot.wait(this.scanDuration * 1000);
333
344
  }).then(async () => {
334
345
  // Stop to monitor
335
346
  switchbot.stopScan();
@@ -34,6 +34,7 @@ export class Motion {
34
34
  lightLevel!: serviceData['lightLevel'];
35
35
 
36
36
  // Config
37
+ scanDuration!: number;
37
38
  deviceLogging!: string;
38
39
  deviceRefreshRate!: number;
39
40
 
@@ -47,8 +48,9 @@ export class Motion {
47
48
  public device: device & devicesConfig,
48
49
  ) {
49
50
  // default placeholders
50
- this.refreshRate();
51
51
  this.logs();
52
+ this.scan();
53
+ this.refreshRate();
52
54
  this.MotionDetected = false;
53
55
 
54
56
  // this is subject we use to track when we need to POST changes to the SwitchBot API
@@ -125,27 +127,36 @@ export class Motion {
125
127
  }
126
128
  }
127
129
 
130
+ scan() {
131
+ if (this.device.scanDuration) {
132
+ this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
133
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
134
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
135
+ }
136
+ } else {
137
+ this.scanDuration = this.accessory.context.scanDuration = 1;
138
+ if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
139
+ this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
140
+ }
141
+ }
142
+ }
143
+
128
144
  logs() {
129
145
  if (this.platform.debugMode) {
130
146
  this.deviceLogging = this.accessory.context.logging = 'debug';
131
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
132
- this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
133
- }
147
+ this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
134
148
  } else if (this.device.logging) {
135
149
  this.deviceLogging = this.accessory.context.logging = this.device.logging;
136
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
150
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
137
151
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
138
152
  }
139
153
  } else if (this.platform.config.options?.logging) {
140
154
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
141
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
155
+ if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
142
156
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
143
157
  }
144
158
  } else {
145
159
  this.deviceLogging = this.accessory.context.logging = 'standard';
146
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
147
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Standard Logging`);
148
- }
149
160
  }
150
161
  }
151
162
 
@@ -236,7 +247,7 @@ export class Motion {
236
247
  }
237
248
  };
238
249
  // Wait 10 seconds
239
- return switchbot.wait(10000);
250
+ return switchbot.wait(this.scanDuration * 1000);
240
251
  }).then(async () => {
241
252
  // Stop to monitor
242
253
  switchbot.stopScan();