@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.0

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 (143) hide show
  1. package/.vscode/tasks.json +13 -0
  2. package/CHANGELOG.md +4 -2
  3. package/README.md +18 -9
  4. package/dist/device/blindtilt.d.ts +1 -5
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +80 -140
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +1 -5
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +79 -138
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +2 -6
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +157 -304
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +2 -6
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +164 -311
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +1 -5
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +36 -72
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +1 -5
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +78 -138
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/hub.d.ts +2 -6
  29. package/dist/device/hub.d.ts.map +1 -1
  30. package/dist/device/hub.js +30 -63
  31. package/dist/device/hub.js.map +1 -1
  32. package/dist/device/humidifier.d.ts +1 -5
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +115 -228
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -5
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +38 -74
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/{striplight.d.ts → lightstrip.d.ts} +2 -10
  41. package/dist/device/lightstrip.d.ts.map +1 -0
  42. package/dist/device/{striplight.js → lightstrip.js} +138 -194
  43. package/dist/device/lightstrip.js.map +1 -0
  44. package/dist/device/lock.d.ts +1 -5
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +66 -126
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +1 -5
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +38 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +1 -5
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +39 -75
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +1 -5
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +35 -72
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -5
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +65 -126
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -5
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +79 -151
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts +3 -7
  69. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  70. package/dist/irdevice/airconditioner.js +34 -62
  71. package/dist/irdevice/airconditioner.js.map +1 -1
  72. package/dist/irdevice/airpurifier.d.ts +3 -7
  73. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  74. package/dist/irdevice/airpurifier.js +31 -59
  75. package/dist/irdevice/airpurifier.js.map +1 -1
  76. package/dist/irdevice/camera.d.ts +1 -5
  77. package/dist/irdevice/camera.d.ts.map +1 -1
  78. package/dist/irdevice/camera.js +30 -57
  79. package/dist/irdevice/camera.js.map +1 -1
  80. package/dist/irdevice/fan.d.ts +2 -6
  81. package/dist/irdevice/fan.d.ts.map +1 -1
  82. package/dist/irdevice/fan.js +39 -66
  83. package/dist/irdevice/fan.js.map +1 -1
  84. package/dist/irdevice/light.d.ts +1 -5
  85. package/dist/irdevice/light.d.ts.map +1 -1
  86. package/dist/irdevice/light.js +32 -59
  87. package/dist/irdevice/light.js.map +1 -1
  88. package/dist/irdevice/other.d.ts +1 -5
  89. package/dist/irdevice/other.d.ts.map +1 -1
  90. package/dist/irdevice/other.js +30 -57
  91. package/dist/irdevice/other.js.map +1 -1
  92. package/dist/irdevice/tv.d.ts +3 -7
  93. package/dist/irdevice/tv.d.ts.map +1 -1
  94. package/dist/irdevice/tv.js +46 -76
  95. package/dist/irdevice/tv.js.map +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts +2 -6
  97. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  98. package/dist/irdevice/vacuumcleaner.js +30 -58
  99. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  100. package/dist/irdevice/waterheater.d.ts +7 -23
  101. package/dist/irdevice/waterheater.d.ts.map +1 -1
  102. package/dist/irdevice/waterheater.js +41 -74
  103. package/dist/irdevice/waterheater.js.map +1 -1
  104. package/dist/platform.d.ts +14 -5
  105. package/dist/platform.d.ts.map +1 -1
  106. package/dist/platform.js +156 -149
  107. package/dist/platform.js.map +1 -1
  108. package/dist/settings.d.ts +4 -0
  109. package/dist/settings.d.ts.map +1 -1
  110. package/dist/settings.js +5 -1
  111. package/dist/settings.js.map +1 -1
  112. package/nodemon.json +1 -1
  113. package/package.json +10 -10
  114. package/src/device/blindtilt.ts +122 -181
  115. package/src/device/bot.ts +96 -149
  116. package/src/device/ceilinglight.ts +172 -315
  117. package/src/device/colorbulb.ts +178 -324
  118. package/src/device/contact.ts +48 -78
  119. package/src/device/curtain.ts +93 -148
  120. package/src/device/hub.ts +34 -63
  121. package/src/device/humidifier.ts +135 -243
  122. package/src/device/iosensor.ts +49 -79
  123. package/src/device/{striplight.ts → lightstrip.ts} +148 -200
  124. package/src/device/lock.ts +78 -134
  125. package/src/device/meter.ts +48 -78
  126. package/src/device/meterplus.ts +50 -80
  127. package/src/device/motion.ts +46 -77
  128. package/src/device/plug.ts +76 -134
  129. package/src/device/robotvacuumcleaner.ts +91 -159
  130. package/src/irdevice/airconditioner.ts +56 -81
  131. package/src/irdevice/airpurifier.ts +41 -67
  132. package/src/irdevice/camera.ts +35 -60
  133. package/src/irdevice/fan.ts +46 -71
  134. package/src/irdevice/light.ts +38 -63
  135. package/src/irdevice/other.ts +35 -60
  136. package/src/irdevice/tv.ts +52 -80
  137. package/src/irdevice/vacuumcleaner.ts +36 -62
  138. package/src/irdevice/waterheater.ts +46 -76
  139. package/src/platform.ts +144 -158
  140. package/src/settings.ts +5 -0
  141. package/.github/npm-version-script.js +0 -81
  142. package/dist/device/striplight.d.ts.map +0 -1
  143. package/dist/device/striplight.js.map +0 -1
package/dist/platform.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -16,7 +39,7 @@ const iosensor_1 = require("./device/iosensor");
16
39
  const meterplus_1 = require("./device/meterplus");
17
40
  const colorbulb_1 = require("./device/colorbulb");
18
41
  const ceilinglight_1 = require("./device/ceilinglight");
19
- const striplight_1 = require("./device/striplight");
42
+ const lightstrip_1 = require("./device/lightstrip");
20
43
  const humidifier_1 = require("./device/humidifier");
21
44
  const robotvacuumcleaner_1 = require("./device/robotvacuumcleaner");
22
45
  const tv_1 = require("./irdevice/tv");
@@ -29,12 +52,11 @@ const airpurifier_1 = require("./irdevice/airpurifier");
29
52
  const waterheater_1 = require("./irdevice/waterheater");
30
53
  const vacuumcleaner_1 = require("./irdevice/vacuumcleaner");
31
54
  const airconditioner_1 = require("./irdevice/airconditioner");
32
- const https_1 = __importDefault(require("https"));
33
- const crypto_1 = __importDefault(require("crypto"));
55
+ const undici_1 = require("undici");
56
+ const crypto_1 = __importStar(require("crypto"));
34
57
  const buffer_1 = require("buffer");
35
58
  const rxjs_1 = require("rxjs");
36
59
  const fakegato_history_1 = __importDefault(require("fakegato-history"));
37
- const super_stringify_1 = __importDefault(require("super-stringify"));
38
60
  const fs_1 = require("fs");
39
61
  const settings_1 = require("./settings");
40
62
  /**
@@ -52,6 +74,20 @@ class SwitchBotPlatform {
52
74
  // this is used to track restored cached accessories
53
75
  this.accessories = [];
54
76
  this.version = process.env.npm_package_version || '2.1.1';
77
+ this.generateHeaders = () => {
78
+ const t = `${Date.now()}`;
79
+ const nonce = (0, crypto_1.randomUUID)();
80
+ const data = this.config.credentials?.token + t + nonce;
81
+ const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
82
+ const sign = signTerm.toString('base64');
83
+ return {
84
+ 'Authorization': this.config.credentials?.token,
85
+ 'sign': sign,
86
+ 'nonce': nonce,
87
+ 't': t,
88
+ 'Content-Type': 'application/json',
89
+ };
90
+ };
55
91
  this.logs();
56
92
  this.debugLog('Finished initializing platform:', this.config.name);
57
93
  // only load if configured
@@ -125,7 +161,7 @@ class SwitchBotPlatform {
125
161
  platformConfig['pushRate'] = this.config.options.pushRate;
126
162
  }
127
163
  if (Object.entries(platformConfig).length !== 0) {
128
- this.infoLog(`Platform Config: ${(0, super_stringify_1.default)(platformConfig)}`);
164
+ this.infoLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
129
165
  }
130
166
  if (this.config.options) {
131
167
  // Device Config
@@ -237,144 +273,115 @@ class SwitchBotPlatform {
237
273
  }
238
274
  /**
239
275
  * this method discovers devices
276
+ *
277
+ const t = `${Date.now()}`;
278
+ const nonce = 'requestID';
279
+ const data = this.config.credentials?.token + t + nonce;
280
+ const signTerm = crypto.createHmac('sha256', this.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
281
+ const sign = signTerm.toString('base64');
240
282
  */
241
283
  async discoverDevices() {
242
- try {
243
- if (this.config.credentials?.token) {
244
- const t = Date.now();
245
- const nonce = 'requestID';
246
- const data = this.config.credentials?.token + t + nonce;
247
- const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
248
- const sign = signTerm.toString('base64');
249
- this.debugLog(`sing: ${sign}`);
250
- const options = {
251
- hostname: settings_1.HostDomain,
252
- port: 443,
253
- path: settings_1.DevicePath,
254
- method: 'GET',
255
- headers: {
256
- 'Authorization': this.config.credentials?.token,
257
- 'sign': sign,
258
- 'nonce': nonce,
259
- 't': t,
260
- 'Content-Type': 'application/json',
261
- },
262
- };
263
- const req = https_1.default.request(options, async (res) => {
264
- this.debugLog(`statusCode: ${res.statusCode}`);
265
- await this.statusCode({ res });
266
- this.debugLog(`headers: ${(0, super_stringify_1.default)(res.headers)}`);
267
- let rawData = '';
268
- res.on('data', (d) => {
269
- rawData += d;
270
- this.debugLog(`d: ${d}`);
271
- });
272
- res.on('end', () => {
273
- try {
274
- const devicesAPI = JSON.parse(rawData);
275
- this.debugLog(`devicesAPI: ${(0, super_stringify_1.default)(devicesAPI.body)}`);
276
- // SwitchBot Devices
277
- const deviceLists = devicesAPI.body.deviceList;
278
- if (!this.config.options?.devices) {
279
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
280
- const devices = deviceLists.map((v) => v);
281
- for (const device of devices) {
282
- if (device.deviceType) {
283
- if (device.configDeviceName) {
284
- device.deviceName = device.configDeviceName;
285
- }
286
- this.createDevice(device);
287
- }
288
- }
289
- }
290
- else if (this.config.credentials?.token && this.config.options.devices) {
291
- this.debugLog(`SwitchBot Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
292
- const deviceConfigs = this.config.options?.devices;
293
- const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
294
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
295
- ...itm,
296
- }));
297
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
298
- this.debugLog(`SwitchBot Devices: ${(0, super_stringify_1.default)(devices)}`);
299
- for (const device of devices) {
300
- if (device.deviceType) {
301
- if (device.configDeviceName) {
302
- device.deviceName = device.configDeviceName;
303
- }
304
- this.createDevice(device);
305
- }
306
- }
307
- }
308
- else {
309
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
310
- }
311
- if (devicesAPI.body.deviceList.length !== 0) {
312
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
313
- }
314
- else {
315
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
316
- }
317
- // IR Devices
318
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
319
- if (!this.config.options?.irdevices) {
320
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
321
- const devices = irDeviceLists.map((v) => v);
322
- for (const device of devices) {
323
- if (device.remoteType) {
324
- this.createIRDevice(device);
325
- }
326
- }
327
- }
328
- else {
329
- this.debugLog(`IR Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
330
- const irDeviceConfig = this.config.options?.irdevices;
331
- const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
332
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
333
- ...itm,
334
- }));
335
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
336
- this.debugLog(`IR Devices: ${(0, super_stringify_1.default)(devices)}`);
337
- for (const device of devices) {
338
- this.createIRDevice(device);
339
- }
340
- }
341
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
342
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
284
+ if (this.config.credentials?.token) {
285
+ try {
286
+ const { body, statusCode, headers } = await (0, undici_1.request)(settings_1.Devices, {
287
+ headers: this.generateHeaders(),
288
+ });
289
+ const devicesAPI = await body.json();
290
+ this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
291
+ this.statusCode(statusCode);
292
+ this.debugLog(`Headers: ${JSON.stringify(headers)}`);
293
+ // SwitchBot Devices
294
+ const deviceLists = devicesAPI.body.deviceList;
295
+ if (!this.config.options?.devices) {
296
+ this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
297
+ const devices = deviceLists.map((v) => v);
298
+ for (const device of devices) {
299
+ if (device.deviceType) {
300
+ if (device.configDeviceName) {
301
+ device.deviceName = device.configDeviceName;
343
302
  }
344
- else {
345
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
303
+ this.createDevice(device);
304
+ }
305
+ }
306
+ }
307
+ else if (this.config.credentials?.token && this.config.options.devices) {
308
+ this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
309
+ const deviceConfigs = this.config.options?.devices;
310
+ const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
311
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
312
+ ...itm,
313
+ }));
314
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
315
+ this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
316
+ for (const device of devices) {
317
+ if (device.deviceType) {
318
+ if (device.configDeviceName) {
319
+ device.deviceName = device.configDeviceName;
346
320
  }
321
+ this.createDevice(device);
347
322
  }
348
- catch (e) {
349
- this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
323
+ }
324
+ }
325
+ else {
326
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
327
+ }
328
+ if (devicesAPI.body.deviceList.length !== 0) {
329
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
330
+ }
331
+ else {
332
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
333
+ }
334
+ // IR Devices
335
+ const irDeviceLists = devicesAPI.body.infraredRemoteList;
336
+ if (!this.config.options?.irdevices) {
337
+ this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
338
+ const devices = irDeviceLists.map((v) => v);
339
+ for (const device of devices) {
340
+ if (device.remoteType) {
341
+ this.createIRDevice(device);
350
342
  }
351
- });
352
- });
353
- req.on('error', (e) => {
354
- this.errorLog(`req: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
355
- });
356
- req.end();
357
- }
358
- else if (!this.config.credentials?.token && this.config.options?.devices) {
359
- this.debugLog(`SwitchBot Device Manual Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
360
- const deviceConfigs = this.config.options?.devices;
361
- const devices = deviceConfigs.map((v) => v);
362
- for (const device of devices) {
363
- device.deviceType = device.configDeviceType;
364
- device.deviceName = device.configDeviceName;
365
- if (device.deviceType) {
366
- this.createDevice(device);
367
343
  }
368
344
  }
345
+ else {
346
+ this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
347
+ const irDeviceConfig = this.config.options?.irdevices;
348
+ const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
349
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
350
+ ...itm,
351
+ }));
352
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
353
+ this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
354
+ for (const device of devices) {
355
+ this.createIRDevice(device);
356
+ }
357
+ }
358
+ if (devicesAPI.body.infraredRemoteList.length !== 0) {
359
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
360
+ }
361
+ else {
362
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
363
+ }
369
364
  }
370
- else {
371
- this.errorLog('Neither SwitchBot Token or Device Config are not set.');
365
+ catch (e) {
366
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: `
367
+ + 'https://tinyurl.com/SwitchBotBug');
368
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
369
+ }
370
+ }
371
+ else if (!this.config.credentials?.token && this.config.options?.devices) {
372
+ this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
373
+ const deviceConfigs = this.config.options?.devices;
374
+ const devices = deviceConfigs.map((v) => v);
375
+ for (const device of devices) {
376
+ device.deviceType = device.configDeviceType;
377
+ device.deviceName = device.configDeviceName;
378
+ if (device.deviceType) {
379
+ this.createDevice(device);
380
+ }
372
381
  }
373
382
  }
374
- catch (e) {
375
- this.debugErrorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}, Submit Bugs Here: `
376
- + 'https://tinyurl.com/SwitchBotBug');
377
- this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
383
+ else {
384
+ this.errorLog('Neither SwitchBot Token or Device Config are not set.');
378
385
  }
379
386
  }
380
387
  createDevice(device) {
@@ -532,7 +539,7 @@ class SwitchBotPlatform {
532
539
  this.createOthers(device);
533
540
  break;
534
541
  default:
535
- this.debugLog(`Unsupported Device: ${(0, super_stringify_1.default)(device)}`);
542
+ this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
536
543
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
537
544
  this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
538
545
  }
@@ -1325,7 +1332,7 @@ class SwitchBotPlatform {
1325
1332
  this.api.updatePlatformAccessories([existingAccessory]);
1326
1333
  // create the accessory handler for the restored accessory
1327
1334
  // this is imported from `platformAccessory.ts`
1328
- new striplight_1.StripLight(this, existingAccessory, device);
1335
+ new lightstrip_1.StripLight(this, existingAccessory, device);
1329
1336
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1330
1337
  }
1331
1338
  else {
@@ -1349,7 +1356,7 @@ class SwitchBotPlatform {
1349
1356
  accessory.context.connectionType = await this.connectionType(device);
1350
1357
  // create the accessory handler for the newly create accessory
1351
1358
  // this is imported from `platformAccessory.ts`
1352
- new striplight_1.StripLight(this, accessory, device);
1359
+ new lightstrip_1.StripLight(this, accessory, device);
1353
1360
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1354
1361
  // publish device externally or link the accessory to your platform
1355
1362
  this.externalOrPlatform(device, accessory);
@@ -2034,35 +2041,35 @@ class SwitchBotPlatform {
2034
2041
  this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [existingAccessory]);
2035
2042
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
2036
2043
  }
2037
- async statusCode({ res }) {
2038
- switch (res.statusCode) {
2044
+ async statusCode(statusCode) {
2045
+ switch (statusCode) {
2039
2046
  case 151:
2040
- this.errorLog('Command not supported by this device type, Submit Feature Request Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
2047
+ this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: `
2048
+ + 'https://tinyurl.com/SwitchBotFeatureRequest');
2041
2049
  break;
2042
2050
  case 152:
2043
- this.errorLog('Device not found.');
2051
+ this.errorLog(`Device not found, statusCode: ${statusCode}`);
2044
2052
  break;
2045
2053
  case 160:
2046
- this.errorLog('Command is not supported, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug');
2054
+ this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2047
2055
  break;
2048
2056
  case 161:
2049
- this.errorLog('Device is offline.');
2057
+ this.errorLog(`Device is offline, statusCode: ${statusCode}`);
2050
2058
  break;
2051
2059
  case 171:
2052
- this.errorLog('is offline');
2060
+ this.errorLog(`is offline, statusCode: ${statusCode}`);
2053
2061
  break;
2054
2062
  case 190:
2055
- this.errorLog('Requests reached the daily limit');
2063
+ this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2056
2064
  break;
2057
2065
  case 100:
2058
- if (this.debugMode) {
2059
- this.debugLog('Command successfully sent.');
2060
- }
2066
+ this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2067
+ break;
2068
+ case 200:
2069
+ this.debugLog(`Request successful, statusCode: ${statusCode}`);
2061
2070
  break;
2062
2071
  default:
2063
- if (this.debugMode) {
2064
- this.debugLog('Unknown statusCode, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug');
2065
- }
2072
+ this.infoLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2066
2073
  }
2067
2074
  }
2068
2075
  // BLE Connection