@switchbot/homebridge-switchbot 1.15.1-beta.6 → 1.15.1-beta.8

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 (112) hide show
  1. package/.prettierrc +1 -1
  2. package/dist/device/bot.d.ts +8 -7
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +83 -11
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +8 -7
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +182 -23
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +3 -3
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +50 -7
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +9 -8
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +86 -14
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +8 -7
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +152 -27
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +8 -7
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +84 -12
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +4 -4
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +51 -8
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +3 -3
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +49 -6
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +3 -3
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +49 -9
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +8 -7
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +83 -11
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +8 -7
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +149 -19
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/irdevice/airconditioner.d.ts +5 -4
  47. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  48. package/dist/irdevice/airconditioner.js +40 -6
  49. package/dist/irdevice/airconditioner.js.map +1 -1
  50. package/dist/irdevice/airpurifier.d.ts +5 -4
  51. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  52. package/dist/irdevice/airpurifier.js +40 -6
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/irdevice/camera.d.ts +5 -4
  55. package/dist/irdevice/camera.d.ts.map +1 -1
  56. package/dist/irdevice/camera.js +40 -6
  57. package/dist/irdevice/camera.js.map +1 -1
  58. package/dist/irdevice/fan.d.ts +7 -6
  59. package/dist/irdevice/fan.d.ts.map +1 -1
  60. package/dist/irdevice/fan.js +40 -6
  61. package/dist/irdevice/fan.js.map +1 -1
  62. package/dist/irdevice/light.d.ts +5 -4
  63. package/dist/irdevice/light.d.ts.map +1 -1
  64. package/dist/irdevice/light.js +40 -6
  65. package/dist/irdevice/light.js.map +1 -1
  66. package/dist/irdevice/other.d.ts +5 -4
  67. package/dist/irdevice/other.d.ts.map +1 -1
  68. package/dist/irdevice/other.js +40 -6
  69. package/dist/irdevice/other.js.map +1 -1
  70. package/dist/irdevice/tv.d.ts +7 -6
  71. package/dist/irdevice/tv.d.ts.map +1 -1
  72. package/dist/irdevice/tv.js +40 -6
  73. package/dist/irdevice/tv.js.map +1 -1
  74. package/dist/irdevice/vacuumcleaner.d.ts +5 -4
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +40 -6
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts +5 -4
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +40 -6
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/platform.d.ts +3 -5
  83. package/dist/platform.d.ts.map +1 -1
  84. package/dist/platform.js +142 -92
  85. package/dist/platform.js.map +1 -1
  86. package/dist/settings.d.ts +2 -16
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js +3 -3
  89. package/dist/settings.js.map +1 -1
  90. package/package.json +6 -7
  91. package/src/device/bot.ts +87 -15
  92. package/src/device/colorbulb.ts +186 -41
  93. package/src/device/contact.ts +49 -10
  94. package/src/device/curtain.ts +92 -19
  95. package/src/device/humidifier.ts +164 -30
  96. package/src/device/lock.ts +88 -16
  97. package/src/device/meter.ts +51 -12
  98. package/src/device/meterplus.ts +48 -9
  99. package/src/device/motion.ts +48 -12
  100. package/src/device/plug.ts +87 -15
  101. package/src/device/striplight.ts +161 -24
  102. package/src/irdevice/airconditioner.ts +43 -8
  103. package/src/irdevice/airpurifier.ts +43 -8
  104. package/src/irdevice/camera.ts +43 -8
  105. package/src/irdevice/fan.ts +44 -9
  106. package/src/irdevice/light.ts +43 -8
  107. package/src/irdevice/other.ts +43 -8
  108. package/src/irdevice/tv.ts +44 -9
  109. package/src/irdevice/vacuumcleaner.ts +43 -8
  110. package/src/irdevice/waterheater.ts +43 -8
  111. package/src/platform.ts +155 -105
  112. package/src/settings.ts +6 -10
@@ -1,6 +1,5 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
3
- import { irdevice, device, SwitchBotPlatformConfig, deviceResponses, devicesConfig } from './settings';
2
+ import { irdevice, device, SwitchBotPlatformConfig, devicesConfig } from './settings';
4
3
  /**
5
4
  * HomebridgePlatform
6
5
  * This class is the main constructor for your plugin, this is where you should
@@ -13,9 +12,8 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
13
12
  readonly Service: typeof Service;
14
13
  readonly Characteristic: typeof Characteristic;
15
14
  readonly accessories: PlatformAccessory[];
16
- axios: AxiosInstance;
17
15
  version: any;
18
- deviceStatus: deviceResponses;
16
+ deviceStatus: any;
19
17
  registeringDevice: boolean;
20
18
  debugMode: boolean;
21
19
  platformLogging?: string;
@@ -71,7 +69,7 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
71
69
  connectionTypeNewIRAccessory(accessory: PlatformAccessory): Promise<void>;
72
70
  connectionTypeExistingIRAccessory(existingAccessory: PlatformAccessory): Promise<void>;
73
71
  unregisterPlatformAccessories(existingAccessory: PlatformAccessory): void;
74
- deviceListInfo(devices: deviceResponses): void;
72
+ deviceListInfo(devices: any): void;
75
73
  deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)): Promise<void>;
76
74
  connectBLE(): any;
77
75
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAwBA,OAAc,EAAE,aAAa,EAAsB,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAyC,QAAQ,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9I;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;aAmBjC,GAAG,EAAE,MAAM;aAAkB,MAAM,EAAE,uBAAuB;aAAkB,GAAG,EAAE,GAAG;IAlBlH,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAE/C,KAAK,EAAE,aAAa,CAExB;IAEH,OAAO,MAAkD;IACzD,YAAY,EAAG,eAAe,CAAC;IA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 @@ const airpurifier_1 = require("./irdevice/airpurifier");
24
24
  const waterheater_1 = require("./irdevice/waterheater");
25
25
  const vacuumcleaner_1 = require("./irdevice/vacuumcleaner");
26
26
  const airconditioner_1 = require("./irdevice/airconditioner");
27
+ const https_1 = __importDefault(require("https"));
28
+ const crypto_1 = __importDefault(require("crypto"));
27
29
  const buffer_1 = require("buffer");
28
- const crypto_js_1 = __importDefault(require("crypto-js"));
29
30
  const fakegato_history_1 = __importDefault(require("fakegato-history"));
30
31
  const fs_1 = require("fs");
31
- const axios_1 = __importDefault(require("axios"));
32
32
  const settings_1 = require("./settings");
33
33
  /**
34
34
  * HomebridgePlatform
@@ -44,16 +44,8 @@ class SwitchBotPlatform {
44
44
  this.Characteristic = this.api.hap.Characteristic;
45
45
  // this is used to track restored cached accessories
46
46
  this.accessories = [];
47
- this.axios = axios_1.default.create({
48
- responseType: 'json',
49
- });
50
47
  this.version = require('../package.json').version || '1.12.8'; // eslint-disable-line @typescript-eslint/no-var-requires
51
48
  this.logs();
52
- const t = (new Date().getTime())?.toString();
53
- const nonce = '';
54
- const data = this.config.credentials?.token + t + nonce;
55
- const Hmac_SHA256 = crypto_js_1.default.HmacSHA256(this.config.credentials?.secret, data).toString();
56
- const sign = buffer_1.Buffer.from(Hmac_SHA256, 'binary').toString('base64');
57
49
  this.debugLog('Finished initializing platform:', this.config.name);
58
50
  // only load if configured
59
51
  if (!this.config) {
@@ -75,15 +67,6 @@ class SwitchBotPlatform {
75
67
  }
76
68
  return;
77
69
  }
78
- // setup axios interceptor to add headers / api key to each request
79
- this.axios.interceptors.request.use((request) => {
80
- request.headers.Authorization = this.config.credentials?.token;
81
- request.headers.sign = sign;
82
- request.headers.t = t;
83
- request.headers.nonce = nonce;
84
- request.headers['Content-Type'] = 'application/json; charset=utf8';
85
- return request;
86
- });
87
70
  // import fakegato-history module
88
71
  this.fakegatoAPI = (0, fakegato_history_1.default)(api);
89
72
  // When this event is fired it means Homebridge has restored all cached accessories from disk.
@@ -272,82 +255,120 @@ class SwitchBotPlatform {
272
255
  async discoverDevices() {
273
256
  try {
274
257
  if (this.config.credentials?.token) {
275
- const devicesAPI = (await this.axios.get(settings_1.DeviceURL)).data;
276
- this.deviceListInfo(devicesAPI);
277
- this.debugLog(JSON.stringify(devicesAPI));
278
- // SwitchBot Devices
279
- if (devicesAPI.body.deviceList.length !== 0) {
280
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
281
- }
282
- else {
283
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
284
- }
285
- const deviceLists = devicesAPI.body.deviceList;
286
- if (!this.config.options?.devices) {
287
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
288
- const devices = deviceLists.map((v) => v);
289
- for (const device of devices) {
290
- if (device.deviceType) {
291
- if (device.configDeviceName) {
292
- device.deviceName = device.configDeviceName;
258
+ const t = Date.now();
259
+ const nonce = 'requestID';
260
+ const data = this.config.credentials?.token + t + nonce;
261
+ const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
262
+ const sign = signTerm.toString('base64');
263
+ this.debugLog(sign);
264
+ const options = {
265
+ hostname: settings_1.HostDomain,
266
+ port: 443,
267
+ path: settings_1.DevicePath,
268
+ method: 'GET',
269
+ headers: {
270
+ 'Authorization': this.config.credentials?.token,
271
+ 'sign': sign,
272
+ 'nonce': nonce,
273
+ 't': t,
274
+ 'Content-Type': 'application/json',
275
+ },
276
+ };
277
+ const req = https_1.default.request(options, (res) => {
278
+ this.debugLog(`statusCode: ${res.statusCode}`);
279
+ this.debugLog(`headers: ${JSON.stringify(res.headers)}`);
280
+ let rawData = '';
281
+ res.on('data', (d) => {
282
+ rawData += d;
283
+ this.debugLog(`d: ${d}`);
284
+ });
285
+ res.on('end', () => {
286
+ try {
287
+ const devicesAPI = JSON.parse(rawData);
288
+ this.debugLog(`devicesAPI: ${JSON.stringify(devicesAPI.body)}`);
289
+ // SwitchBot Devices
290
+ if (devicesAPI.body.deviceList.length !== 0) {
291
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
293
292
  }
294
- this.createDevice(device);
295
- }
296
- }
297
- }
298
- else if (this.config.credentials.token && this.config.options.devices) {
299
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
300
- const deviceConfigs = this.config.options?.devices;
301
- const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
302
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
303
- ...itm,
304
- }));
305
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
306
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
307
- for (const device of devices) {
308
- if (device.deviceType) {
309
- if (device.configDeviceName) {
310
- device.deviceName = device.configDeviceName;
293
+ else {
294
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
295
+ }
296
+ const deviceLists = devicesAPI.body.deviceList;
297
+ if (!this.config.options?.devices) {
298
+ this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
299
+ const devices = deviceLists.map((v) => v);
300
+ for (const device of devices) {
301
+ if (device.deviceType) {
302
+ if (device.configDeviceName) {
303
+ device.deviceName = device.configDeviceName;
304
+ }
305
+ this.createDevice(device);
306
+ }
307
+ }
308
+ }
309
+ else if (this.config.credentials?.token && this.config.options.devices) {
310
+ this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
311
+ const deviceConfigs = this.config.options?.devices;
312
+ const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
313
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
314
+ ...itm,
315
+ }));
316
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
317
+ this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
318
+ for (const device of devices) {
319
+ if (device.deviceType) {
320
+ if (device.configDeviceName) {
321
+ device.deviceName = device.configDeviceName;
322
+ }
323
+ this.createDevice(device);
324
+ }
325
+ }
326
+ }
327
+ else {
328
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
329
+ }
330
+ // IR Devices
331
+ if (devicesAPI.body.infraredRemoteList.length !== 0) {
332
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
333
+ }
334
+ else {
335
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
336
+ }
337
+ const irDeviceLists = devicesAPI.body.infraredRemoteList;
338
+ if (!this.config.options?.irdevices) {
339
+ this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
340
+ const devices = irDeviceLists.map((v) => v);
341
+ for (const device of devices) {
342
+ if (device.remoteType) {
343
+ this.createIRDevice(device);
344
+ }
345
+ }
346
+ }
347
+ else {
348
+ this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
349
+ const irDeviceConfig = this.config.options?.irdevices;
350
+ const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
351
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
352
+ ...itm,
353
+ }));
354
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
355
+ this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
356
+ for (const device of devices) {
357
+ if (device.remoteType) {
358
+ this.createIRDevice(device);
359
+ }
360
+ }
311
361
  }
312
- this.createDevice(device);
313
- }
314
- }
315
- }
316
- else {
317
- this.errorLog('Neither SwitchBot Token or Device Config are not set.');
318
- }
319
- // IR Devices
320
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
321
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
322
- }
323
- else {
324
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
325
- }
326
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
327
- if (!this.config.options?.irdevices) {
328
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
329
- const devices = irDeviceLists.map((v) => v);
330
- for (const device of devices) {
331
- if (device.remoteType) {
332
- this.createIRDevice(device);
333
362
  }
334
- }
335
- }
336
- else {
337
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
338
- const irDeviceConfig = this.config.options?.irdevices;
339
- const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
340
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
341
- ...itm,
342
- }));
343
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
344
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
345
- for (const device of devices) {
346
- if (device.remoteType) {
347
- this.createIRDevice(device);
363
+ catch (e) {
364
+ this.errorLog(e.message);
348
365
  }
349
- }
350
- }
366
+ });
367
+ });
368
+ req.on('error', (error) => {
369
+ this.errorLog(error);
370
+ });
371
+ req.end();
351
372
  }
352
373
  else if (!this.config.credentials?.token && this.config.options?.devices) {
353
374
  this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
@@ -1647,7 +1668,36 @@ class SwitchBotPlatform {
1647
1668
  async deviceInfo(device) {
1648
1669
  if (this.platformLogging?.includes('debug')) {
1649
1670
  this.warnLog(JSON.stringify(device));
1650
- this.deviceStatus = (await this.axios.get(`${settings_1.DeviceURL}/${device.deviceId}/status`)).data;
1671
+ const t = Date.now();
1672
+ const nonce = 'requestID';
1673
+ const data = this.config.credentials?.token + t + nonce;
1674
+ const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
1675
+ const sign = signTerm.toString('base64');
1676
+ this.debugLog(sign);
1677
+ const options = {
1678
+ hostname: settings_1.HostDomain,
1679
+ port: 443,
1680
+ path: `${settings_1.DevicePath}/${device.deviceId}/status`,
1681
+ method: 'GET',
1682
+ headers: {
1683
+ Authorization: this.config.credentials?.token,
1684
+ sign: sign,
1685
+ nonce: nonce,
1686
+ t: t,
1687
+ 'Content-Type': 'application/json',
1688
+ },
1689
+ };
1690
+ const req = https_1.default.request(options, (res) => {
1691
+ this.debugLog(`statusCode: ${res.statusCode}`);
1692
+ res.on('data', (d) => {
1693
+ process.stdout.write(d);
1694
+ });
1695
+ });
1696
+ req.on('error', (error) => {
1697
+ this.errorLog(error);
1698
+ });
1699
+ req.end();
1700
+ this.deviceStatus = req;
1651
1701
  if (this.deviceStatus.message === 'success') {
1652
1702
  this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1653
1703
  }