@switchbot/homebridge-switchbot 0.1.2-beta.0 → 0.1.2-beta.12

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 (90) hide show
  1. package/.github/ISSUE_TEMPLATE/bug-report.yml +1 -1
  2. package/.github/ISSUE_TEMPLATE/config.yml +6 -6
  3. package/.github/ISSUE_TEMPLATE/support-request.yml +1 -1
  4. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +26 -6
  5. package/.github/dependabot.yml +2 -0
  6. package/.github/workflows/codeql-analysis.yml +71 -0
  7. package/.github/workflows/issue-validate.yml +3 -3
  8. package/.github/workflows/nodejs-beta.yml +4 -4
  9. package/.github/workflows/nodejs.yml +4 -4
  10. package/CHANGELOG.md +5 -1
  11. package/config.schema.json +18 -15
  12. package/dist/devices/bots.d.ts +1 -0
  13. package/dist/devices/bots.d.ts.map +1 -1
  14. package/dist/devices/bots.js +72 -24
  15. package/dist/devices/bots.js.map +1 -1
  16. package/dist/devices/bulb.d.ts +10 -1
  17. package/dist/devices/bulb.d.ts.map +1 -1
  18. package/dist/devices/bulb.js +13 -2
  19. package/dist/devices/bulb.js.map +1 -1
  20. package/dist/devices/contact.d.ts +13 -3
  21. package/dist/devices/contact.d.ts.map +1 -1
  22. package/dist/devices/contact.js +78 -3
  23. package/dist/devices/contact.js.map +1 -1
  24. package/dist/devices/curtains.d.ts +19 -8
  25. package/dist/devices/curtains.d.ts.map +1 -1
  26. package/dist/devices/curtains.js +98 -21
  27. package/dist/devices/curtains.js.map +1 -1
  28. package/dist/devices/humidifiers.d.ts.map +1 -1
  29. package/dist/devices/humidifiers.js +4 -4
  30. package/dist/devices/humidifiers.js.map +1 -1
  31. package/dist/devices/indoorcam.d.ts +42 -0
  32. package/dist/devices/indoorcam.d.ts.map +1 -0
  33. package/dist/devices/indoorcam.js +235 -0
  34. package/dist/devices/indoorcam.js.map +1 -0
  35. package/dist/devices/meters.d.ts +13 -4
  36. package/dist/devices/meters.d.ts.map +1 -1
  37. package/dist/devices/meters.js +36 -17
  38. package/dist/devices/meters.js.map +1 -1
  39. package/dist/devices/motion.d.ts +11 -3
  40. package/dist/devices/motion.d.ts.map +1 -1
  41. package/dist/devices/motion.js +70 -8
  42. package/dist/devices/motion.js.map +1 -1
  43. package/dist/devices/plugs.d.ts +11 -1
  44. package/dist/devices/plugs.d.ts.map +1 -1
  45. package/dist/devices/plugs.js +67 -1
  46. package/dist/devices/plugs.js.map +1 -1
  47. package/dist/irdevices/airconditioners.js +2 -2
  48. package/dist/irdevices/airconditioners.js.map +1 -1
  49. package/dist/irdevices/airpurifiers.js +2 -2
  50. package/dist/irdevices/airpurifiers.js.map +1 -1
  51. package/dist/irdevices/cameras.js +1 -1
  52. package/dist/irdevices/cameras.js.map +1 -1
  53. package/dist/irdevices/fans.js +1 -1
  54. package/dist/irdevices/fans.js.map +1 -1
  55. package/dist/irdevices/lights.js +3 -3
  56. package/dist/irdevices/lights.js.map +1 -1
  57. package/dist/irdevices/others.js +1 -1
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts.map +1 -1
  60. package/dist/irdevices/tvs.js +2 -3
  61. package/dist/irdevices/tvs.js.map +1 -1
  62. package/dist/irdevices/vacuumcleaners.js +1 -1
  63. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  64. package/dist/platform.d.ts +1 -0
  65. package/dist/platform.d.ts.map +1 -1
  66. package/dist/platform.js +104 -93
  67. package/dist/platform.js.map +1 -1
  68. package/dist/settings.d.ts +1 -2
  69. package/dist/settings.d.ts.map +1 -1
  70. package/package.json +9 -9
  71. package/src/devices/bots.ts +87 -37
  72. package/src/devices/bulb.ts +33 -3
  73. package/src/devices/contact.ts +102 -10
  74. package/src/devices/curtains.ts +137 -37
  75. package/src/devices/humidifiers.ts +9 -4
  76. package/src/devices/indoorcam.ts +304 -0
  77. package/src/devices/meters.ts +58 -22
  78. package/src/devices/motion.ts +93 -13
  79. package/src/devices/plugs.ts +89 -4
  80. package/src/irdevices/airconditioners.ts +2 -2
  81. package/src/irdevices/airpurifiers.ts +2 -2
  82. package/src/irdevices/cameras.ts +1 -1
  83. package/src/irdevices/fans.ts +1 -1
  84. package/src/irdevices/lights.ts +3 -3
  85. package/src/irdevices/others.ts +1 -1
  86. package/src/irdevices/tvs.ts +2 -4
  87. package/src/irdevices/vacuumcleaners.ts +1 -1
  88. package/src/platform.ts +120 -95
  89. package/src/settings.ts +1 -2
  90. package/.github/ISSUE_TEMPLATE.md +0 -48
package/src/platform.ts CHANGED
@@ -16,6 +16,7 @@ import { Meter } from './devices/meters';
16
16
  import { Motion } from './devices/motion';
17
17
  import { Contact } from './devices/contact';
18
18
  import { Curtain } from './devices/curtains';
19
+ import { IndoorCam } from './devices/indoorcam';
19
20
  import { Humidifier } from './devices/humidifiers';
20
21
  import { TV } from './irdevices/tvs';
21
22
  import { Fan } from './irdevices/fans';
@@ -73,8 +74,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
73
74
 
74
75
  // setup axios interceptor to add headers / api key to each request
75
76
  this.axios.interceptors.request.use((request: AxiosRequestConfig) => {
76
- request.headers.Authorization = this.config.credentials?.openToken;
77
- request.headers['Content-Type'] = 'application/json; charset=utf8';
77
+ request.headers!.Authorization = this.config.credentials?.openToken;
78
+ request.headers!['Content-Type'] = 'application/json; charset=utf8';
78
79
  return request;
79
80
  });
80
81
 
@@ -119,8 +120,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
119
120
  * Hidden Device Discovery Option
120
121
  * This will disable adding any device and will just output info.
121
122
  */
122
- this.config.devicediscovery;
123
-
124
123
  this.config.options = this.config.options || {};
125
124
 
126
125
  //Enable BLE for Device
@@ -209,79 +208,59 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
209
208
  */
210
209
  async discoverDevices() {
211
210
  try {
212
- const devices = (await this.axios.get(DeviceURL)).data;
211
+ const devices: any = (await this.axios.get(DeviceURL)).data;
213
212
 
214
- if (this.config.devicediscovery) {
215
- this.deviceListInfo(devices);
216
- } else {
217
- this.log.debug(JSON.stringify(devices));
218
- }
213
+ this.deviceListInfo(devices);
214
+ this.debug(JSON.stringify(devices));
219
215
  this.log.info('Total SwitchBot Devices Found:', devices.body.deviceList.length);
220
216
  this.log.info('Total IR Devices Found:', devices.body.infraredRemoteList.length);
221
217
  for (const device of devices.body.deviceList) {
222
- if (this.config.devicediscovery) {
218
+ if (this.config.options?.debug === 'device') {
223
219
  this.deviceInfo(device);
224
- } else {
225
- this.debug(JSON.stringify(device));
226
220
  }
221
+ this.debug(JSON.stringify(device));
227
222
  // For Future Devices
228
223
  switch (device.deviceType) {
229
224
  case 'Humidifier':
230
- if (this.config.devicediscovery) {
231
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
232
- }
225
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
233
226
  this.createHumidifier(device);
234
227
  break;
235
228
  case 'Hub Mini':
236
- if (this.config.devicediscovery) {
237
- this.log.info('Discovered a %s', device.deviceType);
238
- }
229
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
239
230
  break;
240
231
  case 'Hub Plus':
241
- if (this.config.devicediscovery) {
242
- this.log.info('Discovered a %s', device.deviceType);
243
- }
232
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
244
233
  break;
245
234
  case 'Bot':
246
- if (this.config.devicediscovery) {
247
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
248
- }
235
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
249
236
  this.createBot(device);
250
237
  break;
251
238
  case 'Meter':
252
- if (this.config.devicediscovery) {
253
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
254
- }
239
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
255
240
  this.createMeter(device);
256
241
  break;
257
242
  case 'Motion Sensor':
258
- if (this.config.devicediscovery) {
259
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
260
- }
243
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
261
244
  this.createMotion(device);
262
245
  break;
263
246
  case 'Contact Sensor':
264
- if (this.config.devicediscovery) {
265
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
266
- }
247
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
267
248
  this.createContact(device);
268
249
  break;
269
250
  case 'Curtain':
270
- if (this.config.devicediscovery) {
271
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
272
- }
251
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
273
252
  this.createCurtain(device);
274
253
  break;
275
254
  case 'Plug':
276
- if (this.config.devicediscovery) {
277
- this.log.info('Discovered %s %s', device.deviceName, device.deviceType);
278
- }
255
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
279
256
  this.createPlug(device);
280
257
  break;
258
+ case 'IndoorCam':
259
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId}`);
260
+ this.createIndoorCam(device);
261
+ break;
281
262
  case 'Remote':
282
- if (this.config.devicediscovery) {
283
- this.debug(`Discovered ${device.deviceName}, ${device.deviceType} is Not Supported.`);
284
- }
263
+ this.debug(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
285
264
  break;
286
265
  default:
287
266
  this.log.info(
@@ -293,11 +272,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
293
272
  }
294
273
  }
295
274
  for (const device of devices.body.infraredRemoteList) {
296
- if (this.config.devicediscovery) {
275
+ if (this.config.options?.debug === 'device') {
297
276
  this.deviceInfo(device);
298
- } else {
299
- this.debug(JSON.stringify(device));
300
277
  }
278
+ this.debug(JSON.stringify(device));
301
279
  // For Future Devices
302
280
  switch (device.remoteType) {
303
281
  case 'TV':
@@ -312,64 +290,46 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
312
290
  case 'DIY DVD':
313
291
  case 'Speaker':
314
292
  case 'DIY Speaker':
315
- if (this.config.devicediscovery) {
316
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
317
- }
293
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
318
294
  this.createTV(device);
319
295
  break;
320
296
  case 'Fan':
321
297
  case 'DIY Fan':
322
- if (this.config.devicediscovery) {
323
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
324
- }
298
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
325
299
  this.createFan(device);
326
300
  break;
327
301
  case 'Air Conditioner':
328
302
  case 'DIY Air Conditioner':
329
- if (this.config.devicediscovery) {
330
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
331
- }
303
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
332
304
  this.createAirConditioner(device);
333
305
  break;
334
306
  case 'Light':
335
307
  case 'DIY Light':
336
- if (this.config.devicediscovery) {
337
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
338
- }
308
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
339
309
  this.createLight(device);
340
310
  break;
341
311
  case 'Air Purifier':
342
312
  case 'DIY Air Purifier':
343
- if (this.config.devicediscovery) {
344
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
345
- }
313
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
346
314
  this.createAirPurifier(device);
347
315
  break;
348
316
  case 'Water Heater':
349
317
  case 'DIY Water Heater':
350
- if (this.config.devicediscovery) {
351
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
352
- }
318
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
353
319
  this.createWaterHeater(device);
354
320
  break;
355
321
  case 'Vacuum Cleaner':
356
322
  case 'DIY Vacuum Cleaner':
357
- if (this.config.devicediscovery) {
358
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
359
- }
323
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
360
324
  this.createVacuumCleaner(device);
361
325
  break;
362
326
  case 'Camera':
363
327
  case 'DIY Camera':
364
- if (this.config.devicediscovery) {
365
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
366
- }
328
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
367
329
  this.createCamera(device);
368
330
  break;
369
331
  case 'Others':
370
- if (this.config.devicediscovery) {
371
- this.log.info('Discovered %s %s', device.deviceName, device.remoteType);
372
- }
332
+ this.debug(`Discovered ${device.remoteType}: ${device.deviceId}`);
373
333
  this.createOthers(device);
374
334
  break;
375
335
  default:
@@ -440,7 +400,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
440
400
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
441
401
  this.accessories.push(accessory);
442
402
  } else {
443
- if (this.config.devicediscovery) {
403
+ if (this.config.options?.debug === 'device') {
444
404
  this.log.error(
445
405
  'Unable to Register new device: %s %s - %s',
446
406
  device.deviceName,
@@ -507,7 +467,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
507
467
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
508
468
  this.accessories.push(accessory);
509
469
  } else {
510
- if (this.config.devicediscovery) {
470
+ if (this.config.options?.debug === 'device') {
511
471
  this.log.error(
512
472
  'Unable to Register new device: %s %s - %s',
513
473
  device.deviceName,
@@ -570,7 +530,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
570
530
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
571
531
  this.accessories.push(accessory);
572
532
  } else {
573
- if (this.config.devicediscovery) {
533
+ if (this.config.options?.debug === 'device') {
574
534
  this.log.error(
575
535
  'Unable to Register new device: %s %s - %s',
576
536
  device.deviceName,
@@ -631,7 +591,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
631
591
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
632
592
  this.accessories.push(accessory);
633
593
  } else {
634
- if (this.config.devicediscovery) {
594
+ if (this.config.options?.debug === 'device') {
635
595
  this.log.error(
636
596
  'Unable to Register new device: %s %s - %s',
637
597
  device.deviceName,
@@ -692,7 +652,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
692
652
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
693
653
  this.accessories.push(accessory);
694
654
  } else {
695
- if (this.config.devicediscovery) {
655
+ if (this.config.options?.debug === 'device') {
696
656
  this.log.error(
697
657
  'Unable to Register new device: %s %s - %s',
698
658
  device.deviceName,
@@ -768,7 +728,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
768
728
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
769
729
  this.accessories.push(accessory);
770
730
  } else {
771
- if (this.config.devicediscovery) {
731
+ if (this.config.options?.debug === 'device') {
772
732
  this.log.error(
773
733
  'Unable to Register new device: %s %s - %s',
774
734
  device.deviceName,
@@ -839,7 +799,70 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
839
799
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
840
800
  this.accessories.push(accessory);
841
801
  } else {
842
- if (this.config.devicediscovery) {
802
+ if (this.config.options?.debug === 'device') {
803
+ this.log.error(
804
+ 'Unable to Register new device: %s %s - %s',
805
+ device.deviceName,
806
+ device.deviceType,
807
+ device.deviceId,
808
+ );
809
+ }
810
+ }
811
+ }
812
+
813
+ private async createIndoorCam(device: device) {
814
+ const uuid = this.api.hap.uuid.generate(`${device.deviceName}-${device.deviceId}-${device.deviceType}`);
815
+
816
+ // see if an accessory with the same uuid has already been registered and restored from
817
+ // the cached devices we stored in the `configureAccessory` method above
818
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
819
+
820
+ if (existingAccessory) {
821
+ // the accessory already exists
822
+ if (!this.config.options?.hide_device.includes(device.deviceId!) && device.enableCloudService) {
823
+ this.log.info(
824
+ 'Restoring existing accessory from cache: %s DeviceID: %s',
825
+ existingAccessory.displayName,
826
+ device.deviceId,
827
+ );
828
+
829
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
830
+ existingAccessory.context.model = device.deviceType;
831
+ existingAccessory.context.deviceID = device.deviceId;
832
+ existingAccessory.context.firmwareRevision = this.version;
833
+ await this.connectionTypeExistingAccessory(device, existingAccessory);
834
+ this.api.updatePlatformAccessories([existingAccessory]);
835
+ // create the accessory handler for the restored accessory
836
+ // this is imported from `platformAccessory.ts`
837
+ new IndoorCam(this, existingAccessory, device);
838
+ this.debug(`${device.deviceType} UDID: ${device.deviceName}-${device.deviceId}-${device.deviceType}`);
839
+ } else {
840
+ this.unregisterPlatformAccessories(existingAccessory);
841
+ }
842
+ } else if (!this.config.options?.hide_device.includes(device.deviceId!) && device.enableCloudService) {
843
+ // the accessory does not yet exist, so we need to create it
844
+ this.log.info('Adding new accessory: %s %s DeviceID: %s', device.deviceName, device.deviceType, device.deviceId);
845
+
846
+ // create a new accessory
847
+ const accessory = new this.api.platformAccessory(`${device.deviceName} ${device.deviceType}`, uuid);
848
+
849
+ // store a copy of the device object in the `accessory.context`
850
+ // the `context` property can be used to store any data about the accessory you may need
851
+ accessory.context.device = device;
852
+ accessory.context.model = device.deviceType;
853
+ accessory.context.deviceID = device.deviceId;
854
+ accessory.context.firmwareRevision = this.version;
855
+ await this.connectionTypeNewAccessory(device, accessory);
856
+ // create the accessory handler for the newly create accessory
857
+ // this is imported from `platformAccessory.ts`
858
+ new IndoorCam(this, accessory, device);
859
+ this.debug(`${device.deviceType} UDID: ${device.deviceName}-${device.deviceId}-${device.deviceType}`);
860
+
861
+ // link the accessory to your platform
862
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
863
+ this.accessories.push(accessory);
864
+ } else {
865
+ if (this.config.options?.debug === 'device') {
843
866
  this.log.error(
844
867
  'Unable to Register new device: %s %s - %s',
845
868
  device.deviceName,
@@ -907,7 +930,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
907
930
  this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
908
931
  this.accessories.push(accessory);
909
932
  } else {
910
- if (this.config.devicediscovery) {
933
+ if (this.config.options?.debug === 'device') {
911
934
  this.log.error(
912
935
  'Unable to Register new device: %s %s - %s',
913
936
  device.deviceName,
@@ -971,7 +994,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
971
994
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
972
995
  this.accessories.push(accessory);
973
996
  } else {
974
- if (this.config.devicediscovery) {
997
+ if (this.config.options?.debug === 'device') {
975
998
  this.log.error(
976
999
  'Unable to Register new device: %s %s - %s',
977
1000
  device.deviceName,
@@ -1034,7 +1057,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1034
1057
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1035
1058
  this.accessories.push(accessory);
1036
1059
  } else {
1037
- if (this.config.devicediscovery) {
1060
+ if (this.config.options?.debug === 'device') {
1038
1061
  this.log.error(
1039
1062
  'Unable to Register new device: %s %s - %s',
1040
1063
  device.deviceName,
@@ -1097,7 +1120,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1097
1120
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1098
1121
  this.accessories.push(accessory);
1099
1122
  } else {
1100
- if (this.config.devicediscovery) {
1123
+ if (this.config.options?.debug === 'device') {
1101
1124
  this.log.error(
1102
1125
  'Unable to Register new device: %s %s - %s',
1103
1126
  device.deviceName,
@@ -1160,7 +1183,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1160
1183
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1161
1184
  this.accessories.push(accessory);
1162
1185
  } else {
1163
- if (this.config.devicediscovery) {
1186
+ if (this.config.options?.debug === 'device') {
1164
1187
  this.log.error(
1165
1188
  'Unable to Register new device: %s %s - %s',
1166
1189
  device.deviceName,
@@ -1223,7 +1246,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1223
1246
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1224
1247
  this.accessories.push(accessory);
1225
1248
  } else {
1226
- if (this.config.devicediscovery) {
1249
+ if (this.config.options?.debug === 'device') {
1227
1250
  this.log.error(
1228
1251
  'Unable to Register new device: %s %s - %s',
1229
1252
  device.deviceName,
@@ -1286,7 +1309,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1286
1309
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1287
1310
  this.accessories.push(accessory);
1288
1311
  } else {
1289
- if (this.config.devicediscovery) {
1312
+ if (this.config.options?.debug === 'device') {
1290
1313
  this.log.error(
1291
1314
  'Unable to Register new device: %s %s - %s',
1292
1315
  device.deviceName,
@@ -1349,7 +1372,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1349
1372
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1350
1373
  this.accessories.push(accessory);
1351
1374
  } else {
1352
- if (this.config.devicediscovery) {
1375
+ if (this.config.options?.debug === 'device') {
1353
1376
  this.log.error(
1354
1377
  'Unable to Register new device: %s %s - %s',
1355
1378
  device.deviceName,
@@ -1412,7 +1435,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1412
1435
  this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1413
1436
  this.accessories.push(accessory);
1414
1437
  } else {
1415
- if (this.config.devicediscovery) {
1438
+ if (this.config.options?.debug === 'device') {
1416
1439
  this.log.error(
1417
1440
  'Unable to Register new device: %s %s - %s',
1418
1441
  device.deviceName,
@@ -1451,17 +1474,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1451
1474
  }
1452
1475
 
1453
1476
  public deviceListInfo(devices: deviceResponses) {
1454
- this.log.warn(JSON.stringify(devices));
1477
+ this.debug(JSON.stringify(devices));
1455
1478
  }
1456
1479
 
1457
1480
  public async deviceInfo(device: irdevice | device) {
1458
1481
  this.log.warn(JSON.stringify(device));
1459
1482
  const deviceStatus: deviceStatusResponse = (await this.axios.get(`${DeviceURL}/${device.deviceId}/status`)).data;
1460
1483
  if (deviceStatus.message === 'success') {
1461
- this.log.warn('deviceStatus -', device.deviceName, JSON.stringify(deviceStatus));
1484
+ this.debug('deviceStatus -', device.deviceName, JSON.stringify(deviceStatus));
1462
1485
  } else {
1463
- this.log.warn('deviceStatus -', device.deviceName, JSON.stringify(deviceStatus.message));
1464
- this.log.error('Unable to retreive device status.');
1486
+ this.debug('deviceStatus -', device.deviceName, JSON.stringify(deviceStatus.message));
1487
+ this.debug('Unable to retreive device status.');
1465
1488
  }
1466
1489
  }
1467
1490
 
@@ -1470,9 +1493,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1470
1493
  * Otherwise send debug logs to log.debug
1471
1494
  */
1472
1495
  debug(...log: any[]) {
1473
- if (this.config.options?.debug) {
1496
+ if (this.config.options!.debug === 'debug') {
1474
1497
  this.log.info('[DEBUG]', String(...log));
1475
- } else{
1498
+ } else if (this.config.options!.debug === 'device') {
1499
+ this.log.warn('[DEVICE]', String(...log));
1500
+ } else {
1476
1501
  this.log.debug(String(...log));
1477
1502
  }
1478
1503
  }
package/src/settings.ts CHANGED
@@ -22,7 +22,6 @@ export const DeviceURL = 'https://api.switch-bot.com/v1.0/devices';
22
22
  //Config
23
23
  export interface SwitchBotPlatformConfig extends PlatformConfig {
24
24
  credentials?: credentials;
25
- devicediscovery?: boolean;
26
25
  options?: options | Record<string, never>;
27
26
  }
28
27
 
@@ -34,7 +33,7 @@ export type options = {
34
33
  refreshRate?: number;
35
34
  pushRate?: number;
36
35
  hide_device: string[];
37
- debug?: boolean;
36
+ debug?: string;
38
37
  bot?: bot;
39
38
  meter?: meter;
40
39
  humidifier?: humidifier;
@@ -1,48 +0,0 @@
1
- ---
2
- name: Bug Report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- <!-- You must use the issue template below when submitting a bug -->
11
-
12
- **Describe The Bug:**
13
- <!-- A clear and concise description of what the bug is. -->
14
-
15
- **To Reproduce:**
16
- <!-- Steps to reproduce the behavior. -->
17
-
18
- **Expected behavior:**
19
- <!-- A clear and concise description of what you expected to happen. -->
20
-
21
- **Logs:**
22
- <!-- Bug reports that do not contain logs may be closed without warning. -->
23
-
24
- ```
25
- Show the Homebridge / Homebridge Config UI X logs here.
26
- ```
27
-
28
- **Homebridge Config:**
29
-
30
- ```json
31
- Show your homebridge config.json here
32
- ```
33
-
34
- **Screenshots:**
35
- <!-- If applicable, add screenshots to help explain your problem. -->
36
-
37
- **Environment:**
38
-
39
- * **Node.js Version**: <!-- node -v -->
40
- * **NPM Version**: <!-- npm -v -->
41
- * **Homebridge Version**: <!-- homebridge -V -->
42
- * **Homebridge SwitchBot BLE Plugin Version**:
43
- * **Homebridge Config UI X Version**:
44
- * **Operating System**: Raspbian / Ubuntu / Debian / Windows / macOS / Docker
45
- * **Process Supervisor**: Docker / Systemd / init.d / pm2 / launchctl / hb-service / other / none
46
-
47
-
48
- <!-- Click the "Preview" tab before you submit to ensure the formatting is correct. -->