@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/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();
@@ -455,56 +408,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
455
408
  this.errorLog('Neither SwitchBot Token or Device Config are not set.');
456
409
  }
457
410
  } 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}`);
411
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
412
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
508
413
  }
509
414
  }
510
415
 
@@ -541,7 +446,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
541
446
  this.createContact(device);
542
447
  break;
543
448
  case 'Curtain':
544
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
449
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
545
450
  this.createCurtain(device);
546
451
  break;
547
452
  case 'Plug':
@@ -688,7 +593,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
688
593
  this.externalOrPlatform(device, accessory);
689
594
  this.accessories.push(accessory);
690
595
  } else {
691
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
596
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
692
597
  }
693
598
  }
694
599
 
@@ -747,7 +652,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
747
652
  this.externalOrPlatform(device, accessory);
748
653
  this.accessories.push(accessory);
749
654
  } else {
750
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
655
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
751
656
  }
752
657
  }
753
658
 
@@ -801,7 +706,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
801
706
  this.externalOrPlatform(device, accessory);
802
707
  this.accessories.push(accessory);
803
708
  } else {
804
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
709
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
805
710
  }
806
711
  }
807
712
 
@@ -855,7 +760,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
855
760
  this.externalOrPlatform(device, accessory);
856
761
  this.accessories.push(accessory);
857
762
  } else {
858
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
763
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
859
764
  }
860
765
  }
861
766
 
@@ -909,7 +814,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
909
814
  this.externalOrPlatform(device, accessory);
910
815
  this.accessories.push(accessory);
911
816
  } else {
912
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
817
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
913
818
  }
914
819
  }
915
820
 
@@ -963,7 +868,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
963
868
  this.externalOrPlatform(device, accessory);
964
869
  this.accessories.push(accessory);
965
870
  } else {
966
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
871
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
967
872
  }
968
873
  }
969
874
 
@@ -976,7 +881,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
976
881
 
977
882
  if (existingAccessory) {
978
883
  // the accessory already exists
979
- if (this.isCurtainGrouped(device)) {
884
+ if (await this.registerDevice(device)) {
980
885
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
981
886
  existingAccessory.context.model = device.deviceType;
982
887
  existingAccessory.context.deviceID = device.deviceId;
@@ -993,7 +898,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
993
898
  } else {
994
899
  this.unregisterPlatformAccessories(existingAccessory);
995
900
  }
996
- } else if (this.isCurtainGrouped(device)) {
901
+ } else if (await this.registerDevice(device)) {
997
902
  // the accessory does not yet exist, so we need to create it
998
903
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
999
904
 
@@ -1002,9 +907,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1002
907
  , Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1003
908
  } else {
1004
909
  if (device.master) {
1005
- this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
910
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1006
911
  } else {
1007
- this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
912
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1008
913
  }
1009
914
  }
1010
915
 
@@ -1028,22 +933,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1028
933
  this.externalOrPlatform(device, accessory);
1029
934
  this.accessories.push(accessory);
1030
935
  } 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);
936
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1047
937
  }
1048
938
  }
1049
939
 
@@ -1097,7 +987,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1097
987
  this.externalOrPlatform(device, accessory);
1098
988
  this.accessories.push(accessory);
1099
989
  } else {
1100
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
990
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1101
991
  }
1102
992
  }
1103
993
 
@@ -1151,7 +1041,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1151
1041
  this.externalOrPlatform(device, accessory);
1152
1042
  this.accessories.push(accessory);
1153
1043
  } else {
1154
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1044
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1155
1045
  }
1156
1046
  }
1157
1047
 
@@ -1205,7 +1095,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1205
1095
  this.externalOrPlatform(device, accessory);
1206
1096
  this.accessories.push(accessory);
1207
1097
  } else {
1208
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1098
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1209
1099
  }
1210
1100
  }
1211
1101
 
@@ -1259,7 +1149,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1259
1149
  this.externalOrPlatform(device, accessory);
1260
1150
  this.accessories.push(accessory);
1261
1151
  } else {
1262
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1152
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1263
1153
  }
1264
1154
  }
1265
1155
 
@@ -1312,7 +1202,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1312
1202
  this.externalAccessory(accessory);
1313
1203
  this.accessories.push(accessory);
1314
1204
  } else {
1315
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1205
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1316
1206
  }
1317
1207
  }
1318
1208
 
@@ -1366,7 +1256,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1366
1256
  this.externalOrPlatform(device, accessory);
1367
1257
  this.accessories.push(accessory);
1368
1258
  } else {
1369
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1259
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1370
1260
  }
1371
1261
  }
1372
1262
 
@@ -1420,7 +1310,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1420
1310
  this.externalOrPlatform(device, accessory);
1421
1311
  this.accessories.push(accessory);
1422
1312
  } else {
1423
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1313
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1424
1314
  }
1425
1315
  }
1426
1316
 
@@ -1474,7 +1364,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1474
1364
  this.externalOrPlatform(device, accessory);
1475
1365
  this.accessories.push(accessory);
1476
1366
  } else {
1477
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1367
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1478
1368
  }
1479
1369
  }
1480
1370
 
@@ -1528,7 +1418,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1528
1418
  this.externalOrPlatform(device, accessory);
1529
1419
  this.accessories.push(accessory);
1530
1420
  } else {
1531
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1421
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1532
1422
  }
1533
1423
  }
1534
1424
 
@@ -1582,7 +1472,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1582
1472
  this.externalOrPlatform(device, accessory);
1583
1473
  this.accessories.push(accessory);
1584
1474
  } else {
1585
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1475
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1586
1476
  }
1587
1477
  }
1588
1478
 
@@ -1636,7 +1526,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1636
1526
  this.externalOrPlatform(device, accessory);
1637
1527
  this.accessories.push(accessory);
1638
1528
  } else {
1639
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1529
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1640
1530
  }
1641
1531
  }
1642
1532
 
@@ -1690,7 +1580,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1690
1580
  this.externalOrPlatform(device, accessory);
1691
1581
  this.accessories.push(accessory);
1692
1582
  } else {
1693
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1583
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1694
1584
  }
1695
1585
  }
1696
1586
 
@@ -1744,12 +1634,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1744
1634
  this.externalOrPlatform(device, accessory);
1745
1635
  this.accessories.push(accessory);
1746
1636
  } else {
1747
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1637
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1748
1638
  }
1749
1639
  }
1750
1640
 
1641
+ async registerCurtains(device: device & devicesConfig) {
1642
+ this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1643
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1644
+
1645
+ let registerCurtain: boolean;
1646
+ if (device.group && !device.curtain?.disable_group) {
1647
+ registerCurtain = true;
1648
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1649
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1650
+ } else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
1651
+ registerCurtain = true;
1652
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
1653
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1654
+ } else {
1655
+ registerCurtain = false;
1656
+ this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1657
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1658
+ }
1659
+ return registerCurtain;
1660
+ }
1661
+
1751
1662
  async connectionType(device: device & devicesConfig): Promise<any> {
1752
- let connectionType = '';
1663
+ let connectionType: string;
1753
1664
  if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1754
1665
  connectionType = 'OpenAPI';
1755
1666
  } else {
@@ -1760,32 +1671,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1760
1671
 
1761
1672
  async registerDevice(device: device & devicesConfig) {
1762
1673
  device.connectionType = await this.connectionType(device);
1674
+ let registerDevice: boolean;
1763
1675
  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}`);
1676
+ if (device.deviceType === 'Curtain') {
1677
+ registerDevice = await this.registerCurtains(device);
1678
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1679
+ } else {
1680
+ registerDevice = true;
1681
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1682
+ }
1683
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1766
1684
  } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1767
1685
  && device.connectionType === 'BLE') {
1768
- this.registeringDevice = true;
1769
- this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled, Connection Type: ${device.connectionType}`);
1686
+ if (device.deviceType === 'Curtain') {
1687
+ registerDevice = await this.registerCurtains(device);
1688
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1689
+ } else {
1690
+ registerDevice = true;
1691
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1692
+ }
1693
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1770
1694
  } 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}`);
1695
+ if (device.deviceType === 'Curtain') {
1696
+ registerDevice = await this.registerCurtains(device);
1697
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1698
+ } else {
1699
+ registerDevice = true;
1700
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1701
+ }
1702
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1703
+ } else if (!device.hide_device && device.connectionType === 'Disabled') {
1704
+ if (device.deviceType === 'Curtain') {
1705
+ registerDevice = await this.registerCurtains(device);
1706
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1707
+ } else {
1708
+ registerDevice = true;
1709
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1710
+ }
1711
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
1712
+ } else if (!device.connectionType && !device.hide_device) {
1713
+ registerDevice = false;
1714
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
1780
1715
  } 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}`);
1716
+ registerDevice = false;
1717
+ this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
1783
1718
  } 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}`);
1719
+ registerDevice = false;
1720
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
1721
+ + `${device.hide_device}, will not display in HomeKit`);
1787
1722
  }
1788
- return this.registeringDevice;
1723
+ return registerDevice;
1789
1724
  }
1790
1725
 
1791
1726
  public async externalOrPlatform(device: device & devicesConfig, accessory: PlatformAccessory) {
@@ -1808,12 +1743,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1808
1743
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
1809
1744
  }
1810
1745
 
1811
- public deviceListInfo(devices) {
1812
- if (this.platformLogging?.includes('debug')) {
1813
- this.warnLog(`deviceListInfoStatus: ${superStringify(devices)}`);
1814
- }
1815
- }
1816
-
1817
1746
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
1818
1747
  switch (res.statusCode) {
1819
1748
  case 151:
@@ -1860,6 +1789,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1860
1789
  return switchbot;
1861
1790
  }
1862
1791
 
1792
+ logs() {
1793
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
1794
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
1795
+ this.platformLogging = this.config.options!.logging;
1796
+ if (this.platformLogging.includes('debug')) {
1797
+ this.log.warn(`Using Config Logging: ${this.platformLogging}`);
1798
+ }
1799
+ } else if (this.debugMode) {
1800
+ this.platformLogging = 'debugMode';
1801
+ if (this.platformLogging?.includes('debug')) {
1802
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1803
+ }
1804
+ } else {
1805
+ this.platformLogging = 'standard';
1806
+ if (this.platformLogging?.includes('debug')) {
1807
+ this.log.warn(`Using ${this.platformLogging} Logging`);
1808
+ }
1809
+ }
1810
+ }
1811
+
1863
1812
  /**
1864
1813
  * If device level logging is turned on, log to log.warn
1865
1814
  * Otherwise send debug logs to log.debug
@@ -1876,12 +1825,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1876
1825
  }
1877
1826
  }
1878
1827
 
1828
+ debugWarnLog(...log: any[]): void {
1829
+ if (this.enablingPlatfromLogging()) {
1830
+ if (this.platformLogging?.includes('debug')) {
1831
+ this.log.warn('[DEBUG]', String(...log));
1832
+ }
1833
+ }
1834
+ }
1835
+
1879
1836
  errorLog(...log: any[]): void {
1880
1837
  if (this.enablingPlatfromLogging()) {
1881
1838
  this.log.error(String(...log));
1882
1839
  }
1883
1840
  }
1884
1841
 
1842
+ debugErrorLog(...log: any[]): void {
1843
+ if (this.enablingPlatfromLogging()) {
1844
+ if (this.platformLogging?.includes('debug')) {
1845
+ this.log.error('[DEBUG]', String(...log));
1846
+ }
1847
+ }
1848
+ }
1849
+
1885
1850
  debugLog(...log: any[]): void {
1886
1851
  if (this.enablingPlatfromLogging()) {
1887
1852
  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