@switchbot/homebridge-switchbot 2.8.0-beta.17 → 2.8.0-beta.19

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 (57) hide show
  1. package/dist/device/blindtilt.js.map +1 -1
  2. package/dist/device/bot.d.ts.map +1 -1
  3. package/dist/device/bot.js +15 -10
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/ceilinglight.js.map +1 -1
  6. package/dist/device/colorbulb.js.map +1 -1
  7. package/dist/device/contact.js.map +1 -1
  8. package/dist/device/curtain.js.map +1 -1
  9. package/dist/device/hub.js.map +1 -1
  10. package/dist/device/humidifier.js.map +1 -1
  11. package/dist/device/iosensor.js.map +1 -1
  12. package/dist/device/lightstrip.js.map +1 -1
  13. package/dist/device/lock.js.map +1 -1
  14. package/dist/device/meter.js.map +1 -1
  15. package/dist/device/meterplus.js.map +1 -1
  16. package/dist/device/motion.js.map +1 -1
  17. package/dist/device/plug.js.map +1 -1
  18. package/dist/device/robotvacuumcleaner.js.map +1 -1
  19. package/dist/irdevice/airconditioner.js.map +1 -1
  20. package/dist/irdevice/airpurifier.js.map +1 -1
  21. package/dist/irdevice/camera.js.map +1 -1
  22. package/dist/irdevice/fan.js.map +1 -1
  23. package/dist/irdevice/light.js.map +1 -1
  24. package/dist/irdevice/other.js.map +1 -1
  25. package/dist/irdevice/tv.js.map +1 -1
  26. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  27. package/dist/irdevice/waterheater.js.map +1 -1
  28. package/dist/platform.d.ts.map +1 -1
  29. package/dist/platform.js +64 -60
  30. package/dist/platform.js.map +1 -1
  31. package/package.json +11 -11
  32. package/src/device/blindtilt.ts +2 -2
  33. package/src/device/bot.ts +15 -11
  34. package/src/device/ceilinglight.ts +5 -5
  35. package/src/device/colorbulb.ts +5 -5
  36. package/src/device/contact.ts +1 -1
  37. package/src/device/curtain.ts +2 -2
  38. package/src/device/hub.ts +1 -1
  39. package/src/device/humidifier.ts +4 -4
  40. package/src/device/iosensor.ts +1 -1
  41. package/src/device/lightstrip.ts +4 -4
  42. package/src/device/lock.ts +2 -2
  43. package/src/device/meter.ts +1 -1
  44. package/src/device/meterplus.ts +1 -1
  45. package/src/device/motion.ts +1 -1
  46. package/src/device/plug.ts +2 -2
  47. package/src/device/robotvacuumcleaner.ts +3 -3
  48. package/src/irdevice/airconditioner.ts +1 -1
  49. package/src/irdevice/airpurifier.ts +1 -1
  50. package/src/irdevice/camera.ts +1 -1
  51. package/src/irdevice/fan.ts +1 -1
  52. package/src/irdevice/light.ts +1 -1
  53. package/src/irdevice/other.ts +1 -1
  54. package/src/irdevice/tv.ts +1 -1
  55. package/src/irdevice/vacuumcleaner.ts +1 -1
  56. package/src/irdevice/waterheater.ts +1 -1
  57. package/src/platform.ts +73 -70
@@ -400,7 +400,7 @@ export class Contact {
400
400
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
401
401
  headers: this.platform.generateHeaders(),
402
402
  });
403
- const deviceStatus = await body.json();
403
+ const deviceStatus: any = await body.json();
404
404
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
405
405
  this.statusCode(statusCode);
406
406
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -559,7 +559,7 @@ export class Curtain {
559
559
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
560
560
  headers: this.platform.generateHeaders(),
561
561
  });
562
- const deviceStatus = await body.json();
562
+ const deviceStatus: any = await body.json();
563
563
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
564
564
  this.statusCode(statusCode);
565
565
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -705,7 +705,7 @@ export class Curtain {
705
705
  method: 'POST',
706
706
  headers: this.platform.generateHeaders(),
707
707
  });
708
- const deviceStatus = await body.json();
708
+ const deviceStatus: any = await body.json();
709
709
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
710
710
  this.statusCode(statusCode);
711
711
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
package/src/device/hub.ts CHANGED
@@ -294,7 +294,7 @@ export class Hub {
294
294
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
295
295
  headers: this.platform.generateHeaders(),
296
296
  });
297
- const deviceStatus = await body.json();
297
+ const deviceStatus: any = await body.json();
298
298
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
299
299
  this.statusCode(statusCode);
300
300
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -379,7 +379,7 @@ export class Humidifier {
379
379
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
380
380
  headers: this.platform.generateHeaders(),
381
381
  });
382
- const deviceStatus = await body.json();
382
+ const deviceStatus: any = await body.json();
383
383
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
384
384
  this.statusCode(statusCode);
385
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -475,7 +475,7 @@ export class Humidifier {
475
475
  method: 'POST',
476
476
  headers: this.platform.generateHeaders(),
477
477
  });
478
- const deviceStatus = await body.json();
478
+ const deviceStatus: any = await body.json();
479
479
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
480
480
  this.statusCode(statusCode);
481
481
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -518,7 +518,7 @@ export class Humidifier {
518
518
  method: 'POST',
519
519
  headers: this.platform.generateHeaders(),
520
520
  });
521
- const deviceStatus = await body.json();
521
+ const deviceStatus: any = await body.json();
522
522
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
523
523
  this.statusCode(statusCode);
524
524
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -556,7 +556,7 @@ export class Humidifier {
556
556
  method: 'POST',
557
557
  headers: this.platform.generateHeaders(),
558
558
  });
559
- const deviceStatus = await body.json();
559
+ const deviceStatus: any = await body.json();
560
560
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
561
561
  this.statusCode(statusCode);
562
562
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -338,7 +338,7 @@ export class IOSensor {
338
338
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
339
339
  headers: this.platform.generateHeaders(),
340
340
  });
341
- const deviceStatus = await body.json();
341
+ const deviceStatus: any = await body.json();
342
342
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
343
343
  this.statusCode(statusCode);
344
344
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -381,7 +381,7 @@ export class StripLight {
381
381
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
382
382
  headers: this.platform.generateHeaders(),
383
383
  });
384
- const deviceStatus = await body.json();
384
+ const deviceStatus: any = await body.json();
385
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
386
386
  this.statusCode(statusCode);
387
387
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -594,7 +594,7 @@ export class StripLight {
594
594
  method: 'POST',
595
595
  headers: this.platform.generateHeaders(),
596
596
  });
597
- const deviceStatus = await body.json();
597
+ const deviceStatus: any = await body.json();
598
598
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
599
599
  this.statusCode(statusCode);
600
600
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -642,7 +642,7 @@ export class StripLight {
642
642
  method: 'POST',
643
643
  headers: this.platform.generateHeaders(),
644
644
  });
645
- const deviceStatus = await body.json();
645
+ const deviceStatus: any = await body.json();
646
646
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
647
647
  this.statusCode(statusCode);
648
648
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -676,7 +676,7 @@ export class StripLight {
676
676
  method: 'POST',
677
677
  headers: this.platform.generateHeaders(),
678
678
  });
679
- const deviceStatus = await body.json();
679
+ const deviceStatus: any = await body.json();
680
680
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
681
681
  this.statusCode(statusCode);
682
682
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -312,7 +312,7 @@ export class Lock {
312
312
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
313
313
  headers: this.platform.generateHeaders(),
314
314
  });
315
- const deviceStatus = await body.json();
315
+ const deviceStatus: any = await body.json();
316
316
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
317
317
  this.statusCode(statusCode);
318
318
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -421,7 +421,7 @@ export class Lock {
421
421
  method: 'POST',
422
422
  headers: this.platform.generateHeaders(),
423
423
  });
424
- const deviceStatus = await body.json();
424
+ const deviceStatus: any = await body.json();
425
425
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
426
426
  this.statusCode(statusCode);
427
427
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -344,7 +344,7 @@ export class Meter {
344
344
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
345
345
  headers: this.platform.generateHeaders(),
346
346
  });
347
- const deviceStatus = await body.json();
347
+ const deviceStatus: any = await body.json();
348
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
349
349
  this.statusCode(statusCode);
350
350
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -344,7 +344,7 @@ export class MeterPlus {
344
344
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
345
345
  headers: this.platform.generateHeaders(),
346
346
  });
347
- const deviceStatus = await body.json();
347
+ const deviceStatus: any = await body.json();
348
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
349
349
  this.statusCode(statusCode);
350
350
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -357,7 +357,7 @@ export class Motion {
357
357
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
358
358
  headers: this.platform.generateHeaders(),
359
359
  });
360
- const deviceStatus = await body.json();
360
+ const deviceStatus: any = await body.json();
361
361
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
362
362
  this.statusCode(statusCode);
363
363
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -265,7 +265,7 @@ export class Plug {
265
265
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
266
266
  headers: this.platform.generateHeaders(),
267
267
  });
268
- const deviceStatus = await body.json();
268
+ const deviceStatus: any = await body.json();
269
269
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
270
270
  this.statusCode(statusCode);
271
271
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -383,7 +383,7 @@ export class Plug {
383
383
  method: 'POST',
384
384
  headers: this.platform.generateHeaders(),
385
385
  });
386
- const deviceStatus = await body.json();
386
+ const deviceStatus: any = await body.json();
387
387
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
388
388
  this.statusCode(statusCode);
389
389
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -303,7 +303,7 @@ export class RobotVacuumCleaner {
303
303
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
304
304
  headers: this.platform.generateHeaders(),
305
305
  });
306
- const deviceStatus = await body.json();
306
+ const deviceStatus: any = await body.json();
307
307
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
308
308
  this.statusCode(statusCode);
309
309
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -422,7 +422,7 @@ export class RobotVacuumCleaner {
422
422
  method: 'POST',
423
423
  headers: this.platform.generateHeaders(),
424
424
  });
425
- const deviceStatus = await body.json();
425
+ const deviceStatus: any = await body.json();
426
426
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
427
427
  this.statusCode(statusCode);
428
428
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -451,7 +451,7 @@ export class RobotVacuumCleaner {
451
451
  method: 'POST',
452
452
  headers: this.platform.generateHeaders(),
453
453
  });
454
- const deviceStatus = await body.json();
454
+ const deviceStatus: any = await body.json();
455
455
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
456
456
  this.statusCode(statusCode);
457
457
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -262,7 +262,7 @@ export class AirConditioner {
262
262
  method: 'POST',
263
263
  headers: this.platform.generateHeaders(),
264
264
  });
265
- const deviceStatus = await body.json();
265
+ const deviceStatus: any = await body.json();
266
266
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
267
267
  this.statusCode(statusCode);
268
268
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -218,7 +218,7 @@ export class AirPurifier {
218
218
  method: 'POST',
219
219
  headers: this.platform.generateHeaders(),
220
220
  });
221
- const deviceStatus = await body.json();
221
+ const deviceStatus: any = await body.json();
222
222
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
223
223
  this.statusCode(statusCode);
224
224
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -123,7 +123,7 @@ export class Camera {
123
123
  method: 'POST',
124
124
  headers: this.platform.generateHeaders(),
125
125
  });
126
- const deviceStatus = await body.json();
126
+ const deviceStatus: any = await body.json();
127
127
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
128
128
  this.statusCode(statusCode);
129
129
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -243,7 +243,7 @@ export class Fan {
243
243
  method: 'POST',
244
244
  headers: this.platform.generateHeaders(),
245
245
  });
246
- const deviceStatus = await body.json();
246
+ const deviceStatus: any = await body.json();
247
247
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
248
248
  this.statusCode(statusCode);
249
249
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -147,7 +147,7 @@ export class Light {
147
147
  method: 'POST',
148
148
  headers: this.platform.generateHeaders(),
149
149
  });
150
- const deviceStatus = await body.json();
150
+ const deviceStatus: any = await body.json();
151
151
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
152
152
  this.statusCode(statusCode);
153
153
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -142,7 +142,7 @@ export class Others {
142
142
  method: 'POST',
143
143
  headers: this.platform.generateHeaders(),
144
144
  });
145
- const deviceStatus = await body.json();
145
+ const deviceStatus: any = await body.json();
146
146
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
147
147
  this.statusCode(statusCode);
148
148
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -375,7 +375,7 @@ export class TV {
375
375
  method: 'POST',
376
376
  headers: this.platform.generateHeaders(),
377
377
  });
378
- const deviceStatus = await body.json();
378
+ const deviceStatus: any = await body.json();
379
379
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
380
380
  this.statusCode(statusCode);
381
381
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -119,7 +119,7 @@ export class VacuumCleaner {
119
119
  method: 'POST',
120
120
  headers: this.platform.generateHeaders(),
121
121
  });
122
- const deviceStatus = await body.json();
122
+ const deviceStatus: any = await body.json();
123
123
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
124
124
  this.statusCode(statusCode);
125
125
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
@@ -128,7 +128,7 @@ export class WaterHeater {
128
128
  method: 'POST',
129
129
  headers: this.platform.generateHeaders(),
130
130
  });
131
- const deviceStatus = await body.json();
131
+ const deviceStatus: any = await body.json();
132
132
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
133
133
  this.statusCode(statusCode);
134
134
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
package/src/platform.ts CHANGED
@@ -300,18 +300,42 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
300
300
  const { body, statusCode, headers } = await request(Devices, {
301
301
  headers: this.generateHeaders(),
302
302
  });
303
- const devicesAPI = await body.json();
304
- this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
305
- this.statusCode(statusCode);
306
- this.debugLog(`Headers: ${JSON.stringify(headers)}`);
307
- // SwitchBot Devices
308
- const deviceLists = devicesAPI.body.deviceList;
309
- if (!this.config.options?.devices) {
310
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
311
- if (deviceLists.length === 0) {
312
- this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
313
- } else {
314
- const devices = deviceLists.map((v: any) => v);
303
+ if (statusCode === 200) {
304
+ const devicesAPI: any = await body.json();
305
+ this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
306
+ this.debugLog(`Headers: ${JSON.stringify(headers)}`);
307
+ // SwitchBot Devices
308
+ const deviceLists = devicesAPI.body.deviceList;
309
+ if (!this.config.options?.devices) {
310
+ this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
311
+ if (deviceLists.length === 0) {
312
+ this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
313
+ } else {
314
+ const devices = deviceLists.map((v: any) => v);
315
+ for (const device of devices) {
316
+ if (device.deviceType) {
317
+ if (device.configDeviceName) {
318
+ device.deviceName = device.configDeviceName;
319
+ }
320
+ this.createDevice(device);
321
+ }
322
+ }
323
+ }
324
+ } else if (this.config.credentials?.token && this.config.options.devices) {
325
+ this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
326
+ const deviceConfigs = this.config.options?.devices;
327
+
328
+ const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
329
+ a1.map((itm: { deviceId: string }) => ({
330
+ ...a2.find(
331
+ (item: { deviceId: string }) =>
332
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
333
+ ),
334
+ ...itm,
335
+ }));
336
+
337
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
338
+ this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
315
339
  for (const device of devices) {
316
340
  if (device.deviceType) {
317
341
  if (device.configDeviceName) {
@@ -320,72 +344,51 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
320
344
  this.createDevice(device);
321
345
  }
322
346
  }
347
+ } else {
348
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
323
349
  }
324
- } else if (this.config.credentials?.token && this.config.options.devices) {
325
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
326
- const deviceConfigs = this.config.options?.devices;
327
-
328
- const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
329
- a1.map((itm: { deviceId: string }) => ({
330
- ...a2.find(
331
- (item: { deviceId: string }) =>
332
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
333
- ),
334
- ...itm,
335
- }));
336
-
337
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
338
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
339
- for (const device of devices) {
340
- if (device.deviceType) {
341
- if (device.configDeviceName) {
342
- device.deviceName = device.configDeviceName;
343
- }
344
- this.createDevice(device);
345
- }
350
+ if (devicesAPI.body.deviceList.length !== 0) {
351
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
352
+ } else {
353
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
346
354
  }
347
- } else {
348
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
349
- }
350
- if (devicesAPI.body.deviceList.length !== 0) {
351
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
352
- } else {
353
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
354
- }
355
355
 
356
- // IR Devices
357
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
358
- if (!this.config.options?.irdevices) {
359
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
360
- const devices = irDeviceLists.map((v: any) => v);
361
- for (const device of devices) {
362
- if (device.remoteType) {
356
+ // IR Devices
357
+ const irDeviceLists = devicesAPI.body.infraredRemoteList;
358
+ if (!this.config.options?.irdevices) {
359
+ this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
360
+ const devices = irDeviceLists.map((v: any) => v);
361
+ for (const device of devices) {
362
+ if (device.remoteType) {
363
+ this.createIRDevice(device);
364
+ }
365
+ }
366
+ } else {
367
+ this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
368
+ const irDeviceConfig = this.config.options?.irdevices;
369
+
370
+ const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
371
+ a1.map((itm: { deviceId: string }) => ({
372
+ ...a2.find(
373
+ (item: { deviceId: string }) =>
374
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
375
+ ),
376
+ ...itm,
377
+ }));
378
+
379
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
380
+ this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
381
+ for (const device of devices) {
363
382
  this.createIRDevice(device);
364
383
  }
365
384
  }
366
- } else {
367
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
368
- const irDeviceConfig = this.config.options?.irdevices;
369
-
370
- const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
371
- a1.map((itm: { deviceId: string }) => ({
372
- ...a2.find(
373
- (item: { deviceId: string }) =>
374
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
375
- ),
376
- ...itm,
377
- }));
378
-
379
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
380
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
381
- for (const device of devices) {
382
- this.createIRDevice(device);
385
+ if (devicesAPI.body.infraredRemoteList.length !== 0) {
386
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
387
+ } else {
388
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
383
389
  }
384
- }
385
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
386
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
387
390
  } else {
388
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
391
+ this.statusCode(statusCode);
389
392
  }
390
393
  } catch (e: any) {
391
394
  this.debugErrorLog(