@switchbot/homebridge-switchbot 1.15.1-beta.7 → 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 +141 -95
  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 +154 -108
  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"));
27
28
  const crypto_1 = __importDefault(require("crypto"));
28
29
  const buffer_1 = require("buffer");
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,20 +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 token = this.config.credentials?.token;
53
- const secret = this.config.credentials?.secret;
54
- const t = Date.now().toString();
55
- const nonce = '';
56
- const data = token + t + nonce;
57
- const signTerm = crypto_1.default.createHmac('sha256', secret)
58
- .update(buffer_1.Buffer.from(data, 'utf-8'))
59
- .digest();
60
- const sign = buffer_1.Buffer.from(String(signTerm), 'binary').toString('base64');
61
49
  this.debugLog('Finished initializing platform:', this.config.name);
62
50
  // only load if configured
63
51
  if (!this.config) {
@@ -79,15 +67,6 @@ class SwitchBotPlatform {
79
67
  }
80
68
  return;
81
69
  }
82
- // setup axios interceptor to add headers / api key to each request
83
- this.axios.interceptors.request.use((request) => {
84
- request.headers.Authorization = token;
85
- request.headers.sign = sign;
86
- request.headers.t = t;
87
- request.headers.nonce = nonce;
88
- request.headers['Content-Type'] = 'application/json; charset=utf8';
89
- return request;
90
- });
91
70
  // import fakegato-history module
92
71
  this.fakegatoAPI = (0, fakegato_history_1.default)(api);
93
72
  // When this event is fired it means Homebridge has restored all cached accessories from disk.
@@ -276,82 +255,120 @@ class SwitchBotPlatform {
276
255
  async discoverDevices() {
277
256
  try {
278
257
  if (this.config.credentials?.token) {
279
- const devicesAPI = (await this.axios.get(settings_1.DeviceURL)).data;
280
- this.deviceListInfo(devicesAPI);
281
- this.debugLog(JSON.stringify(devicesAPI));
282
- // SwitchBot Devices
283
- if (devicesAPI.body.deviceList.length !== 0) {
284
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
285
- }
286
- else {
287
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
288
- }
289
- const deviceLists = devicesAPI.body.deviceList;
290
- if (!this.config.options?.devices) {
291
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
292
- const devices = deviceLists.map((v) => v);
293
- for (const device of devices) {
294
- if (device.deviceType) {
295
- if (device.configDeviceName) {
296
- 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}`);
297
292
  }
298
- this.createDevice(device);
299
- }
300
- }
301
- }
302
- else if (this.config.credentials.token && this.config.options.devices) {
303
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
304
- const deviceConfigs = this.config.options?.devices;
305
- const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
306
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
307
- ...itm,
308
- }));
309
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
310
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
311
- for (const device of devices) {
312
- if (device.deviceType) {
313
- if (device.configDeviceName) {
314
- 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
+ }
315
361
  }
316
- this.createDevice(device);
317
- }
318
- }
319
- }
320
- else {
321
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
322
- }
323
- // IR Devices
324
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
325
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
326
- }
327
- else {
328
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
329
- }
330
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
331
- if (!this.config.options?.irdevices) {
332
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
333
- const devices = irDeviceLists.map((v) => v);
334
- for (const device of devices) {
335
- if (device.remoteType) {
336
- this.createIRDevice(device);
337
362
  }
338
- }
339
- }
340
- else {
341
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
342
- const irDeviceConfig = this.config.options?.irdevices;
343
- const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
344
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
345
- ...itm,
346
- }));
347
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
348
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
349
- for (const device of devices) {
350
- if (device.remoteType) {
351
- this.createIRDevice(device);
363
+ catch (e) {
364
+ this.errorLog(e.message);
352
365
  }
353
- }
354
- }
366
+ });
367
+ });
368
+ req.on('error', (error) => {
369
+ this.errorLog(error);
370
+ });
371
+ req.end();
355
372
  }
356
373
  else if (!this.config.credentials?.token && this.config.options?.devices) {
357
374
  this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
@@ -1651,7 +1668,36 @@ class SwitchBotPlatform {
1651
1668
  async deviceInfo(device) {
1652
1669
  if (this.platformLogging?.includes('debug')) {
1653
1670
  this.warnLog(JSON.stringify(device));
1654
- 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;
1655
1701
  if (this.deviceStatus.message === 'success') {
1656
1702
  this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1657
1703
  }