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

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.
package/CHANGELOG.md CHANGED
@@ -14,6 +14,8 @@ All notable changes to this project will be documented in this file. This projec
14
14
  - `OpenAPI` will only allow connections through the OpenAPI.
15
15
  - `BLE` will only allow connections through Bluetooth (BLE), .
16
16
  - `Disable` will disable all connections. This will also allow you to disable commands and refreshes for a specific device but leave it in HomeKit.
17
+ - Added `discoverDevices` config which allows you to enable device rediscover periodically.
18
+ - Added `discoverDevicesInterval` config which allows you to set the Interval for the `discoverDevices` config.
17
19
  - Housekeeping and updated dependencies.
18
20
 
19
21
  **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.15.0...v2.0.0
@@ -892,6 +892,31 @@
892
892
  "placeholder": 1,
893
893
  "description": "Indicates the number of seconds between pushes to SwitchBot API."
894
894
  },
895
+ "discoverDevices": {
896
+ "title": "Rediscover Devices Periodically",
897
+ "type": "boolean"
898
+ },
899
+ "discoverDevicesInterval": {
900
+ "title": "Rediscover Devices Interval",
901
+ "type": "number",
902
+ "oneOf": [
903
+ {
904
+ "title": "1 Day",
905
+ "enum": [86400]
906
+ },
907
+ {
908
+ "title": "7 Days",
909
+ "enum": [604800]
910
+ },
911
+ {
912
+ "title": "30 Days",
913
+ "enum": [2592000]
914
+ }
915
+ ],
916
+ "condition": {
917
+ "functionBody": "return (model.options && model.options.discoverDevices);"
918
+ }
919
+ },
895
920
  "logging": {
896
921
  "title": "Logging Setting",
897
922
  "type": "string",
@@ -1040,6 +1065,8 @@
1040
1065
  "key": "options.pushRate",
1041
1066
  "notitle": true
1042
1067
  },
1068
+ "options.discoverDevices",
1069
+ "options.discoverDevicesInterval",
1043
1070
  "options.logging"
1044
1071
  ]
1045
1072
  }
@@ -1,5 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
2
- import { irdevice, device, SwitchBotPlatformConfig, devicesConfig } from './settings';
3
+ import { device, SwitchBotPlatformConfig, devicesConfig } from './settings';
4
+ import { IncomingMessage } from 'http';
3
5
  /**
4
6
  * HomebridgePlatform
5
7
  * This class is the main constructor for your plugin, this is where you should
@@ -69,7 +71,9 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
69
71
  externalAccessory(accessory: PlatformAccessory): Promise<void>;
70
72
  unregisterPlatformAccessories(existingAccessory: PlatformAccessory): void;
71
73
  deviceListInfo(devices: any): void;
72
- deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)): Promise<void>;
74
+ statusCode({ res }: {
75
+ res: IncomingMessage;
76
+ }): Promise<void>;
73
77
  connectBLE(): any;
74
78
  /**
75
79
  * If device level logging is turned on, log to log.warn
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EAA8B,QAAQ,EAAE,MAAM,EAAE,uBAAuB,EAAE,aAAa,EAA0B,MAAM,YAAY,CAAC;AAE1I;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;aAejC,GAAG,EAAE,MAAM;aAAkB,MAAM,EAAE,uBAAuB;aAAkB,GAAG,EAAE,GAAG;IAdlH,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAEtD,OAAO,MAAkD;IACzD,YAAY,EAAG,GAAG,CAAC;IACnB,iBAAiB,EAAG,OAAO,CAAC;IAC5B,SAAS,EAAG,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,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AAO,CAAC,YAAY;IAmEpB,OAAO,CAAC,cAAc;YA+DR,gBAAgB;YAsDhB,SAAS;YA2DT,WAAW;YAsDX,eAAe;YAsDf,YAAY;YAsDZ,aAAa;YAsDb,aAAa;IAiE3B,OAAO,CAAC,gBAAgB;YAeV,UAAU;YAsDV,UAAU;YAsDV,eAAe;YAsDf,gBAAgB;YAsDhB,QAAQ;YAqDR,SAAS;YAsDT,WAAW;YAsDX,oBAAoB;YAsDpB,iBAAiB;YAsDjB,iBAAiB;YAsDjB,mBAAmB;YAsDnB,YAAY;YAsDZ,YAAY;IAsDpB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAU5D,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IA4BtC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,SAAS,EAAE,iBAAiB;IAU/E,iBAAiB,CAAC,SAAS,EAAE,iBAAiB;IAIpD,6BAA6B,CAAC,iBAAiB,EAAE,iBAAiB;IAMlE,cAAc,CAAC,OAAO,KAAA;IAMvB,UAAU,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiClE,UAAU;IAaV;;;OAGG;IACH,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAU7B,uBAAuB,IAAI,OAAO;CAGnC"}
package/dist/platform.js CHANGED
@@ -31,6 +31,7 @@ const fakegato_history_1 = __importDefault(require("fakegato-history"));
31
31
  const super_stringify_1 = __importDefault(require("super-stringify"));
32
32
  const fs_1 = require("fs");
33
33
  const settings_1 = require("./settings");
34
+ const rxjs_1 = require("rxjs");
34
35
  /**
35
36
  * HomebridgePlatform
36
37
  * This class is the main constructor for your plugin, this is where you should
@@ -64,7 +65,7 @@ class SwitchBotPlatform {
64
65
  catch (e) {
65
66
  this.errorLog((0, super_stringify_1.default)(e.message));
66
67
  if (this.platformLogging?.includes('debug')) {
67
- this.errorLog((0, super_stringify_1.default)(e));
68
+ this.errorLog(`Verify Config: ${e}`);
68
69
  }
69
70
  return;
70
71
  }
@@ -92,7 +93,7 @@ class SwitchBotPlatform {
92
93
  catch (e) {
93
94
  this.errorLog('Failed to Discover Devices.', (0, super_stringify_1.default)(e.message));
94
95
  if (this.platformLogging?.includes('debug')) {
95
- this.errorLog((0, super_stringify_1.default)(e));
96
+ this.errorLog(`Platform: ${e}`);
96
97
  }
97
98
  }
98
99
  });
@@ -209,6 +210,15 @@ class SwitchBotPlatform {
209
210
  }
210
211
  }
211
212
  }
213
+ // Re-Discover Devices
214
+ if (!this.config.options.discoverDevices) {
215
+ this.config.options.discoverDevices = false;
216
+ this.debugLog(`Rediscover Devices disabled, discoverDevices: ${this.config.options.discoverDevices}`);
217
+ }
218
+ if (!this.config.options.discoverDevicesInterval) {
219
+ this.config.options.discoverDevicesInterval = 86400;
220
+ this.debugLog(`Default Rediscover Devices Interval, discoverDevicesInterval: ${this.config.options.discoverDevicesInterval}`);
221
+ }
212
222
  }
213
223
  /**
214
224
  * The openToken was old config.
@@ -258,7 +268,7 @@ class SwitchBotPlatform {
258
268
  this.verifyConfig();
259
269
  }
260
270
  catch (e) {
261
- this.errorLog(e);
271
+ this.errorLog(`Update Token: ${e}`);
262
272
  }
263
273
  }
264
274
  /**
@@ -286,8 +296,9 @@ class SwitchBotPlatform {
286
296
  'Content-Type': 'application/json',
287
297
  },
288
298
  };
289
- const req = https_1.default.request(options, (res) => {
299
+ const req = https_1.default.request(options, async (res) => {
290
300
  this.debugLog(`statusCode: ${res.statusCode}`);
301
+ await this.statusCode({ res });
291
302
  this.debugLog(`headers: ${(0, super_stringify_1.default)(res.headers)}`);
292
303
  let rawData = '';
293
304
  res.on('data', (d) => {
@@ -299,86 +310,106 @@ class SwitchBotPlatform {
299
310
  const devicesAPI = JSON.parse(rawData);
300
311
  this.debugLog(`devicesAPI: ${(0, super_stringify_1.default)(devicesAPI.body)}`);
301
312
  // SwitchBot Devices
302
- if (devicesAPI.body.deviceList.length !== 0) {
303
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
304
- }
305
- else {
306
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
307
- }
308
- const deviceLists = devicesAPI.body.deviceList;
309
- if (!this.config.options?.devices) {
310
- this.debugLog(`SwitchBot Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
311
- const devices = deviceLists.map((v) => v);
312
- for (const device of devices) {
313
- if (device.deviceType) {
314
- if (device.configDeviceName) {
315
- device.deviceName = device.configDeviceName;
313
+ /*if (devicesAPI.body.deviceList.length !== 0) {
314
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
315
+ } else {
316
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
317
+ }*/
318
+ const deviceBodyList = devicesAPI.body.deviceList;
319
+ let deviceLists;
320
+ if (deviceBodyList) {
321
+ if (deviceBodyList.length > 1) {
322
+ deviceLists = deviceBodyList;
323
+ this.infoLog(`Total SwitchBot Devices Found: ${deviceLists.length}`);
324
+ }
325
+ else {
326
+ deviceLists = [deviceBodyList];
327
+ this.infoLog(`Total SwitchBot Devices Found: ${deviceLists.length}`);
328
+ }
329
+ if (!this.config.options?.devices) {
330
+ this.debugLog(`SwitchBot Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
331
+ const devices = deviceLists.map((v) => v);
332
+ for (const device of devices) {
333
+ if (device.deviceType) {
334
+ if (device.configDeviceName) {
335
+ device.deviceName = device.configDeviceName;
336
+ }
337
+ this.createDevice(device);
316
338
  }
317
- this.createDevice(device);
318
339
  }
319
340
  }
320
- }
321
- else if (this.config.credentials?.token && this.config.options.devices) {
322
- this.debugLog(`SwitchBot Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
323
- const deviceConfigs = this.config.options?.devices;
324
- const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
325
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
326
- ...itm,
327
- }));
328
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
329
- this.debugLog(`SwitchBot Devices: ${(0, super_stringify_1.default)(devices)}`);
330
- for (const device of devices) {
331
- if (device.deviceType) {
332
- if (device.configDeviceName) {
333
- device.deviceName = device.configDeviceName;
341
+ else if (this.config.credentials?.token && this.config.options.devices) {
342
+ this.debugLog(`SwitchBot Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
343
+ const deviceConfigs = this.config.options?.devices;
344
+ const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
345
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
346
+ ...itm,
347
+ }));
348
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
349
+ this.debugLog(`SwitchBot Devices: ${(0, super_stringify_1.default)(devices)}`);
350
+ for (const device of devices) {
351
+ if (device.deviceType) {
352
+ if (device.configDeviceName) {
353
+ device.deviceName = device.configDeviceName;
354
+ }
355
+ this.createDevice(device);
334
356
  }
335
- this.createDevice(device);
336
357
  }
337
358
  }
338
- }
339
- else {
340
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
359
+ else {
360
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
361
+ }
341
362
  }
342
363
  // IR Devices
343
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
344
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
345
- }
346
- else {
347
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
348
- }
349
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
350
- if (!this.config.options?.irdevices) {
351
- this.debugLog(`IR Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
352
- const devices = irDeviceLists.map((v) => v);
353
- for (const device of devices) {
354
- if (device.remoteType) {
355
- this.createIRDevice(device);
364
+ /*if (devicesAPI.body.infraredRemoteList.length !== 0) {
365
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
366
+ } else {
367
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
368
+ }*/
369
+ const irDeviceBodyList = devicesAPI.body.infraredRemoteList;
370
+ let irDeviceLists;
371
+ if (irDeviceBodyList) {
372
+ if (irDeviceBodyList.length > 1) {
373
+ irDeviceLists = irDeviceBodyList;
374
+ this.infoLog(`Total IR Devices Found: ${irDeviceLists.length}`);
375
+ }
376
+ else {
377
+ irDeviceLists = [irDeviceBodyList];
378
+ this.infoLog(`Total IR Devices Found: ${irDeviceLists.length}`);
379
+ }
380
+ if (!this.config.options?.irdevices) {
381
+ this.debugLog(`IR Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
382
+ const devices = irDeviceLists.map((v) => v);
383
+ for (const device of devices) {
384
+ if (device.remoteType) {
385
+ this.createIRDevice(device);
386
+ }
356
387
  }
357
388
  }
358
- }
359
- else {
360
- this.debugLog(`IR Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
361
- const irDeviceConfig = this.config.options?.irdevices;
362
- const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
363
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
364
- ...itm,
365
- }));
366
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
367
- this.debugLog(`IR Devices: ${(0, super_stringify_1.default)(devices)}`);
368
- for (const device of devices) {
369
- if (device.remoteType) {
370
- this.createIRDevice(device);
389
+ else {
390
+ this.debugLog(`IR Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
391
+ const irDeviceConfig = this.config.options?.irdevices;
392
+ const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
393
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
394
+ ...itm,
395
+ }));
396
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
397
+ this.debugLog(`IR Devices: ${(0, super_stringify_1.default)(devices)}`);
398
+ for (const device of devices) {
399
+ if (device.remoteType) {
400
+ this.createIRDevice(device);
401
+ }
371
402
  }
372
403
  }
373
404
  }
374
405
  }
375
406
  catch (e) {
376
- this.errorLog(e.message);
407
+ this.errorLog(`API Request: ${e}`);
377
408
  }
378
409
  });
379
410
  });
380
- req.on('error', (error) => {
381
- this.errorLog(error);
411
+ req.on('error', (e) => {
412
+ this.errorLog(`req: ${e}`);
382
413
  });
383
414
  req.end();
384
415
  }
@@ -399,7 +430,14 @@ class SwitchBotPlatform {
399
430
  }
400
431
  }
401
432
  catch (e) {
402
- this.deviceError(e);
433
+ this.deviceError(`Discover Devices: ${e}`);
434
+ }
435
+ if (this.config.options?.discoverDevices) {
436
+ (0, rxjs_1.interval)(this.config.options.discoverDevicesInterval * 1000)
437
+ .pipe((0, rxjs_1.take)(1))
438
+ .subscribe(async () => {
439
+ await this.discoverDevices();
440
+ });
403
441
  }
404
442
  }
405
443
  deviceError(e) {
@@ -447,7 +485,7 @@ class SwitchBotPlatform {
447
485
  this.errorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
448
486
  }
449
487
  if (this.platformLogging === 'debugMode') {
450
- this.errorLog(`Failed to Discover Devices, Error: ${(0, super_stringify_1.default)(e)}`);
488
+ this.errorLog(`Failed to Discover Devices, Error: ${e}`);
451
489
  }
452
490
  }
453
491
  createDevice(device) {
@@ -505,7 +543,6 @@ class SwitchBotPlatform {
505
543
  this.createStripLight(device);
506
544
  break;
507
545
  case 'Indoor Cam':
508
- this.deviceInfo(device);
509
546
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
510
547
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
511
548
  break;
@@ -513,7 +550,6 @@ class SwitchBotPlatform {
513
550
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
514
551
  break;
515
552
  default:
516
- this.deviceInfo(device);
517
553
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
518
554
  this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
519
555
  }
@@ -575,7 +611,7 @@ class SwitchBotPlatform {
575
611
  this.createOthers(device);
576
612
  break;
577
613
  default:
578
- this.deviceInfo(device);
614
+ this.debugLog(`Unsupported Device: ${(0, super_stringify_1.default)(device)}`);
579
615
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
580
616
  this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
581
617
  }
@@ -1691,46 +1727,35 @@ class SwitchBotPlatform {
1691
1727
  this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
1692
1728
  }
1693
1729
  }
1694
- async deviceInfo(device) {
1695
- if (this.platformLogging?.includes('debug')) {
1696
- this.warnLog((0, super_stringify_1.default)(device));
1697
- const t = Date.now();
1698
- const nonce = 'requestID';
1699
- const data = this.config.credentials?.token + t + nonce;
1700
- const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
1701
- const sign = signTerm.toString('base64');
1702
- this.debugLog(sign);
1703
- const options = {
1704
- hostname: settings_1.HostDomain,
1705
- port: 443,
1706
- path: `${settings_1.DevicePath}/${device.deviceId}/status`,
1707
- method: 'GET',
1708
- headers: {
1709
- Authorization: this.config.credentials?.token,
1710
- sign: sign,
1711
- nonce: nonce,
1712
- t: t,
1713
- 'Content-Type': 'application/json',
1714
- },
1715
- };
1716
- const req = https_1.default.request(options, (res) => {
1717
- this.debugLog(`statusCode: ${res.statusCode}`);
1718
- res.on('data', (d) => {
1719
- process.stdout.write(d);
1720
- });
1721
- });
1722
- req.on('error', (error) => {
1723
- this.errorLog(error);
1724
- });
1725
- req.end();
1726
- this.deviceStatus = req;
1727
- if (this.deviceStatus.message === 'success') {
1728
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
1729
- }
1730
- else {
1731
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus.message)}`);
1732
- this.warnLog('Unable to retreive deviceInfoStatus.');
1733
- }
1730
+ async statusCode({ res }) {
1731
+ switch (res.statusCode) {
1732
+ case 151:
1733
+ this.errorLog('Command not supported by this device type.');
1734
+ break;
1735
+ case 152:
1736
+ this.errorLog('Device not found.');
1737
+ break;
1738
+ case 160:
1739
+ this.errorLog('Command is not supported.');
1740
+ break;
1741
+ case 161:
1742
+ this.errorLog('Device is offline.');
1743
+ break;
1744
+ case 171:
1745
+ this.errorLog('is offline');
1746
+ break;
1747
+ case 190:
1748
+ this.errorLog('Requests reached the daily limit');
1749
+ break;
1750
+ case 100:
1751
+ if (this.debugMode) {
1752
+ this.debugLog('Command successfully sent.');
1753
+ }
1754
+ break;
1755
+ default:
1756
+ if (this.debugMode) {
1757
+ this.debugLog('Unknown statusCode.');
1758
+ }
1734
1759
  }
1735
1760
  }
1736
1761
  // BLE Connection