@switchbot/homebridge-switchbot 2.0.0-beta.27 → 2.0.0-beta.29

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/CHANGELOG.md +0 -2
  2. package/config.schema.json +2 -29
  3. package/dist/device/bot.d.ts +2 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +19 -9
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +2 -0
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +19 -9
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +2 -0
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +18 -8
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +2 -0
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +19 -9
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +2 -0
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +19 -9
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +2 -0
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +17 -3
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +2 -0
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +18 -8
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/meterplus.d.ts +2 -0
  32. package/dist/device/meterplus.d.ts.map +1 -1
  33. package/dist/device/meterplus.js +18 -8
  34. package/dist/device/meterplus.js.map +1 -1
  35. package/dist/device/motion.d.ts +2 -0
  36. package/dist/device/motion.d.ts.map +1 -1
  37. package/dist/device/motion.js +18 -8
  38. package/dist/device/motion.js.map +1 -1
  39. package/dist/device/plug.d.ts +2 -0
  40. package/dist/device/plug.d.ts.map +1 -1
  41. package/dist/device/plug.js +19 -9
  42. package/dist/device/plug.js.map +1 -1
  43. package/dist/device/striplight.d.ts +2 -0
  44. package/dist/device/striplight.d.ts.map +1 -1
  45. package/dist/device/striplight.js +19 -9
  46. package/dist/device/striplight.js.map +1 -1
  47. package/dist/irdevice/airconditioner.d.ts +2 -0
  48. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  49. package/dist/irdevice/airconditioner.js +14 -0
  50. package/dist/irdevice/airconditioner.js.map +1 -1
  51. package/dist/irdevice/airpurifier.d.ts +2 -0
  52. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  53. package/dist/irdevice/airpurifier.js +14 -0
  54. package/dist/irdevice/airpurifier.js.map +1 -1
  55. package/dist/irdevice/camera.d.ts +2 -0
  56. package/dist/irdevice/camera.d.ts.map +1 -1
  57. package/dist/irdevice/camera.js +14 -0
  58. package/dist/irdevice/camera.js.map +1 -1
  59. package/dist/irdevice/fan.d.ts +2 -0
  60. package/dist/irdevice/fan.d.ts.map +1 -1
  61. package/dist/irdevice/fan.js +14 -0
  62. package/dist/irdevice/fan.js.map +1 -1
  63. package/dist/irdevice/light.d.ts +2 -0
  64. package/dist/irdevice/light.d.ts.map +1 -1
  65. package/dist/irdevice/light.js +14 -0
  66. package/dist/irdevice/light.js.map +1 -1
  67. package/dist/irdevice/other.d.ts +2 -0
  68. package/dist/irdevice/other.d.ts.map +1 -1
  69. package/dist/irdevice/other.js +14 -0
  70. package/dist/irdevice/other.js.map +1 -1
  71. package/dist/irdevice/tv.d.ts +2 -0
  72. package/dist/irdevice/tv.d.ts.map +1 -1
  73. package/dist/irdevice/tv.js +14 -0
  74. package/dist/irdevice/tv.js.map +1 -1
  75. package/dist/irdevice/vacuumcleaner.d.ts +2 -0
  76. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  77. package/dist/irdevice/vacuumcleaner.js +14 -0
  78. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  79. package/dist/irdevice/waterheater.d.ts +2 -0
  80. package/dist/irdevice/waterheater.d.ts.map +1 -1
  81. package/dist/irdevice/waterheater.js +14 -0
  82. package/dist/irdevice/waterheater.js.map +1 -1
  83. package/dist/platform.d.ts +4 -5
  84. package/dist/platform.d.ts.map +1 -1
  85. package/dist/platform.js +155 -180
  86. package/dist/platform.js.map +1 -1
  87. package/dist/settings.d.ts +1 -0
  88. package/dist/settings.d.ts.map +1 -1
  89. package/dist/settings.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/device/bot.ts +21 -9
  92. package/src/device/colorbulb.ts +21 -9
  93. package/src/device/contact.ts +20 -8
  94. package/src/device/curtain.ts +21 -9
  95. package/src/device/humidifier.ts +21 -9
  96. package/src/device/lock.ts +19 -3
  97. package/src/device/meter.ts +20 -8
  98. package/src/device/meterplus.ts +20 -8
  99. package/src/device/motion.ts +20 -8
  100. package/src/device/plug.ts +21 -9
  101. package/src/device/striplight.ts +21 -9
  102. package/src/irdevice/airconditioner.ts +16 -0
  103. package/src/irdevice/airpurifier.ts +16 -0
  104. package/src/irdevice/camera.ts +16 -0
  105. package/src/irdevice/fan.ts +16 -0
  106. package/src/irdevice/light.ts +16 -0
  107. package/src/irdevice/other.ts +16 -0
  108. package/src/irdevice/tv.ts +16 -0
  109. package/src/irdevice/vacuumcleaner.ts +16 -0
  110. package/src/irdevice/waterheater.ts +16 -0
  111. package/src/platform.ts +151 -181
  112. package/src/settings.ts +1 -0
package/src/platform.ts CHANGED
@@ -27,7 +27,6 @@ import { readFileSync, writeFileSync } from 'fs';
27
27
  import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
28
28
  import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, DevicePath, HostDomain } from './settings';
29
29
  import { IncomingMessage } from 'http';
30
- import { interval, take } from 'rxjs';
31
30
 
32
31
  /**
33
32
  * HomebridgePlatform
@@ -43,7 +42,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
43
42
 
44
43
  version = require('../package.json').version || '1.12.8'; // eslint-disable-line @typescript-eslint/no-var-requires
45
44
  deviceStatus!: any;
46
- registeringDevice!: boolean;
47
45
  debugMode!: boolean;
48
46
  platformLogging?: string;
49
47
 
@@ -51,7 +49,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
51
49
 
52
50
  constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
53
51
  this.logs();
54
-
55
52
  this.debugLog('Finished initializing platform:', this.config.name);
56
53
  // only load if configured
57
54
  if (!this.config) {
@@ -68,10 +65,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
68
65
  this.verifyConfig();
69
66
  this.debugLog('Config OK');
70
67
  } catch (e: any) {
71
- this.errorLog(superStringify(e.message));
72
- if (this.platformLogging?.includes('debug')) {
73
- this.errorLog(`Verify Config: ${e}`);
74
- }
68
+ this.errorLog(`Verify Config, Error Message: ${e.message}`);
69
+ this.debugErrorLog(`Verify Config, Error: ${e}`);
75
70
  return;
76
71
  }
77
72
 
@@ -95,34 +90,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
95
90
  this.discoverDevices();
96
91
  }
97
92
  } catch (e: any) {
98
- this.errorLog('Failed to Discover Devices.', superStringify(e.message));
99
- if (this.platformLogging?.includes('debug')) {
100
- this.errorLog(`Platform: ${e}`);
101
- }
93
+ this.errorLog(`Failed to Discover, Error Message: ${e.message}`);
94
+ this.debugErrorLog(`Failed to Discover, Error: ${e}`);
102
95
  }
103
96
  });
104
97
  }
105
98
 
106
- logs() {
107
- this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
108
- if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
109
- this.platformLogging = this.config.options!.logging;
110
- if (this.platformLogging.includes('debug')) {
111
- this.log.warn(`Using Config Logging: ${this.platformLogging}`);
112
- }
113
- } else if (this.debugMode) {
114
- this.platformLogging = 'debugMode';
115
- if (this.platformLogging?.includes('debug')) {
116
- this.log.warn(`Using ${this.platformLogging} Logging`);
117
- }
118
- } else {
119
- this.platformLogging = 'standard';
120
- if (this.platformLogging?.includes('debug')) {
121
- this.log.warn(`Using ${this.platformLogging} Logging`);
122
- }
123
- }
124
- }
125
-
126
99
  /**
127
100
  * This function is invoked when homebridge restores cached accessories from disk at startup.
128
101
  * It should be used to setup event handlers for characteristics and update respective values.
@@ -191,48 +164,29 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
191
164
  if (!this.config.options.refreshRate) {
192
165
  // default 120 seconds (2 minutes)
193
166
  this.config.options!.refreshRate! = 120;
194
- if (this.platformLogging?.includes('debug')) {
195
- this.debugLog('Using Default Refresh Rate (2 minutes).');
196
- }
167
+ this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
197
168
  }
198
169
 
199
170
  if (!this.config.options.pushRate) {
200
171
  // default 100 milliseconds
201
172
  this.config.options!.pushRate! = 0.1;
202
- if (this.platformLogging?.includes('debug')) {
203
- this.warnLog('Using Default Push Rate.');
204
- }
173
+ this.debugWarnLog('Using Default Push Rate.');
205
174
  }
206
175
 
207
- if (!this.config.credentials) {
208
- if (this.platformLogging?.includes('debug')) {
209
- this.debugLog('Missing Credentials');
210
- }
211
- }
212
- if (!this.config.credentials?.token) {
213
- if (this.platformLogging?.includes('debug')) {
214
- this.errorLog('Missing token');
215
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
176
+ if (!this.config.credentials && !this.config.options) {
177
+ this.debugWarnLog('Missing Credentials');
178
+ } else if (this.config.credentials && !this.config.credentials.notice) {
179
+ if (!this.config.credentials?.token) {
180
+ this.debugErrorLog('Missing token');
181
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
216
182
  }
217
- }
218
- if (this.config.credentials?.token) {
219
- if (!this.config.credentials?.secret) {
220
- if (this.platformLogging?.includes('debug')) {
221
- this.errorLog('Missing secret');
222
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
183
+ if (this.config.credentials?.token) {
184
+ if (!this.config.credentials?.secret) {
185
+ this.debugErrorLog('Missing secret');
186
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
223
187
  }
224
188
  }
225
189
  }
226
-
227
- // Re-Discover Devices
228
- if (!this.config.options.discoverDevices) {
229
- this.config.options.discoverDevices = false;
230
- this.debugLog(`Rediscover Devices disabled, discoverDevices: ${this.config.options.discoverDevices}`);
231
- }
232
- if (!this.config.options.discoverDevicesInterval) {
233
- this.config.options.discoverDevicesInterval = 86400;
234
- this.debugLog(`Default Rediscover Devices Interval, discoverDevicesInterval: ${this.config.options.discoverDevicesInterval}`);
235
- }
236
190
  }
237
191
 
238
192
  /**
@@ -281,9 +235,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
281
235
  pluginConfig.credentials.token = this.config.credentials?.openToken;
282
236
  pluginConfig.credentials.openToken = 'Delete';
283
237
 
284
- if (this.platformLogging?.includes('debug')) {
285
- this.warnLog(`Token: ${pluginConfig.credentials.token}`);
286
- }
238
+ this.debugWarnLog(`Token: ${pluginConfig.credentials.token}`);
239
+
287
240
  // save the config, ensuring we maintain pretty json
288
241
  writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
289
242
  this.verifyConfig();
@@ -324,6 +277,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
324
277
  let rawData = '';
325
278
  res.on('data', (d) => {
326
279
  rawData += d;
280
+ this.deviceStatus = d;
327
281
  this.debugLog(`d: ${d}`);
328
282
  });
329
283
  res.on('end', () => {
@@ -384,6 +338,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
384
338
  } else {
385
339
  this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
386
340
  }
341
+ } else {
342
+ this.errorLog(`SwitchBot Device Request Issue: ${this.deviceStatus}`);
387
343
  }
388
344
  // IR Devices
389
345
  /*if (devicesAPI.body.infraredRemoteList.length !== 0) {
@@ -430,6 +386,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
430
386
  }
431
387
  }
432
388
  }
389
+ } else {
390
+ this.errorLog(`SwitchBot IR Device Request Issue: ${this.deviceStatus}`);
433
391
  }
434
392
  } catch (e:any) {
435
393
  this.errorLog(`API Request: ${e}`);
@@ -455,56 +413,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
455
413
  this.errorLog('Neither SwitchBot Token or Device Config are not set.');
456
414
  }
457
415
  } catch (e: any) {
458
- this.deviceError(`Discover Devices: ${e}`);
459
- }
460
- if (this.config.options?.discoverDevices) {
461
- interval(this.config.options!.discoverDevicesInterval * 1000)
462
- .pipe(take(1))
463
- .subscribe(async () => {
464
- await this.discoverDevices();
465
- });
466
- }
467
- }
468
-
469
- deviceError(e: any) {
470
- if (e.message.includes('400')) {
471
- this.errorLog('Failed to Discover Devices: Bad Request');
472
- this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
473
- } else if (e.message.includes('401')) {
474
- this.errorLog('Failed to Discover Devices: Unauthorized Request');
475
- this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
476
- } else if (e.message.includes('403')) {
477
- this.errorLog('Failed to Discover Devices: Forbidden Request');
478
- this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
479
- } else if (e.message.includes('404')) {
480
- this.errorLog('Failed to Discover Devices: Requst Not Found');
481
- this.debugLog('Specifies the requested path does not exist.');
482
- } else if (e.message.includes('406')) {
483
- this.errorLog('Failed to Discover Devices: Request Not Acceptable');
484
- this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
485
- } else if (e.message.includes('415')) {
486
- this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
487
- this.debugLog('The client has defined a contentType header that is not supported by the server.');
488
- } else if (e.message.includes('422')) {
489
- this.errorLog('Failed to Discover Devices: Unprocessable Entity');
490
- this.debugLog(
491
- 'The client has made a valid request, but the server cannot process it.' +
492
- ' This is often used for APIs for which certain limits have been exceeded.',
493
- );
494
- } else if (e.message.includes('429')) {
495
- this.errorLog('Failed to Discover Devices: Too Many Requests');
496
- this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
497
- } else if (e.message.includes('500')) {
498
- this.errorLog('Failed to Discover Devices: Internal Server Error');
499
- this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
500
- } else {
501
- this.errorLog('Failed to Discover Devices');
502
- }
503
- if (this.platformLogging === 'debug') {
504
- this.errorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
505
- }
506
- if (this.platformLogging === 'debugMode') {
507
- this.errorLog(`Failed to Discover Devices, Error: ${e}`);
416
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
417
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
508
418
  }
509
419
  }
510
420
 
@@ -541,7 +451,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
541
451
  this.createContact(device);
542
452
  break;
543
453
  case 'Curtain':
544
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
454
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
545
455
  this.createCurtain(device);
546
456
  break;
547
457
  case 'Plug':
@@ -688,7 +598,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
688
598
  this.externalOrPlatform(device, accessory);
689
599
  this.accessories.push(accessory);
690
600
  } else {
691
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
601
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
692
602
  }
693
603
  }
694
604
 
@@ -747,7 +657,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
747
657
  this.externalOrPlatform(device, accessory);
748
658
  this.accessories.push(accessory);
749
659
  } else {
750
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
660
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
751
661
  }
752
662
  }
753
663
 
@@ -801,7 +711,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
801
711
  this.externalOrPlatform(device, accessory);
802
712
  this.accessories.push(accessory);
803
713
  } else {
804
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
714
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
805
715
  }
806
716
  }
807
717
 
@@ -855,7 +765,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
855
765
  this.externalOrPlatform(device, accessory);
856
766
  this.accessories.push(accessory);
857
767
  } else {
858
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
768
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
859
769
  }
860
770
  }
861
771
 
@@ -909,7 +819,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
909
819
  this.externalOrPlatform(device, accessory);
910
820
  this.accessories.push(accessory);
911
821
  } else {
912
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
822
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
913
823
  }
914
824
  }
915
825
 
@@ -963,7 +873,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
963
873
  this.externalOrPlatform(device, accessory);
964
874
  this.accessories.push(accessory);
965
875
  } else {
966
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
876
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
967
877
  }
968
878
  }
969
879
 
@@ -976,7 +886,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
976
886
 
977
887
  if (existingAccessory) {
978
888
  // the accessory already exists
979
- if (this.isCurtainGrouped(device)) {
889
+ if (await this.registerDevice(device)) {
980
890
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
981
891
  existingAccessory.context.model = device.deviceType;
982
892
  existingAccessory.context.deviceID = device.deviceId;
@@ -993,7 +903,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
993
903
  } else {
994
904
  this.unregisterPlatformAccessories(existingAccessory);
995
905
  }
996
- } else if (this.isCurtainGrouped(device)) {
906
+ } else if (await this.registerDevice(device)) {
997
907
  // the accessory does not yet exist, so we need to create it
998
908
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
999
909
 
@@ -1002,9 +912,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1002
912
  , Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1003
913
  } else {
1004
914
  if (device.master) {
1005
- this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
915
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1006
916
  } else {
1007
- this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
917
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1008
918
  }
1009
919
  }
1010
920
 
@@ -1028,22 +938,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1028
938
  this.externalOrPlatform(device, accessory);
1029
939
  this.accessories.push(accessory);
1030
940
  } else {
1031
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1032
- }
1033
- }
1034
-
1035
- private isCurtainGrouped(device: device & devicesConfig) {
1036
- this.debugLog(
1037
- `deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
1038
- ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`,
1039
- );
1040
-
1041
- if (device.group && !device.curtain?.disable_group) {
1042
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1043
- return device.master && this.registerDevice(device);
1044
- } else {
1045
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1046
- return this.registerDevice(device);
941
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1047
942
  }
1048
943
  }
1049
944
 
@@ -1097,7 +992,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1097
992
  this.externalOrPlatform(device, accessory);
1098
993
  this.accessories.push(accessory);
1099
994
  } else {
1100
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
995
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1101
996
  }
1102
997
  }
1103
998
 
@@ -1151,7 +1046,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1151
1046
  this.externalOrPlatform(device, accessory);
1152
1047
  this.accessories.push(accessory);
1153
1048
  } else {
1154
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1049
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1155
1050
  }
1156
1051
  }
1157
1052
 
@@ -1205,7 +1100,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1205
1100
  this.externalOrPlatform(device, accessory);
1206
1101
  this.accessories.push(accessory);
1207
1102
  } else {
1208
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1103
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1209
1104
  }
1210
1105
  }
1211
1106
 
@@ -1259,7 +1154,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1259
1154
  this.externalOrPlatform(device, accessory);
1260
1155
  this.accessories.push(accessory);
1261
1156
  } else {
1262
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1157
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1263
1158
  }
1264
1159
  }
1265
1160
 
@@ -1312,7 +1207,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1312
1207
  this.externalAccessory(accessory);
1313
1208
  this.accessories.push(accessory);
1314
1209
  } else {
1315
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1210
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1316
1211
  }
1317
1212
  }
1318
1213
 
@@ -1366,7 +1261,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1366
1261
  this.externalOrPlatform(device, accessory);
1367
1262
  this.accessories.push(accessory);
1368
1263
  } else {
1369
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1264
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1370
1265
  }
1371
1266
  }
1372
1267
 
@@ -1420,7 +1315,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1420
1315
  this.externalOrPlatform(device, accessory);
1421
1316
  this.accessories.push(accessory);
1422
1317
  } else {
1423
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1318
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1424
1319
  }
1425
1320
  }
1426
1321
 
@@ -1474,7 +1369,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1474
1369
  this.externalOrPlatform(device, accessory);
1475
1370
  this.accessories.push(accessory);
1476
1371
  } else {
1477
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1372
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1478
1373
  }
1479
1374
  }
1480
1375
 
@@ -1528,7 +1423,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1528
1423
  this.externalOrPlatform(device, accessory);
1529
1424
  this.accessories.push(accessory);
1530
1425
  } else {
1531
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1426
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1532
1427
  }
1533
1428
  }
1534
1429
 
@@ -1582,7 +1477,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1582
1477
  this.externalOrPlatform(device, accessory);
1583
1478
  this.accessories.push(accessory);
1584
1479
  } else {
1585
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1480
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1586
1481
  }
1587
1482
  }
1588
1483
 
@@ -1636,7 +1531,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1636
1531
  this.externalOrPlatform(device, accessory);
1637
1532
  this.accessories.push(accessory);
1638
1533
  } else {
1639
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1534
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1640
1535
  }
1641
1536
  }
1642
1537
 
@@ -1690,7 +1585,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1690
1585
  this.externalOrPlatform(device, accessory);
1691
1586
  this.accessories.push(accessory);
1692
1587
  } else {
1693
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1588
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1694
1589
  }
1695
1590
  }
1696
1591
 
@@ -1744,12 +1639,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1744
1639
  this.externalOrPlatform(device, accessory);
1745
1640
  this.accessories.push(accessory);
1746
1641
  } else {
1747
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1642
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1643
+ }
1644
+ }
1645
+
1646
+ async registerCurtains(device: device & devicesConfig) {
1647
+ this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1648
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1649
+
1650
+ let registerCurtain: boolean;
1651
+ if (device.group && !device.curtain?.disable_group) {
1652
+ registerCurtain = true;
1653
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1654
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1655
+ } else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
1656
+ registerCurtain = true;
1657
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
1658
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1659
+ } else {
1660
+ registerCurtain = false;
1661
+ this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1662
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1748
1663
  }
1664
+ return registerCurtain;
1749
1665
  }
1750
1666
 
1751
1667
  async connectionType(device: device & devicesConfig): Promise<any> {
1752
- let connectionType = '';
1668
+ let connectionType: string;
1753
1669
  if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1754
1670
  connectionType = 'OpenAPI';
1755
1671
  } else {
@@ -1760,32 +1676,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1760
1676
 
1761
1677
  async registerDevice(device: device & devicesConfig) {
1762
1678
  device.connectionType = await this.connectionType(device);
1679
+ let registerDevice: boolean;
1763
1680
  if (!device.hide_device && device.enableCloudService && device.connectionType === 'BLE/OpenAPI') {
1764
- this.registeringDevice = true;
1765
- this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled, Connection Type: ${device.connectionType}`);
1681
+ if (device.deviceType === 'Curtain') {
1682
+ registerDevice = await this.registerCurtains(device);
1683
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1684
+ } else {
1685
+ registerDevice = true;
1686
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1687
+ }
1688
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1766
1689
  } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1767
1690
  && device.connectionType === 'BLE') {
1768
- this.registeringDevice = true;
1769
- this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled, Connection Type: ${device.connectionType}`);
1691
+ if (device.deviceType === 'Curtain') {
1692
+ registerDevice = await this.registerCurtains(device);
1693
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1694
+ } else {
1695
+ registerDevice = true;
1696
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1697
+ }
1698
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1770
1699
  } else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
1771
- this.registeringDevice = true;
1772
- this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled, Connection Type: ${device.connectionType}`);
1773
- } else if (!device.hide_device && device.enableCloudService && device.connectionType === 'Disable') {
1774
- this.registeringDevice = true;
1775
- this.debugLog(`Device: ${device.deviceName} Device connection Disabled, will continue to display in HomeKit,`
1776
- + ` Connection Type: ${device.connectionType}`);
1777
- } else if (!device.connectionType){
1778
- this.registeringDevice = false;
1779
- this.errorLog(`Device: ${device.deviceName} Connection Type not Set, will not display in HomeKit, Connection Type: ${device.connectionType}`);
1700
+ if (device.deviceType === 'Curtain') {
1701
+ registerDevice = await this.registerCurtains(device);
1702
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1703
+ } else {
1704
+ registerDevice = true;
1705
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1706
+ }
1707
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1708
+ } else if (!device.hide_device && device.connectionType === 'Disabled') {
1709
+ if (device.deviceType === 'Curtain') {
1710
+ registerDevice = await this.registerCurtains(device);
1711
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1712
+ } else {
1713
+ registerDevice = true;
1714
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1715
+ }
1716
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
1717
+ } else if (!device.connectionType && !device.hide_device) {
1718
+ registerDevice = false;
1719
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
1780
1720
  } else if (device.hide_device){
1781
- this.registeringDevice = false;
1782
- this.errorLog(`Device: ${device.deviceName} Device Set to Hidden, will not display in HomeKit, hide_device: ${device.hide_device}`);
1721
+ registerDevice = false;
1722
+ this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
1783
1723
  } else {
1784
- this.registeringDevice = false;
1785
- this.errorLog(`Device: ${device.deviceName} OpenAPI or BLE Are Not Enabled, Connection Type: ${device.connectionType},`
1786
- + ` hide_device: ${device.hide_device}`);
1724
+ registerDevice = false;
1725
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
1726
+ + `${device.hide_device}, will not display in HomeKit`);
1787
1727
  }
1788
- return this.registeringDevice;
1728
+ return registerDevice;
1789
1729
  }
1790
1730
 
1791
1731
  public async externalOrPlatform(device: device & devicesConfig, accessory: PlatformAccessory) {
@@ -1808,12 +1748,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1808
1748
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
1809
1749
  }
1810
1750
 
1811
- public deviceListInfo(devices) {
1812
- if (this.platformLogging?.includes('debug')) {
1813
- this.warnLog(`deviceListInfoStatus: ${superStringify(devices)}`);
1814
- }
1815
- }
1816
-
1817
1751
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
1818
1752
  switch (res.statusCode) {
1819
1753
  case 151:
@@ -1860,6 +1794,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1860
1794
  return switchbot;
1861
1795
  }
1862
1796
 
1797
+ logs() {
1798
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
1799
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
1800
+ this.platformLogging = this.config.options!.logging;
1801
+ if (this.platformLogging.includes('debug')) {
1802
+ this.log.warn(`Using Config Logging: ${this.platformLogging}`);
1803
+ }
1804
+ } else if (this.debugMode) {
1805
+ this.platformLogging = 'debugMode';
1806
+ if (this.platformLogging?.includes('debug')) {
1807
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1808
+ }
1809
+ } else {
1810
+ this.platformLogging = 'standard';
1811
+ if (this.platformLogging?.includes('debug')) {
1812
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1813
+ }
1814
+ }
1815
+ }
1816
+
1863
1817
  /**
1864
1818
  * If device level logging is turned on, log to log.warn
1865
1819
  * Otherwise send debug logs to log.debug
@@ -1876,12 +1830,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1876
1830
  }
1877
1831
  }
1878
1832
 
1833
+ debugWarnLog(...log: any[]): void {
1834
+ if (this.enablingPlatfromLogging()) {
1835
+ if (this.platformLogging?.includes('debug')) {
1836
+ this.log.warn('[DEBUG]', String(...log));
1837
+ }
1838
+ }
1839
+ }
1840
+
1879
1841
  errorLog(...log: any[]): void {
1880
1842
  if (this.enablingPlatfromLogging()) {
1881
1843
  this.log.error(String(...log));
1882
1844
  }
1883
1845
  }
1884
1846
 
1847
+ debugErrorLog(...log: any[]): void {
1848
+ if (this.enablingPlatfromLogging()) {
1849
+ if (this.platformLogging?.includes('debug')) {
1850
+ this.log.error('[DEBUG]', String(...log));
1851
+ }
1852
+ }
1853
+ }
1854
+
1885
1855
  debugLog(...log: any[]): void {
1886
1856
  if (this.enablingPlatfromLogging()) {
1887
1857
  if (this.platformLogging === 'debugMode') {
package/src/settings.ts CHANGED
@@ -29,6 +29,7 @@ export interface SwitchBotPlatformConfig extends PlatformConfig {
29
29
  export type credentials = {
30
30
  token?: any;
31
31
  secret?: any;
32
+ notice?: any;
32
33
  openToken?: any;
33
34
  };
34
35