@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/dist/platform.js CHANGED
@@ -31,7 +31,6 @@ const fakegato_history_1 = __importDefault(require("fakegato-history"));
31
31
  const super_stringify_1 = __importDefault(require("super-stringify"));
32
32
  const fs_1 = require("fs");
33
33
  const settings_1 = require("./settings");
34
- const rxjs_1 = require("rxjs");
35
34
  /**
36
35
  * HomebridgePlatform
37
36
  * This class is the main constructor for your plugin, this is where you should
@@ -63,10 +62,8 @@ class SwitchBotPlatform {
63
62
  this.debugLog('Config OK');
64
63
  }
65
64
  catch (e) {
66
- this.errorLog((0, super_stringify_1.default)(e.message));
67
- if (this.platformLogging?.includes('debug')) {
68
- this.errorLog(`Verify Config: ${e}`);
69
- }
65
+ this.errorLog(`Verify Config, Error Message: ${e.message}`);
66
+ this.debugErrorLog(`Verify Config, Error: ${e}`);
70
67
  return;
71
68
  }
72
69
  // import fakegato-history module
@@ -91,34 +88,11 @@ class SwitchBotPlatform {
91
88
  }
92
89
  }
93
90
  catch (e) {
94
- this.errorLog('Failed to Discover Devices.', (0, super_stringify_1.default)(e.message));
95
- if (this.platformLogging?.includes('debug')) {
96
- this.errorLog(`Platform: ${e}`);
97
- }
91
+ this.errorLog(`Failed to Discover, Error Message: ${e.message}`);
92
+ this.debugErrorLog(`Failed to Discover, Error: ${e}`);
98
93
  }
99
94
  });
100
95
  }
101
- logs() {
102
- this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
103
- if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
104
- this.platformLogging = this.config.options.logging;
105
- if (this.platformLogging.includes('debug')) {
106
- this.log.warn(`Using Config Logging: ${this.platformLogging}`);
107
- }
108
- }
109
- else if (this.debugMode) {
110
- this.platformLogging = 'debugMode';
111
- if (this.platformLogging?.includes('debug')) {
112
- this.log.warn(`Using ${this.platformLogging} Logging`);
113
- }
114
- }
115
- else {
116
- this.platformLogging = 'standard';
117
- if (this.platformLogging?.includes('debug')) {
118
- this.log.warn(`Using ${this.platformLogging} Logging`);
119
- }
120
- }
121
- }
122
96
  /**
123
97
  * This function is invoked when homebridge restores cached accessories from disk at startup.
124
98
  * It should be used to setup event handlers for characteristics and update respective values.
@@ -180,45 +154,28 @@ class SwitchBotPlatform {
180
154
  if (!this.config.options.refreshRate) {
181
155
  // default 120 seconds (2 minutes)
182
156
  this.config.options.refreshRate = 120;
183
- if (this.platformLogging?.includes('debug')) {
184
- this.debugLog('Using Default Refresh Rate (2 minutes).');
185
- }
157
+ this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
186
158
  }
187
159
  if (!this.config.options.pushRate) {
188
160
  // default 100 milliseconds
189
161
  this.config.options.pushRate = 0.1;
190
- if (this.platformLogging?.includes('debug')) {
191
- this.warnLog('Using Default Push Rate.');
192
- }
162
+ this.debugWarnLog('Using Default Push Rate.');
193
163
  }
194
- if (!this.config.credentials) {
195
- if (this.platformLogging?.includes('debug')) {
196
- this.debugLog('Missing Credentials');
197
- }
164
+ if (!this.config.credentials && !this.config.options) {
165
+ this.debugWarnLog('Missing Credentials');
198
166
  }
199
- if (!this.config.credentials?.token) {
200
- if (this.platformLogging?.includes('debug')) {
201
- this.errorLog('Missing token');
202
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
167
+ else if (this.config.credentials && !this.config.credentials.notice) {
168
+ if (!this.config.credentials?.token) {
169
+ this.debugErrorLog('Missing token');
170
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
203
171
  }
204
- }
205
- if (this.config.credentials?.token) {
206
- if (!this.config.credentials?.secret) {
207
- if (this.platformLogging?.includes('debug')) {
208
- this.errorLog('Missing secret');
209
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
172
+ if (this.config.credentials?.token) {
173
+ if (!this.config.credentials?.secret) {
174
+ this.debugErrorLog('Missing secret');
175
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
210
176
  }
211
177
  }
212
178
  }
213
- // Re-Discover Devices
214
- if (!this.config.options.discoverDevices) {
215
- this.config.options.discoverDevices = false;
216
- this.debugLog(`Rediscover Devices disabled, discoverDevices: ${this.config.options.discoverDevices}`);
217
- }
218
- if (!this.config.options.discoverDevicesInterval) {
219
- this.config.options.discoverDevicesInterval = 86400;
220
- this.debugLog(`Default Rediscover Devices Interval, discoverDevicesInterval: ${this.config.options.discoverDevicesInterval}`);
221
- }
222
179
  }
223
180
  /**
224
181
  * The openToken was old config.
@@ -260,9 +217,7 @@ class SwitchBotPlatform {
260
217
  // set the refresh token
261
218
  pluginConfig.credentials.token = this.config.credentials?.openToken;
262
219
  pluginConfig.credentials.openToken = 'Delete';
263
- if (this.platformLogging?.includes('debug')) {
264
- this.warnLog(`Token: ${pluginConfig.credentials.token}`);
265
- }
220
+ this.debugWarnLog(`Token: ${pluginConfig.credentials.token}`);
266
221
  // save the config, ensuring we maintain pretty json
267
222
  (0, fs_1.writeFileSync)(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
268
223
  this.verifyConfig();
@@ -303,6 +258,7 @@ class SwitchBotPlatform {
303
258
  let rawData = '';
304
259
  res.on('data', (d) => {
305
260
  rawData += d;
261
+ this.deviceStatus = d;
306
262
  this.debugLog(`d: ${d}`);
307
263
  });
308
264
  res.on('end', () => {
@@ -360,6 +316,9 @@ class SwitchBotPlatform {
360
316
  this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
361
317
  }
362
318
  }
319
+ else {
320
+ this.errorLog(`SwitchBot Device Request Issue: ${this.deviceStatus}`);
321
+ }
363
322
  // IR Devices
364
323
  /*if (devicesAPI.body.infraredRemoteList.length !== 0) {
365
324
  this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
@@ -402,6 +361,9 @@ class SwitchBotPlatform {
402
361
  }
403
362
  }
404
363
  }
364
+ else {
365
+ this.errorLog(`SwitchBot IR Device Request Issue: ${this.deviceStatus}`);
366
+ }
405
367
  }
406
368
  catch (e) {
407
369
  this.errorLog(`API Request: ${e}`);
@@ -430,62 +392,8 @@ class SwitchBotPlatform {
430
392
  }
431
393
  }
432
394
  catch (e) {
433
- this.deviceError(`Discover Devices: ${e}`);
434
- }
435
- if (this.config.options?.discoverDevices) {
436
- (0, rxjs_1.interval)(this.config.options.discoverDevicesInterval * 1000)
437
- .pipe((0, rxjs_1.take)(1))
438
- .subscribe(async () => {
439
- await this.discoverDevices();
440
- });
441
- }
442
- }
443
- deviceError(e) {
444
- if (e.message.includes('400')) {
445
- this.errorLog('Failed to Discover Devices: Bad Request');
446
- this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
447
- }
448
- else if (e.message.includes('401')) {
449
- this.errorLog('Failed to Discover Devices: Unauthorized Request');
450
- this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
451
- }
452
- else if (e.message.includes('403')) {
453
- this.errorLog('Failed to Discover Devices: Forbidden Request');
454
- this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
455
- }
456
- else if (e.message.includes('404')) {
457
- this.errorLog('Failed to Discover Devices: Requst Not Found');
458
- this.debugLog('Specifies the requested path does not exist.');
459
- }
460
- else if (e.message.includes('406')) {
461
- this.errorLog('Failed to Discover Devices: Request Not Acceptable');
462
- this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
463
- }
464
- else if (e.message.includes('415')) {
465
- this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
466
- this.debugLog('The client has defined a contentType header that is not supported by the server.');
467
- }
468
- else if (e.message.includes('422')) {
469
- this.errorLog('Failed to Discover Devices: Unprocessable Entity');
470
- this.debugLog('The client has made a valid request, but the server cannot process it.' +
471
- ' This is often used for APIs for which certain limits have been exceeded.');
472
- }
473
- else if (e.message.includes('429')) {
474
- this.errorLog('Failed to Discover Devices: Too Many Requests');
475
- this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
476
- }
477
- else if (e.message.includes('500')) {
478
- this.errorLog('Failed to Discover Devices: Internal Server Error');
479
- this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
480
- }
481
- else {
482
- this.errorLog('Failed to Discover Devices');
483
- }
484
- if (this.platformLogging === 'debug') {
485
- this.errorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
486
- }
487
- if (this.platformLogging === 'debugMode') {
488
- this.errorLog(`Failed to Discover Devices, Error: ${e}`);
395
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
396
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
489
397
  }
490
398
  }
491
399
  createDevice(device) {
@@ -521,7 +429,7 @@ class SwitchBotPlatform {
521
429
  this.createContact(device);
522
430
  break;
523
431
  case 'Curtain':
524
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
432
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
525
433
  this.createCurtain(device);
526
434
  break;
527
435
  case 'Plug':
@@ -664,7 +572,7 @@ class SwitchBotPlatform {
664
572
  this.accessories.push(accessory);
665
573
  }
666
574
  else {
667
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
575
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
668
576
  }
669
577
  }
670
578
  async createBot(device) {
@@ -718,7 +626,7 @@ class SwitchBotPlatform {
718
626
  this.accessories.push(accessory);
719
627
  }
720
628
  else {
721
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
629
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
722
630
  }
723
631
  }
724
632
  async createMeter(device) {
@@ -769,7 +677,7 @@ class SwitchBotPlatform {
769
677
  this.accessories.push(accessory);
770
678
  }
771
679
  else {
772
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
680
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
773
681
  }
774
682
  }
775
683
  async createMeterPlus(device) {
@@ -820,7 +728,7 @@ class SwitchBotPlatform {
820
728
  this.accessories.push(accessory);
821
729
  }
822
730
  else {
823
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
731
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
824
732
  }
825
733
  }
826
734
  async createMotion(device) {
@@ -871,7 +779,7 @@ class SwitchBotPlatform {
871
779
  this.accessories.push(accessory);
872
780
  }
873
781
  else {
874
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
782
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
875
783
  }
876
784
  }
877
785
  async createContact(device) {
@@ -922,7 +830,7 @@ class SwitchBotPlatform {
922
830
  this.accessories.push(accessory);
923
831
  }
924
832
  else {
925
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
833
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
926
834
  }
927
835
  }
928
836
  async createCurtain(device) {
@@ -932,7 +840,7 @@ class SwitchBotPlatform {
932
840
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
933
841
  if (existingAccessory) {
934
842
  // the accessory already exists
935
- if (this.isCurtainGrouped(device)) {
843
+ if (await this.registerDevice(device)) {
936
844
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
937
845
  existingAccessory.context.model = device.deviceType;
938
846
  existingAccessory.context.deviceID = device.deviceId;
@@ -951,7 +859,7 @@ class SwitchBotPlatform {
951
859
  this.unregisterPlatformAccessories(existingAccessory);
952
860
  }
953
861
  }
954
- else if (this.isCurtainGrouped(device)) {
862
+ else if (await this.registerDevice(device)) {
955
863
  // the accessory does not yet exist, so we need to create it
956
864
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
957
865
  if (device.group && !device.curtain?.disable_group) {
@@ -960,10 +868,10 @@ class SwitchBotPlatform {
960
868
  }
961
869
  else {
962
870
  if (device.master) {
963
- this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
871
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
964
872
  }
965
873
  else {
966
- this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
874
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
967
875
  }
968
876
  }
969
877
  // create a new accessory
@@ -985,19 +893,7 @@ class SwitchBotPlatform {
985
893
  this.accessories.push(accessory);
986
894
  }
987
895
  else {
988
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
989
- }
990
- }
991
- isCurtainGrouped(device) {
992
- this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
993
- ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
994
- if (device.group && !device.curtain?.disable_group) {
995
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
996
- return device.master && this.registerDevice(device);
997
- }
998
- else {
999
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1000
- return this.registerDevice(device);
896
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1001
897
  }
1002
898
  }
1003
899
  async createPlug(device) {
@@ -1048,7 +944,7 @@ class SwitchBotPlatform {
1048
944
  this.accessories.push(accessory);
1049
945
  }
1050
946
  else {
1051
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
947
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1052
948
  }
1053
949
  }
1054
950
  async createLock(device) {
@@ -1099,7 +995,7 @@ class SwitchBotPlatform {
1099
995
  this.accessories.push(accessory);
1100
996
  }
1101
997
  else {
1102
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
998
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1103
999
  }
1104
1000
  }
1105
1001
  async createColorBulb(device) {
@@ -1150,7 +1046,7 @@ class SwitchBotPlatform {
1150
1046
  this.accessories.push(accessory);
1151
1047
  }
1152
1048
  else {
1153
- 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}`);
1154
1050
  }
1155
1051
  }
1156
1052
  async createStripLight(device) {
@@ -1201,7 +1097,7 @@ class SwitchBotPlatform {
1201
1097
  this.accessories.push(accessory);
1202
1098
  }
1203
1099
  else {
1204
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1100
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1205
1101
  }
1206
1102
  }
1207
1103
  async createTV(device) {
@@ -1250,7 +1146,7 @@ class SwitchBotPlatform {
1250
1146
  this.accessories.push(accessory);
1251
1147
  }
1252
1148
  else {
1253
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1149
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1254
1150
  }
1255
1151
  }
1256
1152
  async createFan(device) {
@@ -1301,7 +1197,7 @@ class SwitchBotPlatform {
1301
1197
  this.accessories.push(accessory);
1302
1198
  }
1303
1199
  else {
1304
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1200
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1305
1201
  }
1306
1202
  }
1307
1203
  async createLight(device) {
@@ -1352,7 +1248,7 @@ class SwitchBotPlatform {
1352
1248
  this.accessories.push(accessory);
1353
1249
  }
1354
1250
  else {
1355
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1251
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1356
1252
  }
1357
1253
  }
1358
1254
  async createAirConditioner(device) {
@@ -1403,7 +1299,7 @@ class SwitchBotPlatform {
1403
1299
  this.accessories.push(accessory);
1404
1300
  }
1405
1301
  else {
1406
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1302
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1407
1303
  }
1408
1304
  }
1409
1305
  async createAirPurifier(device) {
@@ -1454,7 +1350,7 @@ class SwitchBotPlatform {
1454
1350
  this.accessories.push(accessory);
1455
1351
  }
1456
1352
  else {
1457
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1353
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1458
1354
  }
1459
1355
  }
1460
1356
  async createWaterHeater(device) {
@@ -1505,7 +1401,7 @@ class SwitchBotPlatform {
1505
1401
  this.accessories.push(accessory);
1506
1402
  }
1507
1403
  else {
1508
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1404
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1509
1405
  }
1510
1406
  }
1511
1407
  async createVacuumCleaner(device) {
@@ -1556,7 +1452,7 @@ class SwitchBotPlatform {
1556
1452
  this.accessories.push(accessory);
1557
1453
  }
1558
1454
  else {
1559
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1455
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1560
1456
  }
1561
1457
  }
1562
1458
  async createCamera(device) {
@@ -1607,7 +1503,7 @@ class SwitchBotPlatform {
1607
1503
  this.accessories.push(accessory);
1608
1504
  }
1609
1505
  else {
1610
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1506
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1611
1507
  }
1612
1508
  }
1613
1509
  async createOthers(device) {
@@ -1658,11 +1554,32 @@ class SwitchBotPlatform {
1658
1554
  this.accessories.push(accessory);
1659
1555
  }
1660
1556
  else {
1661
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1557
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1558
+ }
1559
+ }
1560
+ async registerCurtains(device) {
1561
+ this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1562
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1563
+ let registerCurtain;
1564
+ if (device.group && !device.curtain?.disable_group) {
1565
+ registerCurtain = true;
1566
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1567
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1568
+ }
1569
+ else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
1570
+ registerCurtain = true;
1571
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
1572
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1573
+ }
1574
+ else {
1575
+ registerCurtain = false;
1576
+ this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1577
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1662
1578
  }
1579
+ return registerCurtain;
1663
1580
  }
1664
1581
  async connectionType(device) {
1665
- let connectionType = '';
1582
+ let connectionType;
1666
1583
  if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1667
1584
  connectionType = 'OpenAPI';
1668
1585
  }
@@ -1673,38 +1590,66 @@ class SwitchBotPlatform {
1673
1590
  }
1674
1591
  async registerDevice(device) {
1675
1592
  device.connectionType = await this.connectionType(device);
1593
+ let registerDevice;
1676
1594
  if (!device.hide_device && device.enableCloudService && device.connectionType === 'BLE/OpenAPI') {
1677
- this.registeringDevice = true;
1678
- this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled, Connection Type: ${device.connectionType}`);
1595
+ if (device.deviceType === 'Curtain') {
1596
+ registerDevice = await this.registerCurtains(device);
1597
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1598
+ }
1599
+ else {
1600
+ registerDevice = true;
1601
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1602
+ }
1603
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1679
1604
  }
1680
1605
  else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1681
1606
  && device.connectionType === 'BLE') {
1682
- this.registeringDevice = true;
1683
- this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled, Connection Type: ${device.connectionType}`);
1607
+ if (device.deviceType === 'Curtain') {
1608
+ registerDevice = await this.registerCurtains(device);
1609
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1610
+ }
1611
+ else {
1612
+ registerDevice = true;
1613
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1614
+ }
1615
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1684
1616
  }
1685
1617
  else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
1686
- this.registeringDevice = true;
1687
- this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled, Connection Type: ${device.connectionType}`);
1618
+ if (device.deviceType === 'Curtain') {
1619
+ registerDevice = await this.registerCurtains(device);
1620
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1621
+ }
1622
+ else {
1623
+ registerDevice = true;
1624
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1625
+ }
1626
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1688
1627
  }
1689
- else if (!device.hide_device && device.enableCloudService && device.connectionType === 'Disable') {
1690
- this.registeringDevice = true;
1691
- this.debugLog(`Device: ${device.deviceName} Device connection Disabled, will continue to display in HomeKit,`
1692
- + ` Connection Type: ${device.connectionType}`);
1628
+ else if (!device.hide_device && device.connectionType === 'Disabled') {
1629
+ if (device.deviceType === 'Curtain') {
1630
+ registerDevice = await this.registerCurtains(device);
1631
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1632
+ }
1633
+ else {
1634
+ registerDevice = true;
1635
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1636
+ }
1637
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
1693
1638
  }
1694
- else if (!device.connectionType) {
1695
- this.registeringDevice = false;
1696
- this.errorLog(`Device: ${device.deviceName} Connection Type not Set, will not display in HomeKit, Connection Type: ${device.connectionType}`);
1639
+ else if (!device.connectionType && !device.hide_device) {
1640
+ registerDevice = false;
1641
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
1697
1642
  }
1698
1643
  else if (device.hide_device) {
1699
- this.registeringDevice = false;
1700
- this.errorLog(`Device: ${device.deviceName} Device Set to Hidden, will not display in HomeKit, hide_device: ${device.hide_device}`);
1644
+ registerDevice = false;
1645
+ this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
1701
1646
  }
1702
1647
  else {
1703
- this.registeringDevice = false;
1704
- this.errorLog(`Device: ${device.deviceName} OpenAPI or BLE Are Not Enabled, Connection Type: ${device.connectionType},`
1705
- + ` hide_device: ${device.hide_device}`);
1648
+ registerDevice = false;
1649
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
1650
+ + `${device.hide_device}, will not display in HomeKit`);
1706
1651
  }
1707
- return this.registeringDevice;
1652
+ return registerDevice;
1708
1653
  }
1709
1654
  async externalOrPlatform(device, accessory) {
1710
1655
  this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
@@ -1724,11 +1669,6 @@ class SwitchBotPlatform {
1724
1669
  this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [existingAccessory]);
1725
1670
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
1726
1671
  }
1727
- deviceListInfo(devices) {
1728
- if (this.platformLogging?.includes('debug')) {
1729
- this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
1730
- }
1731
- }
1732
1672
  async statusCode({ res }) {
1733
1673
  switch (res.statusCode) {
1734
1674
  case 151:
@@ -1774,6 +1714,27 @@ class SwitchBotPlatform {
1774
1714
  }
1775
1715
  return switchbot;
1776
1716
  }
1717
+ logs() {
1718
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
1719
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
1720
+ this.platformLogging = this.config.options.logging;
1721
+ if (this.platformLogging.includes('debug')) {
1722
+ this.log.warn(`Using Config Logging: ${this.platformLogging}`);
1723
+ }
1724
+ }
1725
+ else if (this.debugMode) {
1726
+ this.platformLogging = 'debugMode';
1727
+ if (this.platformLogging?.includes('debug')) {
1728
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1729
+ }
1730
+ }
1731
+ else {
1732
+ this.platformLogging = 'standard';
1733
+ if (this.platformLogging?.includes('debug')) {
1734
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1735
+ }
1736
+ }
1737
+ }
1777
1738
  /**
1778
1739
  * If device level logging is turned on, log to log.warn
1779
1740
  * Otherwise send debug logs to log.debug
@@ -1788,11 +1749,25 @@ class SwitchBotPlatform {
1788
1749
  this.log.warn(String(...log));
1789
1750
  }
1790
1751
  }
1752
+ debugWarnLog(...log) {
1753
+ if (this.enablingPlatfromLogging()) {
1754
+ if (this.platformLogging?.includes('debug')) {
1755
+ this.log.warn('[DEBUG]', String(...log));
1756
+ }
1757
+ }
1758
+ }
1791
1759
  errorLog(...log) {
1792
1760
  if (this.enablingPlatfromLogging()) {
1793
1761
  this.log.error(String(...log));
1794
1762
  }
1795
1763
  }
1764
+ debugErrorLog(...log) {
1765
+ if (this.enablingPlatfromLogging()) {
1766
+ if (this.platformLogging?.includes('debug')) {
1767
+ this.log.error('[DEBUG]', String(...log));
1768
+ }
1769
+ }
1770
+ }
1796
1771
  debugLog(...log) {
1797
1772
  if (this.enablingPlatfromLogging()) {
1798
1773
  if (this.platformLogging === 'debugMode') {