@switchbot/homebridge-switchbot 2.0.0-beta.21 → 2.0.0-beta.23

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 (62) hide show
  1. package/config.schema.json +4 -4
  2. package/dist/device/bot.d.ts +2 -2
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +19 -15
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +2 -2
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +18 -18
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +1 -2
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +11 -13
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +2 -2
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +19 -21
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +2 -2
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +18 -17
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +3 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +39 -10
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +1 -2
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +11 -13
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +1 -2
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +9 -11
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +1 -2
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +11 -13
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -2
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +18 -17
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +4 -2
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +84 -76
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/platform.d.ts +2 -3
  47. package/dist/platform.d.ts.map +1 -1
  48. package/dist/platform.js +68 -70
  49. package/dist/platform.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/device/bot.ts +20 -16
  52. package/src/device/colorbulb.ts +19 -19
  53. package/src/device/contact.ts +11 -14
  54. package/src/device/curtain.ts +20 -22
  55. package/src/device/humidifier.ts +19 -18
  56. package/src/device/lock.ts +42 -10
  57. package/src/device/meter.ts +11 -14
  58. package/src/device/meterplus.ts +9 -12
  59. package/src/device/motion.ts +11 -14
  60. package/src/device/plug.ts +19 -18
  61. package/src/device/striplight.ts +45 -32
  62. package/src/platform.ts +68 -71
@@ -37,7 +37,6 @@ export class Contact {
37
37
  // BLE Others
38
38
  connected?: boolean;
39
39
  switchbot!: switchbot;
40
- SwitchToOpenAPI!: boolean;
41
40
  serviceData!: serviceData;
42
41
  address!: ad['address'];
43
42
  battery!: serviceData['battery'];
@@ -57,8 +56,8 @@ export class Contact {
57
56
  doContactUpdate!: Subject<void>;
58
57
 
59
58
  // Connection
60
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
61
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
59
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
60
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
62
61
 
63
62
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
64
63
  // default placeholders
@@ -164,10 +163,9 @@ export class Contact {
164
163
  * Parse the device status from the SwitchBot api
165
164
  */
166
165
  async parseStatus(): Promise<void> {
167
- if (this.BLE && !this.SwitchToOpenAPI) {
166
+ if (this.BLE) {
168
167
  await this.BLEparseStatus();
169
168
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
170
- this.SwitchToOpenAPI = false;
171
169
  await this.openAPIparseStatus();
172
170
  } else {
173
171
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -328,20 +326,20 @@ export class Contact {
328
326
  // Stop to monitor
329
327
  switchbot.stopScan();
330
328
  if (this.connected) {
331
- this.parseStatus();
329
+ this.BLEparseStatus();
332
330
  this.updateHomeKitCharacteristics();
333
331
  } else {
334
- await this.BLEconnection(switchbot);
332
+ await this.BLERefreshConnection(switchbot);
335
333
  }
336
334
  })
337
335
  .catch(async (e: any) => {
338
336
  this.apiError(e);
339
337
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
340
338
  + ` Connection, Error Message: ${superStringify(e.message)}`);
341
- await this.BLEconnection(switchbot);
339
+ await this.BLERefreshConnection(switchbot);
342
340
  });
343
341
  } else {
344
- await this.BLEconnection(switchbot);
342
+ await this.BLERefreshConnection(switchbot);
345
343
  }
346
344
  }
347
345
 
@@ -381,7 +379,7 @@ export class Contact {
381
379
  this.openState = this.deviceStatus.body.openState;
382
380
  this.moveDetected = this.deviceStatus.body.moveDetected;
383
381
  this.brightness = this.deviceStatus.body.brightness;
384
- this.parseStatus();
382
+ this.openAPIparseStatus();
385
383
  this.updateHomeKitCharacteristics();
386
384
  } catch (e: any) {
387
385
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -466,11 +464,10 @@ export class Contact {
466
464
  }
467
465
  }
468
466
 
469
- async BLEconnection(switchbot: any): Promise<void> {
467
+ async BLERefreshConnection(switchbot: any): Promise<void> {
470
468
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
471
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
472
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
473
- this.SwitchToOpenAPI = true;
469
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
470
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
474
471
  await this.openAPIRefreshStatus();
475
472
  }
476
473
  }
@@ -39,7 +39,6 @@ export class Curtain {
39
39
  serviceData!: serviceData;
40
40
  spaceBetweenLevels!: number;
41
41
  address!: ad['address'];
42
- SwitchToOpenAPI?: boolean;
43
42
  calibration: serviceData['calibration'];
44
43
  battery: serviceData['battery'];
45
44
  position: serviceData['position'];
@@ -68,8 +67,8 @@ export class Curtain {
68
67
  doCurtainUpdate!: Subject<void>;
69
68
 
70
69
  // Connection
71
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
72
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
70
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
71
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
73
72
 
74
73
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
75
74
  // default placeholders
@@ -215,10 +214,9 @@ export class Curtain {
215
214
  * Parse the device status from the SwitchBot api
216
215
  */
217
216
  async parseStatus(): Promise<void> {
218
- if (this.BLE && !this.SwitchToOpenAPI) {
217
+ if (this.BLE) {
219
218
  await this.BLEparseStatus();
220
219
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
221
- this.SwitchToOpenAPI = false;
222
220
  await this.openAPIparseStatus();
223
221
  } else {
224
222
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -451,20 +449,20 @@ export class Curtain {
451
449
  // Stop to monitor
452
450
  switchbot.stopScan();
453
451
  if (this.connected) {
454
- this.parseStatus();
452
+ this.BLEparseStatus();
455
453
  this.updateHomeKitCharacteristics();
456
454
  } else {
457
- await this.BLEconnection(switchbot);
455
+ await this.BLERefreshConnection(switchbot);
458
456
  }
459
457
  })
460
458
  .catch(async (e: any) => {
461
459
  this.apiError(e);
462
460
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
463
461
  + ` Connection, Error Message: ${superStringify(e.message)}`);
464
- await this.BLEconnection(switchbot);
462
+ await this.BLERefreshConnection(switchbot);
465
463
  });
466
464
  } else {
467
- await this.BLEconnection(switchbot);
465
+ await this.BLERefreshConnection(switchbot);
468
466
  }
469
467
  }
470
468
 
@@ -504,7 +502,7 @@ export class Curtain {
504
502
  this.slidePosition = this.deviceStatus.body.slidePosition;
505
503
  this.moving = this.deviceStatus.body.moving;
506
504
  this.brightness = this.deviceStatus.body.brightness;
507
- this.parseStatus();
505
+ this.openAPIparseStatus();
508
506
  this.updateHomeKitCharacteristics();
509
507
  } catch (e: any) {
510
508
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -568,17 +566,11 @@ export class Curtain {
568
566
  this.apiError(e);
569
567
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
570
568
  + ` Connection, Error Message: ${superStringify(e.message)}`);
571
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
572
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
573
- await this.openAPIpushChanges();
574
- }
569
+ await this.BLEPushConnection();
575
570
  });
576
571
  } else {
577
572
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
578
- if (this.platform.config.credentials?.token) {
579
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
580
- await this.openAPIpushChanges();
581
- }
573
+ await this.BLEPushConnection();
582
574
  }
583
575
  } else {
584
576
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
@@ -810,11 +802,17 @@ export class Curtain {
810
802
  }
811
803
  }
812
804
 
813
- async BLEconnection(switchbot: any): Promise<void> {
805
+ async BLEPushConnection() {
806
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
807
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
808
+ await this.openAPIpushChanges();
809
+ }
810
+ }
811
+
812
+ async BLERefreshConnection(switchbot: any): Promise<void> {
814
813
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
815
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
816
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
817
- this.SwitchToOpenAPI = true;
814
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
815
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
818
816
  await this.openAPIRefreshStatus();
819
817
  }
820
818
  }
@@ -41,7 +41,6 @@ export class Humidifier {
41
41
  connected?: boolean;
42
42
  serviceData!: serviceData;
43
43
  address!: ad['address'];
44
- SwitchToOpenAPI?: boolean;
45
44
  onState!: serviceData['onState'];
46
45
  autoMode!: serviceData['autoMode'];
47
46
  percentage!: serviceData['percentage'];
@@ -57,8 +56,8 @@ export class Humidifier {
57
56
  doHumidifierUpdate!: Subject<void>;
58
57
 
59
58
  // Connection
60
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
61
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
59
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
60
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
62
61
 
63
62
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
64
63
  // default placeholders
@@ -193,10 +192,9 @@ export class Humidifier {
193
192
  * Parse the device status from the SwitchBot api
194
193
  */
195
194
  async parseStatus(): Promise<void> {
196
- if (this.BLE && !this.SwitchToOpenAPI) {
195
+ if (this.BLE) {
197
196
  await this.BLEparseStatus();
198
197
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
199
- this.SwitchToOpenAPI = false;
200
198
  await this.openAPIparseStatus();
201
199
  } else {
202
200
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -343,20 +341,20 @@ export class Humidifier {
343
341
  // Stop to monitor
344
342
  switchbot.stopScan();
345
343
  if (this.connected) {
346
- this.parseStatus();
344
+ this.BLEparseStatus();
347
345
  this.updateHomeKitCharacteristics();
348
346
  } else {
349
- await this.BLEconnection(switchbot);
347
+ await this.BLERefreshConnection(switchbot);
350
348
  }
351
349
  })
352
350
  .catch(async (e: any) => {
353
351
  this.apiError(e);
354
352
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
355
353
  + ` Connection, Error Message: ${superStringify(e.message)}`);
356
- await this.BLEconnection(switchbot);
354
+ await this.BLERefreshConnection(switchbot);
357
355
  });
358
356
  } else {
359
- await this.BLEconnection(switchbot);
357
+ await this.BLERefreshConnection(switchbot);
360
358
  }
361
359
  }
362
360
 
@@ -399,7 +397,7 @@ export class Humidifier {
399
397
  this.humidity = this.deviceStatus.body.humidity;
400
398
  this.temperature = this.deviceStatus.body.temperature;
401
399
  this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
402
- this.parseStatus();
400
+ this.openAPIparseStatus();
403
401
  this.updateHomeKitCharacteristics();
404
402
  } catch (e: any) {
405
403
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -462,10 +460,7 @@ export class Humidifier {
462
460
  this.apiError(e);
463
461
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
464
462
  + ` Connection, Error Message: ${superStringify(e.message)}`);
465
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
466
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
467
- await this.openAPIpushChanges();
468
- }
463
+ await this.BLEPushConnection();
469
464
  });
470
465
  }
471
466
 
@@ -777,11 +772,17 @@ export class Humidifier {
777
772
  }
778
773
  }
779
774
 
780
- async BLEconnection(switchbot: any): Promise<void> {
775
+ async BLEPushConnection() {
776
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
777
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
778
+ await this.openAPIpushChanges();
779
+ }
780
+ }
781
+
782
+ async BLERefreshConnection(switchbot: any): Promise<void> {
781
783
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
782
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
783
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
784
- this.SwitchToOpenAPI = true;
784
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
785
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
785
786
  await this.openAPIRefreshStatus();
786
787
  }
787
788
  }
@@ -34,8 +34,8 @@ export class Lock {
34
34
  doLockUpdate!: Subject<void>;
35
35
 
36
36
  // Connection
37
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
38
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
37
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
38
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
39
39
 
40
40
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
41
41
  // default placeholders
@@ -132,10 +132,9 @@ export class Lock {
132
132
  * Parse the device status from the SwitchBot api
133
133
  */
134
134
  async parseStatus(): Promise<void> {
135
- /*if (this.BLE && !this.SwitchToOpenAPI) {
135
+ /*if (this.BLE) {
136
136
  await this.BLEparseStatus();
137
- } else*/ if (this.OpenAPI) {
138
- //this.SwitchToOpenAPI = false;
137
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
139
138
  await this.openAPIparseStatus();
140
139
  } else {
141
140
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -143,6 +142,27 @@ export class Lock {
143
142
  }
144
143
  }
145
144
 
145
+ async BLEparseStatus(): Promise<void> {
146
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
147
+ switch (this.lockState) {
148
+ case 'locked':
149
+ this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
150
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
151
+ break;
152
+ default:
153
+ this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
154
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.UNSECURED;
155
+ }
156
+ switch (this.doorState) {
157
+ case 'opened':
158
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
159
+ break;
160
+ default:
161
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
162
+ }
163
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
164
+ }
165
+
146
166
  //{"deviceId":"DBDC23B53139","deviceType":"Smart Lock","hubDeviceId":"E68B14109DA2","lockState":"locked","doorState":"opened","calibrate":true}
147
167
 
148
168
  async openAPIparseStatus(): Promise<void> {
@@ -215,7 +235,7 @@ export class Lock {
215
235
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
216
236
  this.lockState = this.deviceStatus.body.lockState;
217
237
  this.doorState = this.deviceStatus.body.doorState;
218
- this.parseStatus();
238
+ this.openAPIparseStatus();
219
239
  this.updateHomeKitCharacteristics();
220
240
  } catch (e: any) {
221
241
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -280,10 +300,7 @@ export class Lock {
280
300
  this.apiError(e);
281
301
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
282
302
  + ` Connection, Error Message: ${superStringify(e.message)}`);
283
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
284
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
285
- await this.openAPIpushChanges();
286
- }
303
+ await this.BLEPushConnection();
287
304
  });
288
305
  } else {
289
306
  this.debugLog(
@@ -395,6 +412,21 @@ export class Lock {
395
412
  }
396
413
  }
397
414
 
415
+ async BLEPushConnection() {
416
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
417
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
418
+ await this.openAPIpushChanges();
419
+ }
420
+ }
421
+
422
+ async BLERefreshConnection(switchbot: any): Promise<void> {
423
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
424
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
425
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
426
+ await this.openAPIRefreshStatus();
427
+ }
428
+ }
429
+
398
430
  async scan(device: device & devicesConfig): Promise<void> {
399
431
  if (device.scanDuration) {
400
432
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
@@ -40,7 +40,6 @@ export class Meter {
40
40
  switchbot!: switchbot;
41
41
  serviceData!: serviceData;
42
42
  address!: ad['address'];
43
- SwitchToOpenAPI?: boolean;
44
43
  temperature!: temperature['c'];
45
44
  battery!: serviceData['battery'];
46
45
  humidity!: serviceData['humidity'];
@@ -61,8 +60,8 @@ export class Meter {
61
60
  doMeterUpdate: Subject<void>;
62
61
 
63
62
  // Connection
64
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
65
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
63
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
64
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
66
65
 
67
66
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
68
67
  // default placeholders
@@ -177,10 +176,9 @@ export class Meter {
177
176
  * Parse the device status from the SwitchBot api
178
177
  */
179
178
  async parseStatus(): Promise<void> {
180
- if (this.BLE && !this.SwitchToOpenAPI) {
179
+ if (this.BLE) {
181
180
  await this.BLEparseStatus();
182
181
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
183
- this.SwitchToOpenAPI = false;
184
182
  await this.openAPIparseStatus();
185
183
  } else {
186
184
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -299,20 +297,20 @@ export class Meter {
299
297
  // Stop to monitor
300
298
  switchbot.stopScan();
301
299
  if (this.connected) {
302
- this.parseStatus();
300
+ this.BLEparseStatus();
303
301
  this.updateHomeKitCharacteristics();
304
302
  } else {
305
- await this.BLEconnection(switchbot);
303
+ await this.BLERefreshConnection(switchbot);
306
304
  }
307
305
  })
308
306
  .catch(async (e: any) => {
309
307
  this.apiError(e);
310
308
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
311
309
  + ` Connection, Error Message: ${superStringify(e.message)}`);
312
- await this.BLEconnection(switchbot);
310
+ await this.BLERefreshConnection(switchbot);
313
311
  });
314
312
  } else {
315
- await this.BLEconnection(switchbot);
313
+ await this.BLERefreshConnection(switchbot);
316
314
  }
317
315
  }
318
316
 
@@ -351,7 +349,7 @@ export class Meter {
351
349
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
352
350
  this.Humidity = this.deviceStatus.body.humidity!;
353
351
  this.Temperature = this.deviceStatus.body.temperature!;
354
- this.parseStatus();
352
+ this.openAPIparseStatus();
355
353
  this.updateHomeKitCharacteristics();
356
354
  } catch (e: any) {
357
355
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -491,11 +489,10 @@ export class Meter {
491
489
  }
492
490
  }
493
491
 
494
- async BLEconnection(switchbot: any): Promise<void> {
492
+ async BLERefreshConnection(switchbot: any): Promise<void> {
495
493
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
496
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
497
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
498
- this.SwitchToOpenAPI = true;
494
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
495
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
499
496
  await this.openAPIRefreshStatus();
500
497
  }
501
498
  }
@@ -40,7 +40,6 @@ export class MeterPlus {
40
40
  switchbot!: switchbot;
41
41
  serviceData!: serviceData;
42
42
  address!: ad['address'];
43
- SwitchToOpenAPI?: boolean;
44
43
  temperature!: temperature['c'];
45
44
  battery!: serviceData['battery'];
46
45
  humidity!: serviceData['humidity'];
@@ -61,8 +60,8 @@ export class MeterPlus {
61
60
  doMeterUpdate: Subject<void>;
62
61
 
63
62
  // Connection
64
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
65
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
63
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
64
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
66
65
 
67
66
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
68
67
  // default placeholders
@@ -177,10 +176,9 @@ export class MeterPlus {
177
176
  * Parse the device status from the SwitchBot api
178
177
  */
179
178
  async parseStatus(): Promise<void> {
180
- if (this.BLE && !this.SwitchToOpenAPI) {
179
+ if (this.BLE) {
181
180
  await this.BLEparseStatus();
182
181
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
183
- this.SwitchToOpenAPI = false;
184
182
  await this.openAPIparseStatus();
185
183
  } else {
186
184
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -302,17 +300,17 @@ export class MeterPlus {
302
300
  this.parseStatus();
303
301
  this.updateHomeKitCharacteristics();
304
302
  } else {
305
- await this.BLEconnection(switchbot);
303
+ await this.BLERefreshConnection(switchbot);
306
304
  }
307
305
  })
308
306
  .catch(async (e: any) => {
309
307
  this.apiError(e);
310
308
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
311
309
  + ` Connection, Error Message: ${superStringify(e.message)}`);
312
- await this.BLEconnection(switchbot);
310
+ await this.BLERefreshConnection(switchbot);
313
311
  });
314
312
  } else {
315
- await this.BLEconnection(switchbot);
313
+ await this.BLERefreshConnection(switchbot);
316
314
  }
317
315
  }
318
316
 
@@ -490,11 +488,10 @@ export class MeterPlus {
490
488
  }
491
489
  }
492
490
 
493
- async BLEconnection(switchbot: any): Promise<void> {
491
+ async BLERefreshConnection(switchbot: any): Promise<void> {
494
492
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
495
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
496
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
497
- this.SwitchToOpenAPI = true;
493
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
494
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
498
495
  await this.openAPIRefreshStatus();
499
496
  }
500
497
  }
@@ -36,7 +36,6 @@ export class Motion {
36
36
  switchbot!: switchbot;
37
37
  serviceData!: serviceData;
38
38
  address!: ad['address'];
39
- SwitchToOpenAPI?: boolean;
40
39
  battery!: serviceData['battery'];
41
40
  movement!: serviceData['movement'];
42
41
  lightLevel!: serviceData['lightLevel'];
@@ -53,8 +52,8 @@ export class Motion {
53
52
  doMotionUpdate!: Subject<void>;
54
53
 
55
54
  // Connection
56
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
57
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
55
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
56
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
58
57
 
59
58
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
60
59
  // default placeholders
@@ -143,10 +142,9 @@ export class Motion {
143
142
  * Parse the device status from the SwitchBot api
144
143
  */
145
144
  async parseStatus(): Promise<void> {
146
- if (this.BLE && !this.SwitchToOpenAPI) {
145
+ if (this.BLE) {
147
146
  await this.BLEparseStatus();
148
147
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
149
- this.SwitchToOpenAPI = false;
150
148
  await this.openAPIparseStatus();
151
149
  } else {
152
150
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -279,20 +277,20 @@ export class Motion {
279
277
  // Stop to monitor
280
278
  switchbot.stopScan();
281
279
  if (this.connected) {
282
- this.parseStatus();
280
+ this.BLEparseStatus();
283
281
  this.updateHomeKitCharacteristics();
284
282
  } else {
285
- await this.BLEconnection(switchbot);
283
+ await this.BLERefreshConnection(switchbot);
286
284
  }
287
285
  })
288
286
  .catch(async (e: any) => {
289
287
  this.apiError(e);
290
288
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
291
289
  + ` Connection, Error Message: ${superStringify(e.message)}`);
292
- await this.BLEconnection(switchbot);
290
+ await this.BLERefreshConnection(switchbot);
293
291
  });
294
292
  } else {
295
- await this.BLEconnection(switchbot);
293
+ await this.BLERefreshConnection(switchbot);
296
294
  }
297
295
  }
298
296
 
@@ -332,7 +330,7 @@ export class Motion {
332
330
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
333
331
  this.moveDetected = this.deviceStatus.body.moveDetected;
334
332
  this.brightness = this.deviceStatus.body.brightness;
335
- this.parseStatus();
333
+ this.openAPIparseStatus();
336
334
  this.updateHomeKitCharacteristics();
337
335
  } catch (e: any) {
338
336
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -407,11 +405,10 @@ export class Motion {
407
405
  }
408
406
  }
409
407
 
410
- async BLEconnection(switchbot: any): Promise<void> {
408
+ async BLERefreshConnection(switchbot: any): Promise<void> {
411
409
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
412
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
413
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
414
- this.SwitchToOpenAPI = true;
410
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
411
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
415
412
  await this.openAPIRefreshStatus();
416
413
  }
417
414
  }