@switchbot/homebridge-switchbot 1.7.1-beta.1 → 1.7.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.
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
- import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
7
+ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
8
8
 
9
9
  export class Curtain {
10
10
  // Services
@@ -22,16 +22,20 @@ export class Curtain {
22
22
 
23
23
  // OpenAPI Others
24
24
  deviceStatus!: deviceStatusResponse;
25
+ slidePosition: deviceStatus['slidePosition'];
26
+ moving: deviceStatus['moving'];
27
+ brightness: deviceStatus['brightness'];
25
28
 
26
29
  // BLE Others
27
30
  connected?: boolean;
28
31
  switchbot!: switchbot;
32
+ SwitchToOpenAPI?: boolean;
29
33
  serviceData!: serviceData;
34
+ spaceBetweenLevels!: number;
30
35
  calibration: serviceData['calibration'];
31
36
  battery: serviceData['battery'];
32
37
  position: serviceData['position'];
33
38
  lightLevel: serviceData['lightLevel'];
34
- spaceBetweenLevels!: number;
35
39
 
36
40
  // Target
37
41
  setNewTarget!: boolean;
@@ -142,6 +146,23 @@ export class Curtain {
142
146
  this.debugLog(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
143
147
  }
144
148
 
149
+ // Battery Service
150
+ if (!device.ble) {
151
+ this.debugLog(`Curtain: ${accessory.displayName} Removing Battery Service`);
152
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
153
+ accessory.removeService(this.batteryService!);
154
+ } else if (!this.batteryService) {
155
+ this.debugLog(`Curtain: ${accessory.displayName} Add Battery Service`);
156
+ (this.batteryService =
157
+ this.accessory.getService(this.platform.Service.Battery) ||
158
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
159
+
160
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
161
+
162
+ } else {
163
+ this.debugLog(`Curtain: ${accessory.displayName} Battery Service Not Added`);
164
+ }
165
+
145
166
 
146
167
  // Update Homekit
147
168
  this.updateHomeKitCharacteristics();
@@ -253,30 +274,6 @@ export class Curtain {
253
274
  }
254
275
  }
255
276
 
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
277
  private minStep(): number {
281
278
  if (this.device.curtain?.set_minStep) {
282
279
  this.set_minStep = this.device.curtain?.set_minStep;
@@ -304,16 +301,20 @@ export class Curtain {
304
301
  return this.set_maxLux;
305
302
  }
306
303
 
304
+ /**
305
+ * Parse the device status from the SwitchBot api
306
+ */
307
307
  async parseStatus() {
308
- if (this.device.ble) {
309
- await this.BLEparseStatus();
310
- } else {
308
+ if (this.SwitchToOpenAPI || !this.device.ble) {
311
309
  await this.openAPIparseStatus();
310
+ } else {
311
+ await this.BLEparseStatus();
312
312
  }
313
313
  }
314
314
 
315
315
  private async BLEparseStatus() {
316
316
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
317
+ // CurrentPosition
317
318
  this.setMinMax();
318
319
  this.CurrentPosition = 100 - Number(this.position);
319
320
  this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
@@ -339,6 +340,7 @@ export class Curtain {
339
340
  // If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
340
341
  this.TargetPosition = this.CurrentPosition;
341
342
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
343
+ this.infoLog(`Curtain: ${this.accessory.displayName} Stopped`);
342
344
  }
343
345
  }
344
346
  this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
@@ -407,17 +409,20 @@ export class Curtain {
407
409
  }
408
410
 
409
411
  private async openAPIparseStatus() {
412
+ if (this.device.ble) {
413
+ this.SwitchToOpenAPI = false;
414
+ }
410
415
  if (this.platform.config.credentials?.openToken) {
411
416
  this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
412
417
  // CurrentPosition
413
418
  this.setMinMax();
414
- this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
419
+ this.CurrentPosition = 100 - Number(this.slidePosition);
415
420
  this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
416
421
  if (this.setNewTarget) {
417
- this.infoLog(`Checking ${this.accessory.displayName} Status ...`);
422
+ this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
418
423
  }
419
424
 
420
- if (this.deviceStatus.body.moving) {
425
+ if (this.setNewTarget && this.moving) {
421
426
  this.setMinMax();
422
427
  if (this.TargetPosition > this.CurrentPosition) {
423
428
  this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
@@ -435,6 +440,7 @@ export class Curtain {
435
440
  /*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
436
441
  this.TargetPosition = this.CurrentPosition;
437
442
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
443
+ this.infoLog(`Curtain: ${this.accessory.displayName} Stopped`);
438
444
  }
439
445
  }
440
446
  this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
@@ -444,7 +450,7 @@ export class Curtain {
444
450
  this.set_minLux = this.minLux();
445
451
  this.set_maxLux = this.maxLux();
446
452
  // Brightness
447
- switch (this.deviceStatus.body.brightness) {
453
+ switch (this.brightness) {
448
454
  case 'dim':
449
455
  this.CurrentAmbientLightLevel = this.set_minLux;
450
456
  break;
@@ -468,7 +474,10 @@ export class Curtain {
468
474
  private async BLERefreshStatus() {
469
475
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
470
476
  // eslint-disable-next-line @typescript-eslint/no-var-requires
471
- const switchbot = await this.connectBLE();
477
+ const switchbot = await this.platform.connectBLE();
478
+ // Convert to BLE Address
479
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
480
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
472
481
  // Start to monitor advertisement packets
473
482
  if (switchbot !== false) {
474
483
  switchbot.startScan({
@@ -506,6 +515,7 @@ export class Curtain {
506
515
  this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
507
516
  if (this.platform.config.credentials?.openToken) {
508
517
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
518
+ this.SwitchToOpenAPI = true;
509
519
  await this.openAPIRefreshStatus();
510
520
  }
511
521
  }
@@ -521,6 +531,7 @@ export class Curtain {
521
531
  }
522
532
  if (this.platform.config.credentials?.openToken) {
523
533
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
534
+ this.SwitchToOpenAPI = true;
524
535
  await this.openAPIRefreshStatus();
525
536
  }
526
537
  this.apiError(e);
@@ -534,6 +545,7 @@ export class Curtain {
534
545
  this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
535
546
  if (this.platform.config.credentials?.openToken) {
536
547
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
548
+ this.SwitchToOpenAPI = true;
537
549
  await this.openAPIRefreshStatus();
538
550
  }
539
551
  }
@@ -544,6 +556,9 @@ export class Curtain {
544
556
  try {
545
557
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
546
558
  this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
559
+ this.slidePosition = this.deviceStatus.body.slidePosition;
560
+ this.moving = this.deviceStatus.body.moving;
561
+ this.brightness = this.deviceStatus.body.brightness;
547
562
  this.parseStatus();
548
563
  this.updateHomeKitCharacteristics();
549
564
  } catch (e: any) {
@@ -578,7 +593,10 @@ export class Curtain {
578
593
  private async BLEpushChanges() {
579
594
  if (this.TargetPosition !== this.CurrentPosition) {
580
595
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
581
- const switchbot = await this.connectBLE();
596
+ const switchbot = await this.platform.connectBLE();
597
+ // Convert to BLE Address
598
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
599
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
582
600
  if (switchbot !== false) {
583
601
  switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
584
602
  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
  }
@@ -2,7 +2,7 @@ import { interval, Subject } from 'rxjs';
2
2
  import { skipWhile } from 'rxjs/operators';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
- import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
5
+ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
6
6
 
7
7
  /**
8
8
  * Platform Accessory
@@ -23,10 +23,13 @@ export class Motion {
23
23
 
24
24
  // OpenAPI Others
25
25
  deviceStatus!: deviceStatusResponse;
26
+ moveDetected: deviceStatus['moveDetected'];
27
+ brightness: deviceStatus['brightness'];
26
28
 
27
29
  // BLE Others
28
30
  connected?: boolean;
29
31
  switchbot!: switchbot;
32
+ SwitchToOpenAPI?: boolean;
30
33
  serviceData!: serviceData;
31
34
  battery!: serviceData['battery'];
32
35
  movement!: serviceData['movement'];
@@ -108,12 +111,20 @@ export class Motion {
108
111
  }
109
112
 
110
113
  // Battery Service
111
- if (device.ble) {
114
+ if (!device.ble) {
115
+ this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Battery Service`);
116
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
117
+ accessory.removeService(this.batteryService!);
118
+ } else if (!this.batteryService) {
119
+ this.debugLog(`Motion Sensor: ${accessory.displayName} Add Battery Service`);
112
120
  (this.batteryService =
113
- accessory.getService(this.platform.Service.Battery) ||
114
- accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
121
+ this.accessory.getService(this.platform.Service.Battery) ||
122
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
115
123
 
116
124
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
125
+
126
+ } else {
127
+ this.debugLog(`Motion Sensor: ${accessory.displayName} Battery Service Not Added`);
117
128
  }
118
129
 
119
130
  // Retrieve initial values and updateHomekit
@@ -196,42 +207,38 @@ export class Motion {
196
207
  * Parse the device status from the SwitchBot api
197
208
  */
198
209
  async parseStatus() {
199
- if (this.device.ble) {
200
- await this.BLEparseStatus();
201
- } else {
210
+ if (this.SwitchToOpenAPI || !this.device.ble) {
202
211
  await this.openAPIparseStatus();
212
+ } else {
213
+ await this.BLEparseStatus();
203
214
  }
204
215
  }
205
216
 
206
217
  private async BLEparseStatus() {
207
218
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
208
219
  // Movement
209
- if (this.movement === undefined && this.platform.config.credentials?.openToken) {
210
- this.openAPImotion();
211
- } else if (this.movement === undefined) {
212
- this.movement = false;
213
- this.BLEmotion();
214
- } else {
215
- this.BLEmotion();
216
- }
220
+ this.MotionDetected = this.movement!;
221
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
217
222
  // Light Level
218
223
  if (!this.device.motion?.hide_lightsensor) {
219
224
  this.set_minLux = this.minLux();
220
225
  this.set_maxLux = this.maxLux();
221
- if (this.lightLevel === undefined && this.platform.config.credentials?.openToken) {
222
- this.openAPIlux();
223
- } else if (this.lightLevel === undefined) {
224
- this.lightLevel = 100;
225
- this.BLElux();
226
- } else {
227
- this.BLElux();
226
+ switch (this.lightLevel) {
227
+ case 'dark':
228
+ case 1:
229
+ this.CurrentAmbientLightLevel = this.set_minLux;
230
+ break;
231
+ default:
232
+ this.CurrentAmbientLightLevel = this.set_maxLux;
228
233
  }
234
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
235
+ + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
229
236
  }
230
237
  // Battery
231
238
  if (this.battery === undefined) {
232
239
  this.battery = 100;
233
240
  }
234
- this.BatteryLevel = Number(this.battery);
241
+ this.BatteryLevel = this.battery!;
235
242
  if (this.BatteryLevel < 10) {
236
243
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
237
244
  } else {
@@ -240,55 +247,31 @@ export class Motion {
240
247
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
241
248
  }
242
249
 
243
- private BLEmotion() {
244
- this.MotionDetected = Boolean(this.movement);
245
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
246
- }
247
-
248
- private BLElux() {
249
- switch (this.lightLevel) {
250
- case 'dark':
251
- case 1:
252
- this.CurrentAmbientLightLevel = this.set_minLux;
253
- break;
254
- default:
255
- this.CurrentAmbientLightLevel = this.set_maxLux;
256
- }
257
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
258
- + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
259
- }
260
-
261
250
  private async openAPIparseStatus() {
251
+ if (this.device.ble) {
252
+ this.SwitchToOpenAPI = false;
253
+ }
262
254
  if (this.platform.config.credentials?.openToken) {
263
255
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
264
256
  // Motion State
265
- this.openAPImotion();
257
+ this.MotionDetected = this.moveDetected!;
258
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
266
259
  // Light Level
267
260
  if (!this.device.motion?.hide_lightsensor) {
268
- this.openAPIlux();
269
- }
270
- }
271
- }
272
-
273
- private openAPImotion() {
274
- if (typeof this.deviceStatus.body.moveDetected === 'boolean') {
275
- this.MotionDetected = this.deviceStatus.body.moveDetected;
276
- }
277
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
278
- }
261
+ this.set_minLux = this.minLux();
262
+ this.set_maxLux = this.maxLux();
263
+ switch (this.brightness) {
264
+ case 'dim':
265
+ this.CurrentAmbientLightLevel = this.set_minLux;
266
+ break;
267
+ case 'bright':
268
+ default:
269
+ this.CurrentAmbientLightLevel = this.set_maxLux;
270
+ }
271
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
279
272
 
280
- private openAPIlux() {
281
- this.set_minLux = this.minLux();
282
- this.set_maxLux = this.maxLux();
283
- switch (this.deviceStatus.body.brightness) {
284
- case 'dim':
285
- this.CurrentAmbientLightLevel = this.set_minLux;
286
- break;
287
- case 'bright':
288
- default:
289
- this.CurrentAmbientLightLevel = this.set_maxLux;
273
+ }
290
274
  }
291
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
292
275
  }
293
276
 
294
277
  /**
@@ -333,7 +316,7 @@ export class Motion {
333
316
  // Start to monitor advertisement packets
334
317
  if (switchbot !== false) {
335
318
  switchbot.startScan({
336
- //model: 's',
319
+ model: 's',
337
320
  id: this.device.bleMac,
338
321
  }).then(() => {
339
322
  // Set an event hander
@@ -377,6 +360,7 @@ export class Motion {
377
360
  }
378
361
  if (this.platform.config.credentials?.openToken) {
379
362
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
363
+ this.SwitchToOpenAPI = true;
380
364
  await this.openAPIRefreshStatus();
381
365
  }
382
366
  this.apiError(e);
@@ -390,6 +374,7 @@ export class Motion {
390
374
  this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
391
375
  if (this.platform.config.credentials?.openToken) {
392
376
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
377
+ this.SwitchToOpenAPI = true;
393
378
  await this.openAPIRefreshStatus();
394
379
  }
395
380
  }
@@ -400,6 +385,11 @@ export class Motion {
400
385
  try {
401
386
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
402
387
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
388
+ if (this.deviceStatus.body.moveDetected === undefined) {
389
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
390
+ }
391
+ this.moveDetected = this.deviceStatus.body.moveDetected;
392
+ this.brightness = this.deviceStatus.body.brightness;
403
393
  this.parseStatus();
404
394
  this.updateHomeKitCharacteristics();
405
395
  } catch (e: any) {
package/src/platform.ts CHANGED
@@ -192,8 +192,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
192
192
  }
193
193
  }
194
194
 
195
+ connectBLE() {
196
+ let Switchbot: new () => any;
197
+ let switchbot: any;
198
+ try {
199
+ Switchbot = require('node-switchbot');
200
+ switchbot = new Switchbot();
201
+ } catch (e) {
202
+ switchbot = false;
203
+ this.errorLog(`Was 'node-switchbot' found: ${switchbot}`);
204
+ }
205
+ return switchbot;
206
+ }
207
+
195
208
  /**
196
- * this method discovers the Locations
209
+ * this method discovers devices
197
210
  */
198
211
  async discoverDevices() {
199
212
  try {