@switchbot/homebridge-switchbot 1.7.1-beta.0 → 1.7.1-beta.4

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.
@@ -38,6 +38,7 @@ export class Bot {
38
38
  // BLE Others
39
39
  connected?: boolean;
40
40
  switchbot!: switchbot;
41
+ SwitchToOpenAPI?: boolean;
41
42
  serviceData!: serviceData;
42
43
  mode!: serviceData['mode'];
43
44
  state!: serviceData['state'];
@@ -317,12 +318,21 @@ export class Bot {
317
318
  this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
318
319
  }
319
320
 
320
- if (device.ble) {
321
+ // Battery Service
322
+ if (!device.ble) {
323
+ this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
324
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
325
+ accessory.removeService(this.batteryService!);
326
+ } else if (!this.batteryService) {
327
+ this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
321
328
  (this.batteryService =
322
- accessory.getService(this.platform.Service.Battery) ||
323
- accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
329
+ this.accessory.getService(this.platform.Service.Battery) ||
330
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
324
331
 
325
332
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
333
+
334
+ } else {
335
+ this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
326
336
  }
327
337
 
328
338
  // Retrieve initial values and updateHomekit
@@ -523,10 +533,10 @@ export class Bot {
523
533
  * Parse the device status from the SwitchBot api
524
534
  */
525
535
  async parseStatus() {
526
- if (this.device.ble) {
527
- await this.BLEparseStatus();
528
- } else {
536
+ if (this.SwitchToOpenAPI || !this.device.ble) {
529
537
  await this.openAPIparseStatus();
538
+ } else {
539
+ await this.BLEparseStatus();
530
540
  }
531
541
  }
532
542
 
@@ -560,6 +570,9 @@ export class Bot {
560
570
  }
561
571
 
562
572
  private async openAPIparseStatus() {
573
+ if (this.device.ble) {
574
+ this.SwitchToOpenAPI = false;
575
+ }
563
576
  if (this.platform.config.credentials?.openToken) {
564
577
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
565
578
  if (this.botMode === 'press') {
@@ -664,6 +677,7 @@ export class Bot {
664
677
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
665
678
  if (this.platform.config.credentials?.openToken) {
666
679
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
680
+ this.SwitchToOpenAPI = true;
667
681
  await this.openAPIRefreshStatus();
668
682
  }
669
683
  }
@@ -679,6 +693,7 @@ export class Bot {
679
693
  }
680
694
  if (this.platform.config.credentials?.openToken) {
681
695
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
696
+ this.SwitchToOpenAPI = true;
682
697
  await this.openAPIRefreshStatus();
683
698
  }
684
699
  this.apiError(e);
@@ -29,6 +29,7 @@ export class Contact {
29
29
  // BLE Others
30
30
  connected?: boolean;
31
31
  switchbot!: switchbot;
32
+ SwitchToOpenAPI!: boolean;
32
33
  serviceData!: serviceData;
33
34
  battery!: serviceData['battery'];
34
35
  movement!: serviceData['movement'];
@@ -38,7 +39,6 @@ export class Contact {
38
39
  // Config
39
40
  set_minLux!: number;
40
41
  set_maxLux!: number;
41
- spaceBetweenLevels!: number;
42
42
  scanDuration!: number;
43
43
  deviceLogging!: string;
44
44
  deviceRefreshRate!: number;
@@ -60,8 +60,8 @@ export class Contact {
60
60
 
61
61
  // Contact Config
62
62
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline},`
63
- + ` hide_lightsensor: ${device.contact?.hide_lightsensor}, hide_motionsensor: ${device.contact?.hide_motionsensor})`);
64
-
63
+ + ` hide_lightsensor: ${device.contact?.hide_lightsensor}, hide_motionsensor: ${device.contact?.hide_motionsensor},`
64
+ + ` set_minLux: ${this.device.contact?.set_minLux}, set_maxLux: ${this.device.contact?.set_maxLux})`);
65
65
 
66
66
  // this is subject we use to track when we need to POST changes to the SwitchBot API
67
67
  this.doContactUpdate = new Subject();
@@ -92,7 +92,7 @@ export class Contact {
92
92
  this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
93
93
 
94
94
  // each service must implement at-minimum the "required characteristics" for the given service type
95
- // see https://developers.homebridge.io/#/service/MotionSensor
95
+ // see https://developers.homebridge.io/#/service/ContactSensor
96
96
 
97
97
  // Motion Sensor Service
98
98
  if (device.contact?.hide_motionsensor) {
@@ -128,12 +128,21 @@ export class Contact {
128
128
  this.debugLog(`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
129
129
  }
130
130
 
131
- if (device.ble) {
131
+ // Battery Service
132
+ if (!device.ble) {
133
+ this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Battery Service`);
134
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
135
+ accessory.removeService(this.batteryService!);
136
+ } else if (!this.batteryService) {
137
+ this.debugLog(`Contact Sensor: ${accessory.displayName} Add Battery Service`);
132
138
  (this.batteryService =
133
- accessory.getService(this.platform.Service.Battery) ||
134
- accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
139
+ this.accessory.getService(this.platform.Service.Battery) ||
140
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
135
141
 
136
142
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
143
+
144
+ } else {
145
+ this.debugLog(`Contact Sensor: ${accessory.displayName} Battery Service Not Added`);
137
146
  }
138
147
 
139
148
  // Retrieve initial values and updateHomekit
@@ -195,7 +204,7 @@ export class Contact {
195
204
  }
196
205
 
197
206
  private minLux(): number {
198
- if (this.device.curtain?.set_minLux) {
207
+ if (this.device.contact?.set_minLux) {
199
208
  this.set_minLux = this.device.contact!.set_minLux!;
200
209
  } else {
201
210
  this.set_minLux = 1;
@@ -204,7 +213,7 @@ export class Contact {
204
213
  }
205
214
 
206
215
  private maxLux(): number {
207
- if (this.device.curtain?.set_maxLux) {
216
+ if (this.device.contact?.set_maxLux) {
208
217
  this.set_maxLux = this.device.contact!.set_maxLux!;
209
218
  } else {
210
219
  this.set_maxLux = 6001;
@@ -216,19 +225,15 @@ export class Contact {
216
225
  * Parse the device status from the SwitchBot api
217
226
  */
218
227
  async parseStatus() {
219
- if (this.device.ble) {
220
- await this.BLEparseStatus();
221
- } else {
228
+ if (this.SwitchToOpenAPI || !this.device.ble) {
222
229
  await this.openAPIparseStatus();
230
+ } else {
231
+ await this.BLEparseStatus();
223
232
  }
224
233
  }
225
234
 
226
235
  private async BLEparseStatus() {
227
236
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
228
- if (!this.device.contact?.hide_motionsensor) {
229
- // Movement
230
- this.MotionDetected = Boolean(this.movement);
231
- }
232
237
  // Door State
233
238
  switch (this.doorState) {
234
239
  case 'open':
@@ -242,90 +247,46 @@ export class Contact {
242
247
  default:
243
248
  this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
244
249
  }
245
- // Light Level
246
- if (!this.device.contact?.hide_lightsensor) {
247
- switch (this.lightLevel) {
248
- case 'dark':
249
- case 0:
250
- this.CurrentAmbientLightLevel = 0.0001;
251
- break;
252
- default:
253
- this.CurrentAmbientLightLevel = 100000;
254
- }
250
+ // Movement
251
+ if (!this.device.contact?.hide_motionsensor) {
252
+ this.MotionDetected = Boolean(this.movement);
253
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
255
254
  }
256
-
257
- /*
258
255
  // Light Level
259
256
  if (!this.device.contact?.hide_lightsensor) {
260
257
  this.set_minLux = this.minLux();
261
258
  this.set_maxLux = this.maxLux();
262
- this.spaceBetweenLevels = 9;
263
-
264
- //
265
259
  switch (this.lightLevel) {
266
- case 1:
260
+ case 'dark':
261
+ case 0:
267
262
  this.CurrentAmbientLightLevel = this.set_minLux;
268
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
269
- break;
270
- case 2:
271
- this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels);
272
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
273
- + ` Calculation: ${((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels)}`);
274
- break;
275
- case 3:
276
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2);
277
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
278
- break;
279
- case 4:
280
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3);
281
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
282
263
  break;
283
- case 5:
284
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4);
285
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
286
- break;
287
- case 6:
288
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5);
289
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
290
- break;
291
- case 7:
292
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6);
293
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
294
- break;
295
- case 8:
296
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7);
297
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
298
- break;
299
- case 9:
300
- this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8);
301
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
302
- break;
303
- case 10:
304
264
  default:
305
265
  this.CurrentAmbientLightLevel = this.set_maxLux;
306
- this.debugLog();
307
266
  }
308
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
267
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
309
268
  + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
310
- }*/
311
-
312
-
269
+ }
313
270
  // Battery
271
+ if (this.battery === undefined) {
272
+ this.battery === 100;
273
+ }
314
274
  this.BatteryLevel = Number(this.battery);
315
275
  if (this.BatteryLevel < 10) {
316
276
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
317
277
  } else {
318
278
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
319
279
  }
320
-
321
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}, MotionDetected: `
322
- + `${this.MotionDetected}, CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}, BatteryLevel: ${this.BatteryLevel}`);
280
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
323
281
  }
324
282
 
325
283
  private async openAPIparseStatus() {
284
+ if (this.device.ble) {
285
+ this.SwitchToOpenAPI = false;
286
+ }
326
287
  if (this.platform.config.credentials?.openToken) {
327
- // Contact State
328
288
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
289
+ // Contact State
329
290
  if (this.deviceStatus.body.openState === 'open') {
330
291
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
331
292
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
@@ -337,14 +298,15 @@ export class Contact {
337
298
  }
338
299
  // Motion State
339
300
  if (!this.device.contact?.hide_motionsensor) {
340
- this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
301
+ if (typeof this.deviceStatus.body.moveDetected === 'boolean') {
302
+ this.MotionDetected = this.deviceStatus.body.moveDetected;
303
+ }
304
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
341
305
  }
342
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
343
306
  // Light Level
344
307
  if (!this.device.contact?.hide_lightsensor) {
345
308
  this.set_minLux = this.minLux();
346
309
  this.set_maxLux = this.maxLux();
347
- // Brightness
348
310
  switch (this.deviceStatus.body.brightness) {
349
311
  case 'dim':
350
312
  this.CurrentAmbientLightLevel = this.set_minLux;
@@ -449,6 +411,7 @@ export class Contact {
449
411
  }
450
412
  if (this.platform.config.credentials?.openToken) {
451
413
  this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
414
+ this.SwitchToOpenAPI = true;
452
415
  await this.openAPIRefreshStatus();
453
416
  }
454
417
  this.apiError(e);
@@ -462,6 +425,7 @@ export class Contact {
462
425
  this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
463
426
  if (this.platform.config.credentials?.openToken) {
464
427
  this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
428
+ this.SwitchToOpenAPI = true;
465
429
  await this.openAPIRefreshStatus();
466
430
  }
467
431
  }
@@ -26,11 +26,13 @@ export class Curtain {
26
26
  // BLE Others
27
27
  connected?: boolean;
28
28
  switchbot!: switchbot;
29
+ SwitchToOpenAPI?: boolean;
29
30
  serviceData!: serviceData;
30
31
  calibration: serviceData['calibration'];
31
32
  battery: serviceData['battery'];
32
33
  position: serviceData['position'];
33
34
  lightLevel: serviceData['lightLevel'];
35
+ spaceBetweenLevels!: number;
34
36
 
35
37
  // Target
36
38
  setNewTarget!: boolean;
@@ -44,7 +46,6 @@ export class Curtain {
44
46
  scanDuration!: number;
45
47
  deviceLogging!: string;
46
48
  deviceRefreshRate!: number;
47
- spaceBetweenLevels!: number;
48
49
 
49
50
  // Updates
50
51
  curtainUpdateInProgress!: boolean;
@@ -142,6 +143,23 @@ export class Curtain {
142
143
  this.debugLog(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
143
144
  }
144
145
 
146
+ // Battery Service
147
+ if (!device.ble) {
148
+ this.debugLog(`Curtain: ${accessory.displayName} Removing Battery Service`);
149
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
150
+ accessory.removeService(this.batteryService!);
151
+ } else if (!this.batteryService) {
152
+ this.debugLog(`Curtain: ${accessory.displayName} Add Battery Service`);
153
+ (this.batteryService =
154
+ this.accessory.getService(this.platform.Service.Battery) ||
155
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
156
+
157
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
158
+
159
+ } else {
160
+ this.debugLog(`Curtain: ${accessory.displayName} Battery Service Not Added`);
161
+ }
162
+
145
163
 
146
164
  // Update Homekit
147
165
  this.updateHomeKitCharacteristics();
@@ -253,30 +271,6 @@ export class Curtain {
253
271
  }
254
272
  }
255
273
 
256
- public async connectBLE() {
257
- let switchbot: any;
258
- try {
259
- // eslint-disable-next-line @typescript-eslint/no-var-requires
260
- const Switchbot = require('node-switchbot');
261
- switchbot = new Switchbot();
262
- // Convert to BLE Address
263
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
264
- this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
265
- } catch (e: any) {
266
- switchbot = false;
267
- this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
268
- if (this.deviceLogging === 'debug') {
269
- this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
270
- + ` Error Message: ${JSON.stringify(e.message)}`);
271
- }
272
- if (this.platform.debugMode) {
273
- this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
274
- + ` Error: ${JSON.stringify(e)}`);
275
- }
276
- }
277
- return switchbot;
278
- }
279
-
280
274
  private minStep(): number {
281
275
  if (this.device.curtain?.set_minStep) {
282
276
  this.set_minStep = this.device.curtain?.set_minStep;
@@ -304,11 +298,14 @@ export class Curtain {
304
298
  return this.set_maxLux;
305
299
  }
306
300
 
301
+ /**
302
+ * Parse the device status from the SwitchBot api
303
+ */
307
304
  async parseStatus() {
308
- if (this.device.ble) {
309
- await this.BLEparseStatus();
310
- } else {
305
+ if (this.SwitchToOpenAPI || !this.device.ble) {
311
306
  await this.openAPIparseStatus();
307
+ } else {
308
+ await this.BLEparseStatus();
312
309
  }
313
310
  }
314
311
 
@@ -407,6 +404,9 @@ export class Curtain {
407
404
  }
408
405
 
409
406
  private async openAPIparseStatus() {
407
+ if (this.device.ble) {
408
+ this.SwitchToOpenAPI = false;
409
+ }
410
410
  if (this.platform.config.credentials?.openToken) {
411
411
  this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
412
412
  // CurrentPosition
@@ -468,7 +468,10 @@ export class Curtain {
468
468
  private async BLERefreshStatus() {
469
469
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
470
470
  // eslint-disable-next-line @typescript-eslint/no-var-requires
471
- const switchbot = await this.connectBLE();
471
+ const switchbot = await this.platform.connectBLE();
472
+ // Convert to BLE Address
473
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
474
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
472
475
  // Start to monitor advertisement packets
473
476
  if (switchbot !== false) {
474
477
  switchbot.startScan({
@@ -506,6 +509,7 @@ export class Curtain {
506
509
  this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
507
510
  if (this.platform.config.credentials?.openToken) {
508
511
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
512
+ this.SwitchToOpenAPI = true;
509
513
  await this.openAPIRefreshStatus();
510
514
  }
511
515
  }
@@ -521,6 +525,7 @@ export class Curtain {
521
525
  }
522
526
  if (this.platform.config.credentials?.openToken) {
523
527
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
528
+ this.SwitchToOpenAPI = true;
524
529
  await this.openAPIRefreshStatus();
525
530
  }
526
531
  this.apiError(e);
@@ -534,6 +539,7 @@ export class Curtain {
534
539
  this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
535
540
  if (this.platform.config.credentials?.openToken) {
536
541
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
542
+ this.SwitchToOpenAPI = true;
537
543
  await this.openAPIRefreshStatus();
538
544
  }
539
545
  }
@@ -578,7 +584,10 @@ export class Curtain {
578
584
  private async BLEpushChanges() {
579
585
  if (this.TargetPosition !== this.CurrentPosition) {
580
586
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
581
- const switchbot = await this.connectBLE();
587
+ const switchbot = await this.platform.connectBLE();
588
+ // Convert to BLE Address
589
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
590
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
582
591
  if (switchbot !== false) {
583
592
  switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
584
593
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
@@ -33,6 +33,7 @@ export class Meter {
33
33
  // BLE Others
34
34
  connected?: boolean;
35
35
  switchbot!: switchbot;
36
+ SwitchToOpenAPI?: boolean;
36
37
  serviceData!: serviceData;
37
38
  temperature!: temperature['c'];
38
39
  battery!: serviceData['battery'];
@@ -232,10 +233,10 @@ export class Meter {
232
233
  * Parse the device status from the SwitchBot api
233
234
  */
234
235
  async parseStatus() {
235
- if (this.device.ble) {
236
- await this.BLEparseStatus();
237
- } else {
236
+ if (this.SwitchToOpenAPI || !this.device.ble) {
238
237
  await this.openAPIparseStatus();
238
+ } else {
239
+ await this.BLEparseStatus();
239
240
  }
240
241
  }
241
242
 
@@ -266,6 +267,9 @@ export class Meter {
266
267
  }
267
268
 
268
269
  private async openAPIparseStatus() {
270
+ if (this.device.ble) {
271
+ this.SwitchToOpenAPI = false;
272
+ }
269
273
  if (this.platform.config.credentials?.openToken) {
270
274
  this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI parseStatus`);
271
275
  if (this.deviceStatus.body) {
@@ -385,6 +389,7 @@ export class Meter {
385
389
  }
386
390
  if (this.platform.config.credentials?.openToken) {
387
391
  this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
392
+ this.SwitchToOpenAPI = true;
388
393
  this.openAPIRefreshStatus();
389
394
  }
390
395
  this.apiError(e);
@@ -398,6 +403,7 @@ export class Meter {
398
403
  this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
399
404
  if (this.platform.config.credentials?.openToken) {
400
405
  this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
406
+ this.SwitchToOpenAPI = true;
401
407
  await this.openAPIRefreshStatus();
402
408
  }
403
409
  }