@switchbot/homebridge-switchbot 1.2.1-beta.2 → 1.2.1-beta.6

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 (92) hide show
  1. package/config.schema.json +3 -3
  2. package/dist/devices/bots.d.ts +2 -2
  3. package/dist/devices/bots.d.ts.map +1 -1
  4. package/dist/devices/bots.js +15 -9
  5. package/dist/devices/bots.js.map +1 -1
  6. package/dist/devices/colorbulb.d.ts +2 -2
  7. package/dist/devices/colorbulb.d.ts.map +1 -1
  8. package/dist/devices/colorbulb.js +1 -0
  9. package/dist/devices/colorbulb.js.map +1 -1
  10. package/dist/devices/contact.d.ts +2 -2
  11. package/dist/devices/contact.d.ts.map +1 -1
  12. package/dist/devices/contact.js +7 -6
  13. package/dist/devices/contact.js.map +1 -1
  14. package/dist/devices/curtains.d.ts +2 -2
  15. package/dist/devices/curtains.d.ts.map +1 -1
  16. package/dist/devices/curtains.js +16 -14
  17. package/dist/devices/curtains.js.map +1 -1
  18. package/dist/devices/humidifiers.d.ts +2 -2
  19. package/dist/devices/humidifiers.d.ts.map +1 -1
  20. package/dist/devices/humidifiers.js +9 -7
  21. package/dist/devices/humidifiers.js.map +1 -1
  22. package/dist/devices/indoorcam.d.ts +2 -2
  23. package/dist/devices/indoorcam.d.ts.map +1 -1
  24. package/dist/devices/indoorcam.js.map +1 -1
  25. package/dist/devices/meters.d.ts +2 -2
  26. package/dist/devices/meters.d.ts.map +1 -1
  27. package/dist/devices/meters.js +7 -6
  28. package/dist/devices/meters.js.map +1 -1
  29. package/dist/devices/motion.d.ts +2 -2
  30. package/dist/devices/motion.d.ts.map +1 -1
  31. package/dist/devices/motion.js +7 -6
  32. package/dist/devices/motion.js.map +1 -1
  33. package/dist/devices/plugs.d.ts +2 -2
  34. package/dist/devices/plugs.d.ts.map +1 -1
  35. package/dist/devices/plugs.js.map +1 -1
  36. package/dist/irdevices/airconditioners.d.ts +1 -1
  37. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  38. package/dist/irdevices/airconditioners.js +2 -2
  39. package/dist/irdevices/airconditioners.js.map +1 -1
  40. package/dist/irdevices/airpurifiers.d.ts +1 -1
  41. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  42. package/dist/irdevices/airpurifiers.js +2 -2
  43. package/dist/irdevices/airpurifiers.js.map +1 -1
  44. package/dist/irdevices/cameras.d.ts +1 -1
  45. package/dist/irdevices/cameras.d.ts.map +1 -1
  46. package/dist/irdevices/cameras.js +2 -2
  47. package/dist/irdevices/cameras.js.map +1 -1
  48. package/dist/irdevices/fans.d.ts +1 -1
  49. package/dist/irdevices/fans.d.ts.map +1 -1
  50. package/dist/irdevices/fans.js +2 -2
  51. package/dist/irdevices/fans.js.map +1 -1
  52. package/dist/irdevices/lights.d.ts +1 -1
  53. package/dist/irdevices/lights.d.ts.map +1 -1
  54. package/dist/irdevices/lights.js +2 -2
  55. package/dist/irdevices/lights.js.map +1 -1
  56. package/dist/irdevices/others.d.ts +1 -1
  57. package/dist/irdevices/others.d.ts.map +1 -1
  58. package/dist/irdevices/others.js +2 -2
  59. package/dist/irdevices/others.js.map +1 -1
  60. package/dist/irdevices/tvs.d.ts +1 -1
  61. package/dist/irdevices/tvs.d.ts.map +1 -1
  62. package/dist/irdevices/vacuumcleaners.d.ts +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  64. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  65. package/dist/irdevices/waterheaters.d.ts +1 -1
  66. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  67. package/dist/irdevices/waterheaters.js +2 -2
  68. package/dist/irdevices/waterheaters.js.map +1 -1
  69. package/dist/platform.d.ts +1 -1
  70. package/dist/platform.d.ts.map +1 -1
  71. package/dist/platform.js +31 -27
  72. package/dist/platform.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/devices/bots.ts +14 -11
  75. package/src/devices/colorbulb.ts +4 -3
  76. package/src/devices/contact.ts +5 -7
  77. package/src/devices/curtains.ts +16 -16
  78. package/src/devices/humidifiers.ts +8 -9
  79. package/src/devices/indoorcam.ts +3 -3
  80. package/src/devices/meters.ts +5 -7
  81. package/src/devices/motion.ts +5 -7
  82. package/src/devices/plugs.ts +4 -3
  83. package/src/irdevices/airconditioners.ts +3 -3
  84. package/src/irdevices/airpurifiers.ts +3 -3
  85. package/src/irdevices/cameras.ts +3 -3
  86. package/src/irdevices/fans.ts +3 -3
  87. package/src/irdevices/lights.ts +3 -3
  88. package/src/irdevices/others.ts +3 -3
  89. package/src/irdevices/tvs.ts +1 -1
  90. package/src/irdevices/vacuumcleaners.ts +1 -1
  91. package/src/irdevices/waterheaters.ts +3 -3
  92. package/src/platform.ts +33 -37
@@ -1,9 +1,11 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+
2
+ import { AxiosResponse } from 'axios';
3
+ import Switchbot from 'node-switchbot';
3
4
  import { interval, Subject } from 'rxjs';
5
+ import { SwitchBotPlatform } from '../platform';
4
6
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
7
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
8
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
9
 
8
10
  /**
9
11
  * Platform Accessory
@@ -171,10 +173,11 @@ export class Bot {
171
173
  this.platform.debug(`Bot: ${this.accessory.displayName} BLE parseStatus`);
172
174
  // BLEmode (true if Switch Mode) | (false if Press Mode)
173
175
  if (this.mode) {
174
- this.platform.device(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}`);
176
+ this.On = Boolean(this.state);
177
+ this.platform.device(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
178
+ } else {
179
+ this.platform.device(`Bot: ${this.accessory.displayName} Press Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`);
175
180
  }
176
- this.On = Boolean(this.state);
177
- this.platform.log.error(`Bot: ${this.accessory.displayName} On: ${JSON.stringify(this.On)}`);
178
181
 
179
182
  this.BatteryLevel = Number(this.battery);
180
183
  if (this.BatteryLevel < 10) {
@@ -210,12 +213,8 @@ export class Bot {
210
213
  }
211
214
 
212
215
  private connectBLE() {
213
- // eslint-disable-next-line @typescript-eslint/no-var-requires
214
- const Switchbot = require('node-switchbot');
215
216
  const switchbot = new Switchbot();
216
- const colon = this.device.deviceId!.match(/.{1,2}/g);
217
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
218
- this.device.bleMac = bleMac.toLowerCase();
217
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
219
218
  this.platform.device(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
220
219
  return switchbot;
221
220
  }
@@ -260,6 +259,7 @@ export class Bot {
260
259
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
261
260
  await this.openAPIRefreshStatus();
262
261
  }
262
+ this.apiError(e);
263
263
  });
264
264
  }
265
265
 
@@ -334,6 +334,7 @@ export class Bot {
334
334
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
335
335
  await this.openAPIpushChanges();
336
336
  }
337
+ this.apiError(e);
337
338
  });
338
339
  } else if (this.device.bot?.mode === 'switch') {
339
340
  this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
@@ -356,6 +357,7 @@ export class Bot {
356
357
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
357
358
  await this.openAPIpushChanges();
358
359
  }
360
+ this.apiError(e);
359
361
  });
360
362
  } else {
361
363
  this.platform.log.error(`Bot: ${this.accessory.displayName} Mode Not Set, mode: ${this.device.bot?.mode}`);
@@ -412,6 +414,7 @@ export class Bot {
412
414
  this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
413
415
  + ` Error: ${JSON.stringify(e)}`);
414
416
  }
417
+ this.apiError(e);
415
418
  }
416
419
  }
417
420
  }
@@ -1,9 +1,9 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import { AxiosResponse } from 'axios';
3
2
  import { interval, Subject } from 'rxjs';
3
+ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
6
  import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
7
 
8
8
  /**
9
9
  * Platform Accessory
@@ -344,6 +344,7 @@ export class ColorBulb {
344
344
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
345
345
  + ` Error: ${JSON.stringify(e)}`);
346
346
  }
347
+ this.apiError(e);
347
348
  }
348
349
  }
349
350
 
@@ -1,7 +1,8 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import Switchbot from 'node-switchbot';
3
2
  import { interval, Subject } from 'rxjs';
4
3
  import { skipWhile } from 'rxjs/operators';
4
+ import { SwitchBotPlatform } from '../platform';
5
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
6
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
6
7
 
7
8
  /**
@@ -222,12 +223,8 @@ export class Contact {
222
223
  }
223
224
 
224
225
  private connectBLE() {
225
- // eslint-disable-next-line @typescript-eslint/no-var-requires
226
- const Switchbot = require('node-switchbot');
227
226
  const switchbot = new Switchbot();
228
- const colon = this.device.deviceId!.match(/.{1,2}/g);
229
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
230
- this.device.bleMac = bleMac.toLowerCase();
227
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
231
228
  this.platform.device(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
232
229
  return switchbot;
233
230
  }
@@ -273,6 +270,7 @@ export class Contact {
273
270
  this.platform.log.warn(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
274
271
  await this.openAPIRefreshStatus();
275
272
  }
273
+ this.apiError(e);
276
274
  });
277
275
  }
278
276
 
@@ -1,9 +1,11 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+
2
+ import { AxiosResponse } from 'axios';
3
+ import Switchbot from 'node-switchbot';
3
4
  import { interval, Subject } from 'rxjs';
5
+ import { SwitchBotPlatform } from '../platform';
4
6
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
7
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
8
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
9
 
8
10
  export class Curtain {
9
11
  // Services
@@ -188,12 +190,8 @@ export class Curtain {
188
190
  }
189
191
 
190
192
  private connectBLE() {
191
- // eslint-disable-next-line @typescript-eslint/no-var-requires
192
- const Switchbot = require('node-switchbot');
193
193
  const switchbot = new Switchbot();
194
- const colon = this.device.deviceId!.match(/.{1,2}/g);
195
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
196
- this.device.bleMac = bleMac.toLowerCase();
194
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
197
195
  this.platform.device(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
198
196
  return switchbot;
199
197
  }
@@ -249,13 +247,13 @@ export class Curtain {
249
247
  this.platform.debug(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
250
248
  this.setMinMax();
251
249
  this.CurrentPosition = 100 - Number(this.position);
252
- this.setMinMax();
253
250
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
254
251
  if (this.setNewTarget) {
255
252
  this.platform.log.info(`Curtain: ${this.accessory.displayName} Checking Status ...`);
256
253
  }
257
254
 
258
255
  if (this.setNewTarget) {
256
+ this.setMinMax();
259
257
  if (this.TargetPosition > this.CurrentPosition) {
260
258
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
261
259
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -345,13 +343,13 @@ export class Curtain {
345
343
  // CurrentPosition
346
344
  this.setMinMax();
347
345
  this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
348
- this.setMinMax();
349
346
  this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
350
347
  if (this.setNewTarget) {
351
348
  this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
352
349
  }
353
350
 
354
351
  if (this.deviceStatus.body.moving) {
352
+ this.setMinMax();
355
353
  if (this.TargetPosition > this.CurrentPosition) {
356
354
  this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
357
355
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
@@ -421,7 +419,6 @@ export class Curtain {
421
419
  }).then(() => {
422
420
  // Stop to monitor
423
421
  switchbot.stopScan();
424
- this.setMinMax();
425
422
  this.parseStatus();
426
423
  this.updateHomeKitCharacteristics();
427
424
  }).catch(async (e: any) => {
@@ -437,8 +434,8 @@ export class Curtain {
437
434
  if (this.platform.config.credentials?.openToken) {
438
435
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
439
436
  await this.openAPIRefreshStatus();
440
- this.apiError(e);
441
437
  }
438
+ this.apiError(e);
442
439
  });
443
440
  }
444
441
 
@@ -448,7 +445,6 @@ export class Curtain {
448
445
  try {
449
446
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
450
447
  this.platform.debug(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
- this.setMinMax();
452
448
  this.parseStatus();
453
449
  this.updateHomeKitCharacteristics();
454
450
  } catch (e: any) {
@@ -497,6 +493,7 @@ export class Curtain {
497
493
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
498
494
  await this.OpenAPIpushChanges();
499
495
  }
496
+ this.apiError(e);
500
497
  });
501
498
  }
502
499
 
@@ -531,6 +528,7 @@ export class Curtain {
531
528
  this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
532
529
  + ` Error: ${JSON.stringify(e)}`);
533
530
  }
531
+ this.apiError(e);
534
532
  }
535
533
  }
536
534
  }
@@ -629,20 +627,22 @@ export class Curtain {
629
627
 
630
628
  this.TargetPosition = value;
631
629
 
630
+ this.setMinMax();
632
631
  if (value > this.CurrentPosition) {
633
632
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
634
633
  this.setNewTarget = true;
635
- this.setMinMax();
634
+ this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
636
635
  } else if (value < this.CurrentPosition) {
637
636
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
638
637
  this.setNewTarget = true;
639
- this.setMinMax();
638
+ this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
640
639
  } else {
641
640
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
642
641
  this.setNewTarget = false;
643
- this.setMinMax();
642
+ this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
644
643
  }
645
644
  this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
645
+ this.service.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
646
646
 
647
647
  /**
648
648
  * If Curtain movement time is short, the moving flag from backend is always false.
@@ -1,9 +1,10 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import { AxiosResponse } from 'axios';
2
+ import Switchbot from 'node-switchbot';
3
3
  import { interval, Subject } from 'rxjs';
4
+ import { SwitchBotPlatform } from '../platform';
4
5
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
6
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
7
  import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
8
 
8
9
  /**
9
10
  * Platform Accessory
@@ -290,12 +291,8 @@ export class Humidifier {
290
291
  }
291
292
 
292
293
  private connectBLE() {
293
- // eslint-disable-next-line @typescript-eslint/no-var-requires
294
- const Switchbot = require('node-switchbot');
295
294
  const switchbot = new Switchbot();
296
- const colon = this.device.deviceId!.match(/.{1,2}/g);
297
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
298
- this.device.bleMac = bleMac.toLowerCase();
295
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
299
296
  this.platform.device(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
300
297
  return switchbot;
301
298
  }
@@ -340,6 +337,7 @@ export class Humidifier {
340
337
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
341
338
  await this.openAPIRefreshStatus();
342
339
  }
340
+ this.apiError(e);
343
341
  });
344
342
  }
345
343
 
@@ -387,7 +385,7 @@ export class Humidifier {
387
385
  const switchbot = this.connectBLE();
388
386
  switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
389
387
  this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.Active}`);
390
- return device_list[0].runToPos(100 - Number(this.Active));
388
+ return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
391
389
  }).then(() => {
392
390
  this.platform.device(`Humidifier: ${this.accessory.displayName} Done.`);
393
391
  }).catch(async (e: any) => {
@@ -404,6 +402,7 @@ export class Humidifier {
404
402
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
405
403
  await this.OpenAPIpushChanges();
406
404
  }
405
+ this.apiError(e);
407
406
  });
408
407
  }
409
408
 
@@ -1,9 +1,9 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import { AxiosResponse } from 'axios';
3
2
  import { interval, Subject } from 'rxjs';
3
+ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
6
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
7
 
8
8
  export class IndoorCam {
9
9
  // Services
@@ -1,7 +1,8 @@
1
- import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import Switchbot from 'node-switchbot';
3
2
  import { interval, Subject } from 'rxjs';
4
3
  import { skipWhile } from 'rxjs/operators';
4
+ import { SwitchBotPlatform } from '../platform';
5
+ import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
5
6
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse } from '../settings';
6
7
 
7
8
  /**
@@ -239,12 +240,8 @@ export class Meter {
239
240
  }
240
241
 
241
242
  private connectBLE() {
242
- // eslint-disable-next-line @typescript-eslint/no-var-requires
243
- const Switchbot = require('node-switchbot');
244
243
  const switchbot = new Switchbot();
245
- const colon = this.device.deviceId!.match(/.{1,2}/g);
246
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
247
- this.device.bleMac = bleMac.toLowerCase();
244
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
248
245
  this.platform.device(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
249
246
  return switchbot;
250
247
  }
@@ -291,6 +288,7 @@ export class Meter {
291
288
  this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
292
289
  await this.openAPIRefreshStatus();
293
290
  }
291
+ this.apiError(e);
294
292
  });
295
293
  }
296
294
 
@@ -1,7 +1,8 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+ import Switchbot from 'node-switchbot';
3
2
  import { interval, Subject } from 'rxjs';
4
3
  import { skipWhile } from 'rxjs/operators';
4
+ import { SwitchBotPlatform } from '../platform';
5
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
6
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
6
7
 
7
8
  /**
@@ -160,12 +161,8 @@ export class Motion {
160
161
  }
161
162
 
162
163
  private connectBLE() {
163
- // eslint-disable-next-line @typescript-eslint/no-var-requires
164
- const Switchbot = require('node-switchbot');
165
164
  const switchbot = new Switchbot();
166
- const colon = this.device.deviceId!.match(/.{1,2}/g);
167
- const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
168
- this.device.bleMac = bleMac.toLowerCase();
165
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
169
166
  this.platform.device(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
170
167
  return switchbot;
171
168
  }
@@ -210,6 +207,7 @@ export class Motion {
210
207
  this.platform.log.warn(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
211
208
  await this.openAPIRefreshStatus();
212
209
  }
210
+ this.apiError(e);
213
211
  });
214
212
  }
215
213
 
@@ -1,9 +1,10 @@
1
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
- import { SwitchBotPlatform } from '../platform';
1
+
2
+ import { AxiosResponse } from 'axios';
3
3
  import { interval, Subject } from 'rxjs';
4
+ import { SwitchBotPlatform } from '../platform';
4
5
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
6
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
7
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
6
- import { AxiosResponse } from 'axios';
7
8
 
8
9
  export class Plug {
9
10
  // Services
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -373,8 +373,8 @@ export class AirConditioner {
373
373
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} Hub Device is offline.`);
374
374
  break;
375
375
  case 190:
376
- this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
377
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
376
+ this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
377
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
378
378
  break;
379
379
  case 100:
380
380
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -242,8 +242,8 @@ export class AirPurifier {
242
242
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} Hub Device is offline.`);
243
243
  break;
244
244
  case 190:
245
- this.platform.log.error(`Air Purifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
246
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
245
+ this.platform.log.error(`Air Purifier: ${this.accessory.displayName} Device internal error due to device states not synchronized`
246
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
247
247
  break;
248
248
  case 100:
249
249
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -142,8 +142,8 @@ export class Camera {
142
142
  this.platform.log.error(`Camera: ${this.accessory.displayName} Hub Device is offline.`);
143
143
  break;
144
144
  case 190:
145
- this.platform.log.error(`Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
146
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
145
+ this.platform.log.error(`Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized`
146
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
147
147
  break;
148
148
  case 100:
149
149
  this.platform.debug(`Camera: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
3
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
4
  import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
5
5
 
6
6
  /**
@@ -264,8 +264,8 @@ export class Fan {
264
264
  this.platform.log.error(`Fan: ${this.accessory.displayName} Hub Device is offline.`);
265
265
  break;
266
266
  case 190:
267
- this.platform.log.error(`Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
268
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
267
+ this.platform.log.error(`Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized`
268
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
269
269
  break;
270
270
  case 100:
271
271
  this.platform.debug(`Fan: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -176,8 +176,8 @@ export class Light {
176
176
  this.platform.log.error(`Light: ${this.accessory.displayName} Hub Device is offline.`);
177
177
  break;
178
178
  case 190:
179
- this.platform.log.error(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
180
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
179
+ this.platform.log.error(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized`
180
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
181
181
  break;
182
182
  case 100:
183
183
  this.platform.debug(`Light: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -163,8 +163,8 @@ export class Others {
163
163
  this.platform.log.error(`Other: ${this.accessory.displayName} Hub Device is offline.`);
164
164
  break;
165
165
  case 190:
166
- this.platform.log.error(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
167
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
166
+ this.platform.log.error(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized`
167
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
168
168
  break;
169
169
  case 100:
170
170
  this.platform.debug(`Other: ${this.accessory.displayName} Command successfully sent.`);
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
3
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
4
  import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
5
5
 
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
2
  import { SwitchBotPlatform } from '../platform';
4
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -156,8 +156,8 @@ export class WaterHeater {
156
156
  this.platform.log.error(`Water Heater: ${this.accessory.displayName} Hub Device is offline.`);
157
157
  break;
158
158
  case 190:
159
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
160
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
159
+ this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
160
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
161
161
  break;
162
162
  case 100:
163
163
  this.platform.debug(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);