@switchbot/homebridge-switchbot 2.2.1-beta.1 → 2.2.2-beta.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 (43) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/device/bot.js +1 -1
  3. package/dist/device/bot.js.map +1 -1
  4. package/dist/device/ceilinglight.d.ts +3 -0
  5. package/dist/device/ceilinglight.d.ts.map +1 -1
  6. package/dist/device/ceilinglight.js +14 -10
  7. package/dist/device/ceilinglight.js.map +1 -1
  8. package/dist/device/colorbulb.js +1 -1
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.js +1 -1
  11. package/dist/device/contact.js.map +1 -1
  12. package/dist/device/curtain.js +1 -1
  13. package/dist/device/curtain.js.map +1 -1
  14. package/dist/device/humidifier.js +1 -1
  15. package/dist/device/humidifier.js.map +1 -1
  16. package/dist/device/lock.js +1 -1
  17. package/dist/device/lock.js.map +1 -1
  18. package/dist/device/meter.js +1 -1
  19. package/dist/device/meter.js.map +1 -1
  20. package/dist/device/meterplus.js +1 -1
  21. package/dist/device/meterplus.js.map +1 -1
  22. package/dist/device/motion.js +1 -1
  23. package/dist/device/motion.js.map +1 -1
  24. package/dist/device/plug.js +1 -1
  25. package/dist/device/plug.js.map +1 -1
  26. package/dist/device/striplight.js +1 -1
  27. package/dist/device/striplight.js.map +1 -1
  28. package/dist/platform.js +66 -67
  29. package/dist/platform.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/device/bot.ts +1 -1
  32. package/src/device/ceilinglight.ts +14 -9
  33. package/src/device/colorbulb.ts +1 -1
  34. package/src/device/contact.ts +1 -1
  35. package/src/device/curtain.ts +1 -1
  36. package/src/device/humidifier.ts +1 -1
  37. package/src/device/lock.ts +1 -1
  38. package/src/device/meter.ts +1 -1
  39. package/src/device/meterplus.ts +1 -1
  40. package/src/device/motion.ts +1 -1
  41. package/src/device/plug.ts +1 -1
  42. package/src/device/striplight.ts +1 -1
  43. package/src/platform.ts +75 -75
package/src/platform.ts CHANGED
@@ -285,91 +285,91 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
285
285
  this.debugLog(`d: ${d}`);
286
286
  });
287
287
  res.on('end', () => {
288
- try {
289
- const devicesAPI = JSON.parse(rawData);
290
- this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
291
- // SwitchBot Devices
292
- if (devicesAPI.body.deviceList.length !== 0) {
293
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
294
- } else {
295
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
296
- }
297
- const deviceLists = devicesAPI.body.deviceList;
298
- if (!this.config.options?.devices) {
299
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
300
- const devices = deviceLists.map((v: any) => v);
301
- for (const device of devices) {
302
- if (device.deviceType) {
303
- if (device.configDeviceName) {
304
- device.deviceName = device.configDeviceName;
305
- }
306
- this.createDevice(device);
288
+ // try {
289
+ const devicesAPI = JSON.parse(rawData);
290
+ this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
291
+ // SwitchBot Devices
292
+ if (devicesAPI.body.deviceList.length !== 0) {
293
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
294
+ } else {
295
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
296
+ }
297
+ const deviceLists = devicesAPI.body.deviceList;
298
+ if (!this.config.options?.devices) {
299
+ this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
300
+ const devices = deviceLists.map((v: any) => v);
301
+ for (const device of devices) {
302
+ if (device.deviceType) {
303
+ if (device.configDeviceName) {
304
+ device.deviceName = device.configDeviceName;
307
305
  }
306
+ this.createDevice(device);
308
307
  }
309
- } else if (this.config.credentials?.token && this.config.options.devices) {
310
- this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
311
- const deviceConfigs = this.config.options?.devices;
312
-
313
- const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
314
- a1.map((itm: { deviceId: string }) => ({
315
- ...a2.find(
316
- (item: { deviceId: string }) =>
317
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
318
- ),
319
- ...itm,
320
- }));
321
-
322
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
323
- this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
324
- for (const device of devices) {
325
- if (device.deviceType) {
326
- if (device.configDeviceName) {
327
- device.deviceName = device.configDeviceName;
328
- }
329
- this.createDevice(device);
308
+ }
309
+ } else if (this.config.credentials?.token && this.config.options.devices) {
310
+ this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
311
+ const deviceConfigs = this.config.options?.devices;
312
+
313
+ const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
314
+ a1.map((itm: { deviceId: string }) => ({
315
+ ...a2.find(
316
+ (item: { deviceId: string }) =>
317
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
318
+ ),
319
+ ...itm,
320
+ }));
321
+
322
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
323
+ this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
324
+ for (const device of devices) {
325
+ if (device.deviceType) {
326
+ if (device.configDeviceName) {
327
+ device.deviceName = device.configDeviceName;
330
328
  }
329
+ this.createDevice(device);
331
330
  }
332
- } else {
333
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
334
331
  }
332
+ } else {
333
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
334
+ }
335
335
 
336
- // IR Devices
337
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
338
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
339
- } else {
340
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
341
- }
342
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
343
- if (!this.config.options?.irdevices) {
344
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
345
- const devices = irDeviceLists.map((v: any) => v);
346
- for (const device of devices) {
347
- if (device.remoteType) {
348
- this.createIRDevice(device);
349
- }
350
- }
351
- } else {
352
- this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
353
- const irDeviceConfig = this.config.options?.irdevices;
354
-
355
- const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
356
- a1.map((itm: { deviceId: string }) => ({
357
- ...a2.find(
358
- (item: { deviceId: string }) =>
359
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
360
- ),
361
- ...itm,
362
- }));
363
-
364
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
365
- this.debugLog(`IR Devices: ${superStringify(devices)}`);
366
- for (const device of devices) {
336
+ // IR Devices
337
+ if (devicesAPI.body.infraredRemoteList.length !== 0) {
338
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
339
+ } else {
340
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
341
+ }
342
+ const irDeviceLists = devicesAPI.body.infraredRemoteList;
343
+ if (!this.config.options?.irdevices) {
344
+ this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
345
+ const devices = irDeviceLists.map((v: any) => v);
346
+ for (const device of devices) {
347
+ if (device.remoteType) {
367
348
  this.createIRDevice(device);
368
349
  }
369
350
  }
370
- } catch (e:any) {
371
- this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
351
+ } else {
352
+ this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
353
+ const irDeviceConfig = this.config.options?.irdevices;
354
+
355
+ const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
356
+ a1.map((itm: { deviceId: string }) => ({
357
+ ...a2.find(
358
+ (item: { deviceId: string }) =>
359
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
360
+ ),
361
+ ...itm,
362
+ }));
363
+
364
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
365
+ this.debugLog(`IR Devices: ${superStringify(devices)}`);
366
+ for (const device of devices) {
367
+ this.createIRDevice(device);
368
+ }
372
369
  }
370
+ //} catch (e:any) {
371
+ // this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
372
+ // }
373
373
  });
374
374
  });
375
375
  req.on('error', (e: any) => {