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

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 +148 -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 +146 -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();
@@ -430,62 +385,8 @@ class SwitchBotPlatform {
430
385
  }
431
386
  }
432
387
  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}`);
388
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
389
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
489
390
  }
490
391
  }
491
392
  createDevice(device) {
@@ -521,7 +422,7 @@ class SwitchBotPlatform {
521
422
  this.createContact(device);
522
423
  break;
523
424
  case 'Curtain':
524
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
425
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
525
426
  this.createCurtain(device);
526
427
  break;
527
428
  case 'Plug':
@@ -664,7 +565,7 @@ class SwitchBotPlatform {
664
565
  this.accessories.push(accessory);
665
566
  }
666
567
  else {
667
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
568
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
668
569
  }
669
570
  }
670
571
  async createBot(device) {
@@ -718,7 +619,7 @@ class SwitchBotPlatform {
718
619
  this.accessories.push(accessory);
719
620
  }
720
621
  else {
721
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
622
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
722
623
  }
723
624
  }
724
625
  async createMeter(device) {
@@ -769,7 +670,7 @@ class SwitchBotPlatform {
769
670
  this.accessories.push(accessory);
770
671
  }
771
672
  else {
772
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
673
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
773
674
  }
774
675
  }
775
676
  async createMeterPlus(device) {
@@ -820,7 +721,7 @@ class SwitchBotPlatform {
820
721
  this.accessories.push(accessory);
821
722
  }
822
723
  else {
823
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
724
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
824
725
  }
825
726
  }
826
727
  async createMotion(device) {
@@ -871,7 +772,7 @@ class SwitchBotPlatform {
871
772
  this.accessories.push(accessory);
872
773
  }
873
774
  else {
874
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
775
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
875
776
  }
876
777
  }
877
778
  async createContact(device) {
@@ -922,7 +823,7 @@ class SwitchBotPlatform {
922
823
  this.accessories.push(accessory);
923
824
  }
924
825
  else {
925
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
826
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
926
827
  }
927
828
  }
928
829
  async createCurtain(device) {
@@ -932,7 +833,7 @@ class SwitchBotPlatform {
932
833
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
933
834
  if (existingAccessory) {
934
835
  // the accessory already exists
935
- if (this.isCurtainGrouped(device)) {
836
+ if (await this.registerDevice(device)) {
936
837
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
937
838
  existingAccessory.context.model = device.deviceType;
938
839
  existingAccessory.context.deviceID = device.deviceId;
@@ -951,7 +852,7 @@ class SwitchBotPlatform {
951
852
  this.unregisterPlatformAccessories(existingAccessory);
952
853
  }
953
854
  }
954
- else if (this.isCurtainGrouped(device)) {
855
+ else if (await this.registerDevice(device)) {
955
856
  // the accessory does not yet exist, so we need to create it
956
857
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
957
858
  if (device.group && !device.curtain?.disable_group) {
@@ -960,10 +861,10 @@ class SwitchBotPlatform {
960
861
  }
961
862
  else {
962
863
  if (device.master) {
963
- this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
864
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
964
865
  }
965
866
  else {
966
- this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
867
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
967
868
  }
968
869
  }
969
870
  // create a new accessory
@@ -985,19 +886,7 @@ class SwitchBotPlatform {
985
886
  this.accessories.push(accessory);
986
887
  }
987
888
  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);
889
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1001
890
  }
1002
891
  }
1003
892
  async createPlug(device) {
@@ -1048,7 +937,7 @@ class SwitchBotPlatform {
1048
937
  this.accessories.push(accessory);
1049
938
  }
1050
939
  else {
1051
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
940
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1052
941
  }
1053
942
  }
1054
943
  async createLock(device) {
@@ -1099,7 +988,7 @@ class SwitchBotPlatform {
1099
988
  this.accessories.push(accessory);
1100
989
  }
1101
990
  else {
1102
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
991
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1103
992
  }
1104
993
  }
1105
994
  async createColorBulb(device) {
@@ -1150,7 +1039,7 @@ class SwitchBotPlatform {
1150
1039
  this.accessories.push(accessory);
1151
1040
  }
1152
1041
  else {
1153
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1042
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1154
1043
  }
1155
1044
  }
1156
1045
  async createStripLight(device) {
@@ -1201,7 +1090,7 @@ class SwitchBotPlatform {
1201
1090
  this.accessories.push(accessory);
1202
1091
  }
1203
1092
  else {
1204
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1093
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1205
1094
  }
1206
1095
  }
1207
1096
  async createTV(device) {
@@ -1250,7 +1139,7 @@ class SwitchBotPlatform {
1250
1139
  this.accessories.push(accessory);
1251
1140
  }
1252
1141
  else {
1253
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1142
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1254
1143
  }
1255
1144
  }
1256
1145
  async createFan(device) {
@@ -1301,7 +1190,7 @@ class SwitchBotPlatform {
1301
1190
  this.accessories.push(accessory);
1302
1191
  }
1303
1192
  else {
1304
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1193
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1305
1194
  }
1306
1195
  }
1307
1196
  async createLight(device) {
@@ -1352,7 +1241,7 @@ class SwitchBotPlatform {
1352
1241
  this.accessories.push(accessory);
1353
1242
  }
1354
1243
  else {
1355
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1244
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1356
1245
  }
1357
1246
  }
1358
1247
  async createAirConditioner(device) {
@@ -1403,7 +1292,7 @@ class SwitchBotPlatform {
1403
1292
  this.accessories.push(accessory);
1404
1293
  }
1405
1294
  else {
1406
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1295
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1407
1296
  }
1408
1297
  }
1409
1298
  async createAirPurifier(device) {
@@ -1454,7 +1343,7 @@ class SwitchBotPlatform {
1454
1343
  this.accessories.push(accessory);
1455
1344
  }
1456
1345
  else {
1457
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1346
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1458
1347
  }
1459
1348
  }
1460
1349
  async createWaterHeater(device) {
@@ -1505,7 +1394,7 @@ class SwitchBotPlatform {
1505
1394
  this.accessories.push(accessory);
1506
1395
  }
1507
1396
  else {
1508
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1397
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1509
1398
  }
1510
1399
  }
1511
1400
  async createVacuumCleaner(device) {
@@ -1556,7 +1445,7 @@ class SwitchBotPlatform {
1556
1445
  this.accessories.push(accessory);
1557
1446
  }
1558
1447
  else {
1559
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1448
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1560
1449
  }
1561
1450
  }
1562
1451
  async createCamera(device) {
@@ -1607,7 +1496,7 @@ class SwitchBotPlatform {
1607
1496
  this.accessories.push(accessory);
1608
1497
  }
1609
1498
  else {
1610
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1499
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1611
1500
  }
1612
1501
  }
1613
1502
  async createOthers(device) {
@@ -1658,11 +1547,32 @@ class SwitchBotPlatform {
1658
1547
  this.accessories.push(accessory);
1659
1548
  }
1660
1549
  else {
1661
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1550
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1551
+ }
1552
+ }
1553
+ async registerCurtains(device) {
1554
+ this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1555
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1556
+ let registerCurtain;
1557
+ if (device.group && !device.curtain?.disable_group) {
1558
+ registerCurtain = true;
1559
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1560
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1561
+ }
1562
+ else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
1563
+ registerCurtain = true;
1564
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
1565
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1566
+ }
1567
+ else {
1568
+ registerCurtain = false;
1569
+ this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1570
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1662
1571
  }
1572
+ return registerCurtain;
1663
1573
  }
1664
1574
  async connectionType(device) {
1665
- let connectionType = '';
1575
+ let connectionType;
1666
1576
  if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1667
1577
  connectionType = 'OpenAPI';
1668
1578
  }
@@ -1673,38 +1583,66 @@ class SwitchBotPlatform {
1673
1583
  }
1674
1584
  async registerDevice(device) {
1675
1585
  device.connectionType = await this.connectionType(device);
1586
+ let registerDevice;
1676
1587
  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}`);
1588
+ if (device.deviceType === 'Curtain') {
1589
+ registerDevice = await this.registerCurtains(device);
1590
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1591
+ }
1592
+ else {
1593
+ registerDevice = true;
1594
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1595
+ }
1596
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1679
1597
  }
1680
1598
  else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1681
1599
  && device.connectionType === 'BLE') {
1682
- this.registeringDevice = true;
1683
- this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled, Connection Type: ${device.connectionType}`);
1600
+ if (device.deviceType === 'Curtain') {
1601
+ registerDevice = await this.registerCurtains(device);
1602
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1603
+ }
1604
+ else {
1605
+ registerDevice = true;
1606
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1607
+ }
1608
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1684
1609
  }
1685
1610
  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}`);
1611
+ if (device.deviceType === 'Curtain') {
1612
+ registerDevice = await this.registerCurtains(device);
1613
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1614
+ }
1615
+ else {
1616
+ registerDevice = true;
1617
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1618
+ }
1619
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1688
1620
  }
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}`);
1621
+ else if (!device.hide_device && device.connectionType === 'Disabled') {
1622
+ if (device.deviceType === 'Curtain') {
1623
+ registerDevice = await this.registerCurtains(device);
1624
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1625
+ }
1626
+ else {
1627
+ registerDevice = true;
1628
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1629
+ }
1630
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
1693
1631
  }
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}`);
1632
+ else if (!device.connectionType && !device.hide_device) {
1633
+ registerDevice = false;
1634
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
1697
1635
  }
1698
1636
  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}`);
1637
+ registerDevice = false;
1638
+ this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
1701
1639
  }
1702
1640
  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}`);
1641
+ registerDevice = false;
1642
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
1643
+ + `${device.hide_device}, will not display in HomeKit`);
1706
1644
  }
1707
- return this.registeringDevice;
1645
+ return registerDevice;
1708
1646
  }
1709
1647
  async externalOrPlatform(device, accessory) {
1710
1648
  this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
@@ -1724,11 +1662,6 @@ class SwitchBotPlatform {
1724
1662
  this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [existingAccessory]);
1725
1663
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
1726
1664
  }
1727
- deviceListInfo(devices) {
1728
- if (this.platformLogging?.includes('debug')) {
1729
- this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
1730
- }
1731
- }
1732
1665
  async statusCode({ res }) {
1733
1666
  switch (res.statusCode) {
1734
1667
  case 151:
@@ -1774,6 +1707,27 @@ class SwitchBotPlatform {
1774
1707
  }
1775
1708
  return switchbot;
1776
1709
  }
1710
+ logs() {
1711
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
1712
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
1713
+ this.platformLogging = this.config.options.logging;
1714
+ if (this.platformLogging.includes('debug')) {
1715
+ this.log.warn(`Using Config Logging: ${this.platformLogging}`);
1716
+ }
1717
+ }
1718
+ else if (this.debugMode) {
1719
+ this.platformLogging = 'debugMode';
1720
+ if (this.platformLogging?.includes('debug')) {
1721
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1722
+ }
1723
+ }
1724
+ else {
1725
+ this.platformLogging = 'standard';
1726
+ if (this.platformLogging?.includes('debug')) {
1727
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1728
+ }
1729
+ }
1730
+ }
1777
1731
  /**
1778
1732
  * If device level logging is turned on, log to log.warn
1779
1733
  * Otherwise send debug logs to log.debug
@@ -1788,11 +1742,25 @@ class SwitchBotPlatform {
1788
1742
  this.log.warn(String(...log));
1789
1743
  }
1790
1744
  }
1745
+ debugWarnLog(...log) {
1746
+ if (this.enablingPlatfromLogging()) {
1747
+ if (this.platformLogging?.includes('debug')) {
1748
+ this.log.warn('[DEBUG]', String(...log));
1749
+ }
1750
+ }
1751
+ }
1791
1752
  errorLog(...log) {
1792
1753
  if (this.enablingPlatfromLogging()) {
1793
1754
  this.log.error(String(...log));
1794
1755
  }
1795
1756
  }
1757
+ debugErrorLog(...log) {
1758
+ if (this.enablingPlatfromLogging()) {
1759
+ if (this.platformLogging?.includes('debug')) {
1760
+ this.log.error('[DEBUG]', String(...log));
1761
+ }
1762
+ }
1763
+ }
1796
1764
  debugLog(...log) {
1797
1765
  if (this.enablingPlatfromLogging()) {
1798
1766
  if (this.platformLogging === 'debugMode') {