@switchbot/homebridge-switchbot 2.0.0-beta.4 → 2.0.0-beta.40

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 (119) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/README.md +3 -2
  3. package/config.schema.json +108 -20
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -19
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +486 -309
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +15 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +574 -454
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +21 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +13 -11
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +490 -344
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +282 -241
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +567 -476
  119. package/src/settings.ts +22 -11
package/dist/platform.js CHANGED
@@ -13,6 +13,7 @@ const contact_1 = require("./device/contact");
13
13
  const curtain_1 = require("./device/curtain");
14
14
  const meterplus_1 = require("./device/meterplus");
15
15
  const colorbulb_1 = require("./device/colorbulb");
16
+ const ceilinglight_1 = require("./device/ceilinglight");
16
17
  const striplight_1 = require("./device/striplight");
17
18
  const humidifier_1 = require("./device/humidifier");
18
19
  const tv_1 = require("./irdevice/tv");
@@ -28,6 +29,7 @@ const https_1 = __importDefault(require("https"));
28
29
  const crypto_1 = __importDefault(require("crypto"));
29
30
  const buffer_1 = require("buffer");
30
31
  const fakegato_history_1 = __importDefault(require("fakegato-history"));
32
+ const super_stringify_1 = __importDefault(require("super-stringify"));
31
33
  const fs_1 = require("fs");
32
34
  const settings_1 = require("./settings");
33
35
  /**
@@ -61,10 +63,8 @@ class SwitchBotPlatform {
61
63
  this.debugLog('Config OK');
62
64
  }
63
65
  catch (e) {
64
- this.errorLog(JSON.stringify(e.message));
65
- if (this.platformLogging?.includes('debug')) {
66
- this.errorLog(JSON.stringify(e));
67
- }
66
+ this.errorLog(`Verify Config, Error Message: ${e.message}`);
67
+ this.debugErrorLog(`Verify Config, Error: ${e}`);
68
68
  return;
69
69
  }
70
70
  // import fakegato-history module
@@ -80,39 +80,20 @@ class SwitchBotPlatform {
80
80
  if (this.config.credentials?.openToken && !this.config.credentials.token) {
81
81
  await this.updateToken();
82
82
  }
83
+ else if (this.config.credentials?.token && !this.config.credentials?.secret) {
84
+ // eslint-disable-next-line no-useless-escape
85
+ this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
86
+ }
83
87
  else {
84
88
  this.discoverDevices();
85
89
  }
86
90
  }
87
91
  catch (e) {
88
- this.errorLog('Failed to Discover Devices.', JSON.stringify(e.message));
89
- if (this.platformLogging?.includes('debug')) {
90
- this.errorLog(JSON.stringify(e));
91
- }
92
+ this.errorLog(`Failed to Discover, Error Message: ${e.message}`);
93
+ this.debugErrorLog(`Failed to Discover, Error: ${e}`);
92
94
  }
93
95
  });
94
96
  }
95
- logs() {
96
- this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
97
- if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
98
- this.platformLogging = this.config.options.logging;
99
- if (this.platformLogging.includes('debug')) {
100
- this.log.warn(`Using Config Logging: ${this.platformLogging}`);
101
- }
102
- }
103
- else if (this.debugMode) {
104
- this.platformLogging = 'debugMode';
105
- if (this.platformLogging?.includes('debug')) {
106
- this.log.warn(`Using ${this.platformLogging} Logging`);
107
- }
108
- }
109
- else {
110
- this.platformLogging = 'standard';
111
- if (this.platformLogging?.includes('debug')) {
112
- this.log.warn(`Using ${this.platformLogging} Logging`);
113
- }
114
- }
115
- }
116
97
  /**
117
98
  * This function is invoked when homebridge restores cached accessories from disk at startup.
118
99
  * It should be used to setup event handlers for characteristics and update respective values.
@@ -131,14 +112,14 @@ class SwitchBotPlatform {
131
112
  if (this.config.options.logging) {
132
113
  platformConfig['logging'] = this.config.options.logging;
133
114
  }
134
- if (this.config.options.logging) {
115
+ if (this.config.options.logging && this.config.options.refreshRate) {
135
116
  platformConfig['refreshRate'] = this.config.options.refreshRate;
136
117
  }
137
- if (this.config.options.logging) {
118
+ if (this.config.options.logging && this.config.options.pushRate) {
138
119
  platformConfig['pushRate'] = this.config.options.pushRate;
139
120
  }
140
121
  if (Object.entries(platformConfig).length !== 0) {
141
- this.infoLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
122
+ this.infoLog(`Platform Config: ${(0, super_stringify_1.default)(platformConfig)}`);
142
123
  }
143
124
  if (this.config.options) {
144
125
  // Device Config
@@ -148,7 +129,7 @@ class SwitchBotPlatform {
148
129
  if (!deviceConfig.deviceId) {
149
130
  throw new Error('The devices config section is missing the *Device ID* in the config. Please check your config.');
150
131
  }
151
- if (!deviceConfig.configDeviceType && deviceConfig.ble) {
132
+ if (!deviceConfig.configDeviceType && deviceConfig.connectionType) {
152
133
  throw new Error('The devices config section is missing the *Device Type* in the config. Please check your config.');
153
134
  }
154
135
  }
@@ -174,34 +155,25 @@ class SwitchBotPlatform {
174
155
  if (!this.config.options.refreshRate) {
175
156
  // default 120 seconds (2 minutes)
176
157
  this.config.options.refreshRate = 120;
177
- if (this.platformLogging?.includes('debug')) {
178
- this.debugLog('Using Default Refresh Rate (2 minutes).');
179
- }
180
- if (!this.config.options.pushRate) {
181
- // default 100 milliseconds
182
- this.config.options.pushRate = 0.1;
183
- if (this.platformLogging?.includes('debug')) {
184
- this.warnLog('Using Default Push Rate.');
185
- }
186
- }
187
- if (!this.config.credentials) {
188
- if (this.platformLogging?.includes('debug')) {
189
- this.debugLog('Missing Credentials');
190
- }
191
- }
158
+ this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
159
+ }
160
+ if (!this.config.options.pushRate) {
161
+ // default 100 milliseconds
162
+ this.config.options.pushRate = 0.1;
163
+ this.debugWarnLog('Using Default Push Rate.');
164
+ }
165
+ if (!this.config.credentials && !this.config.options) {
166
+ this.debugWarnLog('Missing Credentials');
167
+ }
168
+ else if (this.config.credentials && !this.config.credentials.notice) {
192
169
  if (!this.config.credentials?.token) {
193
- if (this.platformLogging?.includes('debug')) {
194
- this.errorLog('Missing token');
195
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
196
- }
170
+ this.debugErrorLog('Missing token');
171
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
197
172
  }
198
173
  if (this.config.credentials?.token) {
199
174
  if (!this.config.credentials?.secret) {
200
- if (this.platformLogging?.includes('debug')) {
201
- this.errorLog('Missing secret');
202
- this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
203
- }
204
- throw Error('Missing secret');
175
+ this.debugErrorLog('Missing secret');
176
+ this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
205
177
  }
206
178
  }
207
179
  }
@@ -233,20 +205,26 @@ class SwitchBotPlatform {
233
205
  throw new Error('pluginConfig.credentials is not an object');
234
206
  }
235
207
  // Move openToken to token
236
- this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken.');
237
- this.warnLog('`openToken` config has been moved to the `token` config, Please restart Homebridge.');
208
+ if (!this.config.credentials.secret) {
209
+ // eslint-disable-next-line no-useless-escape, max-len
210
+ this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, \"openToken\" cconfig has been moved to the \"token\" config');
211
+ // eslint-disable-next-line no-useless-escape
212
+ this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
213
+ }
214
+ else {
215
+ // eslint-disable-next-line no-useless-escape, max-len
216
+ this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, \"openToken\" config has been moved to the \"token\" config, please restart Homebridge.');
217
+ }
238
218
  // set the refresh token
239
219
  pluginConfig.credentials.token = this.config.credentials?.openToken;
240
220
  pluginConfig.credentials.openToken = 'Delete';
241
- if (this.platformLogging?.includes('debug')) {
242
- this.warnLog(`Token: ${pluginConfig.credentials.token}`);
243
- }
221
+ this.debugWarnLog(`Token: ${pluginConfig.credentials.token}`);
244
222
  // save the config, ensuring we maintain pretty json
245
223
  (0, fs_1.writeFileSync)(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
246
224
  this.verifyConfig();
247
225
  }
248
226
  catch (e) {
249
- this.errorLog(e);
227
+ this.errorLog(`Update Token: ${e}`);
250
228
  }
251
229
  }
252
230
  /**
@@ -274,104 +252,132 @@ class SwitchBotPlatform {
274
252
  'Content-Type': 'application/json',
275
253
  },
276
254
  };
277
- const req = https_1.default.request(options, (res) => {
255
+ const req = https_1.default.request(options, async (res) => {
278
256
  this.debugLog(`statusCode: ${res.statusCode}`);
279
- this.debugLog(`headers: ${JSON.stringify(res.headers)}`);
257
+ await this.statusCode({ res });
258
+ this.debugLog(`headers: ${(0, super_stringify_1.default)(res.headers)}`);
280
259
  let rawData = '';
281
260
  res.on('data', (d) => {
282
261
  rawData += d;
262
+ this.deviceStatus = d;
283
263
  this.debugLog(`d: ${d}`);
284
264
  });
285
265
  res.on('end', () => {
286
266
  try {
287
267
  const devicesAPI = JSON.parse(rawData);
288
- this.debugLog(`devicesAPI: ${JSON.stringify(devicesAPI.body)}`);
268
+ this.debugLog(`devicesAPI: ${(0, super_stringify_1.default)(devicesAPI.body)}`);
289
269
  // SwitchBot Devices
290
- if (devicesAPI.body.deviceList.length !== 0) {
291
- this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
292
- }
293
- else {
294
- this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
295
- }
296
- const deviceLists = devicesAPI.body.deviceList;
297
- if (!this.config.options?.devices) {
298
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
299
- const devices = deviceLists.map((v) => v);
300
- for (const device of devices) {
301
- if (device.deviceType) {
302
- if (device.configDeviceName) {
303
- device.deviceName = device.configDeviceName;
270
+ /*if (devicesAPI.body.deviceList.length !== 0) {
271
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
272
+ } else {
273
+ this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
274
+ }*/
275
+ const deviceBodyList = devicesAPI.body.deviceList;
276
+ let deviceLists;
277
+ if (deviceBodyList) {
278
+ if (deviceBodyList.length > 1) {
279
+ deviceLists = deviceBodyList;
280
+ this.infoLog(`Total SwitchBot Devices Found: ${deviceLists.length}`);
281
+ }
282
+ else {
283
+ deviceLists = [deviceBodyList];
284
+ this.infoLog(`Total SwitchBot Devices Found: ${deviceLists.length}`);
285
+ }
286
+ if (!this.config.options?.devices) {
287
+ this.debugLog(`SwitchBot Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
288
+ const devices = deviceLists.map((v) => v);
289
+ for (const device of devices) {
290
+ if (device.deviceType) {
291
+ if (device.configDeviceName) {
292
+ device.deviceName = device.configDeviceName;
293
+ }
294
+ this.createDevice(device);
304
295
  }
305
- this.createDevice(device);
306
296
  }
307
297
  }
308
- }
309
- else if (this.config.credentials?.token && this.config.options.devices) {
310
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
311
- const deviceConfigs = this.config.options?.devices;
312
- const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
313
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
314
- ...itm,
315
- }));
316
- const devices = mergeBydeviceId(deviceLists, deviceConfigs);
317
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
318
- for (const device of devices) {
319
- if (device.deviceType) {
320
- if (device.configDeviceName) {
321
- device.deviceName = device.configDeviceName;
298
+ else if (this.config.credentials?.token && this.config.options.devices) {
299
+ this.debugLog(`SwitchBot Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
300
+ const deviceConfigs = this.config.options?.devices;
301
+ const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
302
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
303
+ ...itm,
304
+ }));
305
+ const devices = mergeBydeviceId(deviceLists, deviceConfigs);
306
+ this.debugLog(`SwitchBot Devices: ${(0, super_stringify_1.default)(devices)}`);
307
+ for (const device of devices) {
308
+ if (device.deviceType) {
309
+ if (device.configDeviceName) {
310
+ device.deviceName = device.configDeviceName;
311
+ }
312
+ this.createDevice(device);
322
313
  }
323
- this.createDevice(device);
324
314
  }
325
315
  }
316
+ else {
317
+ this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
318
+ }
326
319
  }
327
320
  else {
328
- this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
321
+ this.errorLog(`SwitchBot Device Request Issue: ${this.deviceStatus}`);
329
322
  }
330
323
  // IR Devices
331
- if (devicesAPI.body.infraredRemoteList.length !== 0) {
332
- this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
333
- }
334
- else {
335
- this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
336
- }
337
- const irDeviceLists = devicesAPI.body.infraredRemoteList;
338
- if (!this.config.options?.irdevices) {
339
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
340
- const devices = irDeviceLists.map((v) => v);
341
- for (const device of devices) {
342
- if (device.remoteType) {
343
- this.createIRDevice(device);
324
+ /*if (devicesAPI.body.infraredRemoteList.length !== 0) {
325
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
326
+ } else {
327
+ this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
328
+ }*/
329
+ const irDeviceBodyList = devicesAPI.body.infraredRemoteList;
330
+ let irDeviceLists;
331
+ if (irDeviceBodyList) {
332
+ if (irDeviceBodyList.length > 1) {
333
+ irDeviceLists = irDeviceBodyList;
334
+ this.infoLog(`Total IR Devices Found: ${irDeviceLists.length}`);
335
+ }
336
+ else {
337
+ irDeviceLists = [irDeviceBodyList];
338
+ this.infoLog(`Total IR Devices Found: ${irDeviceLists.length}`);
339
+ }
340
+ if (!this.config.options?.irdevices) {
341
+ this.debugLog(`IR Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
342
+ const devices = irDeviceLists.map((v) => v);
343
+ for (const device of devices) {
344
+ if (device.remoteType) {
345
+ this.createIRDevice(device);
346
+ }
344
347
  }
345
348
  }
346
- }
347
- else {
348
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
349
- const irDeviceConfig = this.config.options?.irdevices;
350
- const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
351
- ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
352
- ...itm,
353
- }));
354
- const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
355
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
356
- for (const device of devices) {
357
- if (device.remoteType) {
358
- this.createIRDevice(device);
349
+ else {
350
+ this.debugLog(`IR Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
351
+ const irDeviceConfig = this.config.options?.irdevices;
352
+ const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
353
+ ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
354
+ ...itm,
355
+ }));
356
+ const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
357
+ this.debugLog(`IR Devices: ${(0, super_stringify_1.default)(devices)}`);
358
+ for (const device of devices) {
359
+ if (device.remoteType) {
360
+ this.createIRDevice(device);
361
+ }
359
362
  }
360
363
  }
361
364
  }
365
+ else {
366
+ this.errorLog(`SwitchBot IR Device Request Issue: ${this.deviceStatus}`);
367
+ }
362
368
  }
363
369
  catch (e) {
364
- this.errorLog(e.message);
370
+ this.errorLog(`API Request: ${e}`);
365
371
  }
366
372
  });
367
373
  });
368
- req.on('error', (error) => {
369
- this.errorLog(error);
374
+ req.on('error', (e) => {
375
+ this.errorLog(`req: ${e}`);
370
376
  });
371
377
  req.end();
372
378
  }
373
379
  else if (!this.config.credentials?.token && this.config.options?.devices) {
374
- this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
380
+ this.debugLog(`SwitchBot Device Manual Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
375
381
  const deviceConfigs = this.config.options?.devices;
376
382
  const devices = deviceConfigs.map((v) => v);
377
383
  for (const device of devices) {
@@ -387,55 +393,8 @@ class SwitchBotPlatform {
387
393
  }
388
394
  }
389
395
  catch (e) {
390
- this.deviceError(e);
391
- }
392
- }
393
- deviceError(e) {
394
- if (e.message.includes('400')) {
395
- this.errorLog('Failed to Discover Devices: Bad Request');
396
- this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
397
- }
398
- else if (e.message.includes('401')) {
399
- this.errorLog('Failed to Discover Devices: Unauthorized Request');
400
- this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
401
- }
402
- else if (e.message.includes('403')) {
403
- this.errorLog('Failed to Discover Devices: Forbidden Request');
404
- this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
405
- }
406
- else if (e.message.includes('404')) {
407
- this.errorLog('Failed to Discover Devices: Requst Not Found');
408
- this.debugLog('Specifies the requested path does not exist.');
409
- }
410
- else if (e.message.includes('406')) {
411
- this.errorLog('Failed to Discover Devices: Request Not Acceptable');
412
- this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
413
- }
414
- else if (e.message.includes('415')) {
415
- this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
416
- this.debugLog('The client has defined a contentType header that is not supported by the server.');
417
- }
418
- else if (e.message.includes('422')) {
419
- this.errorLog('Failed to Discover Devices: Unprocessable Entity');
420
- this.debugLog('The client has made a valid request, but the server cannot process it.' +
421
- ' This is often used for APIs for which certain limits have been exceeded.');
422
- }
423
- else if (e.message.includes('429')) {
424
- this.errorLog('Failed to Discover Devices: Too Many Requests');
425
- this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
426
- }
427
- else if (e.message.includes('500')) {
428
- this.errorLog('Failed to Discover Devices: Internal Server Error');
429
- this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
430
- }
431
- else {
432
- this.errorLog('Failed to Discover Devices');
433
- }
434
- if (this.platformLogging === 'debug') {
435
- this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
436
- }
437
- if (this.platformLogging === 'debugMode') {
438
- this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
396
+ this.debugErrorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
397
+ this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
439
398
  }
440
399
  }
441
400
  createDevice(device) {
@@ -471,7 +430,7 @@ class SwitchBotPlatform {
471
430
  this.createContact(device);
472
431
  break;
473
432
  case 'Curtain':
474
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
433
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
475
434
  this.createCurtain(device);
476
435
  break;
477
436
  case 'Plug':
@@ -488,12 +447,15 @@ class SwitchBotPlatform {
488
447
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
489
448
  this.createColorBulb(device);
490
449
  break;
450
+ case 'Ceiling Light':
451
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
452
+ this.createCeilingLight(device);
453
+ break;
491
454
  case 'Strip Light':
492
455
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
493
456
  this.createStripLight(device);
494
457
  break;
495
458
  case 'Indoor Cam':
496
- this.deviceInfo(device);
497
459
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
498
460
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
499
461
  break;
@@ -501,7 +463,6 @@ class SwitchBotPlatform {
501
463
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
502
464
  break;
503
465
  default:
504
- this.deviceInfo(device);
505
466
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
506
467
  this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
507
468
  }
@@ -563,30 +524,11 @@ class SwitchBotPlatform {
563
524
  this.createOthers(device);
564
525
  break;
565
526
  default:
566
- this.deviceInfo(device);
527
+ this.debugLog(`Unsupported Device: ${(0, super_stringify_1.default)(device)}`);
567
528
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
568
529
  this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
569
530
  }
570
531
  }
571
- registerDevice(device) {
572
- if (!device.hide_device && device.enableCloudService && device.ble) {
573
- this.registeringDevice = true;
574
- this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
575
- }
576
- else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && !device.enableCloudService) {
577
- this.registeringDevice = true;
578
- this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
579
- }
580
- else if (!device.hide_device && device.enableCloudService && !device.ble) {
581
- this.registeringDevice = true;
582
- this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
583
- }
584
- else {
585
- this.registeringDevice = false;
586
- this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
587
- }
588
- return this.registeringDevice;
589
- }
590
532
  async createHumidifier(device) {
591
533
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
592
534
  // see if an accessory with the same uuid has already been registered and restored from
@@ -594,16 +536,15 @@ class SwitchBotPlatform {
594
536
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
595
537
  if (existingAccessory) {
596
538
  // the accessory already exists
597
- if (this.registerDevice(device)) {
598
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
539
+ if (await this.registerDevice(device)) {
599
540
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
600
- //existingAccessory.context.firmwareRevision = firmware;
601
541
  existingAccessory.context.model = device.deviceType;
602
542
  existingAccessory.context.deviceID = device.deviceId;
603
- existingAccessory.displayName = device.deviceName;
543
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
604
544
  existingAccessory.context.firmwareRevision = device.firmware;
605
545
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
606
- await this.connectionTypeExistingAccessory(device, existingAccessory);
546
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
547
+ existingAccessory.context.connectionType = await this.connectionType(device);
607
548
  this.api.updatePlatformAccessories([existingAccessory]);
608
549
  // create the accessory handler for the restored accessory
609
550
  // this is imported from `platformAccessory.ts`
@@ -614,9 +555,11 @@ class SwitchBotPlatform {
614
555
  this.unregisterPlatformAccessories(existingAccessory);
615
556
  }
616
557
  }
617
- else if (this.registerDevice(device)) {
558
+ else if (await this.registerDevice(device)) {
618
559
  // the accessory does not yet exist, so we need to create it
619
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
560
+ if (!device.external) {
561
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
562
+ }
620
563
  // create a new accessory
621
564
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
622
565
  // store a copy of the device object in the `accessory.context`
@@ -626,17 +569,17 @@ class SwitchBotPlatform {
626
569
  accessory.context.deviceID = device.deviceId;
627
570
  accessory.context.firmwareRevision = device.firmware;
628
571
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
629
- await this.connectionTypeNewAccessory(device, accessory);
572
+ accessory.context.connectionType = await this.connectionType(device);
630
573
  // create the accessory handler for the newly create accessory
631
574
  // this is imported from `platformAccessory.ts`
632
575
  new humidifier_1.Humidifier(this, accessory, device);
633
576
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
634
- // link the accessory to your platform
635
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
577
+ // publish device externally or link the accessory to your platform
578
+ this.externalOrPlatform(device, accessory);
636
579
  this.accessories.push(accessory);
637
580
  }
638
581
  else {
639
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
582
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
640
583
  }
641
584
  }
642
585
  async createBot(device) {
@@ -646,16 +589,16 @@ class SwitchBotPlatform {
646
589
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
647
590
  if (existingAccessory) {
648
591
  // the accessory already exists
649
- if (this.registerDevice(device)) {
650
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
651
- this.debugLog(JSON.stringify(device.bot?.mode));
592
+ if (await this.registerDevice(device)) {
593
+ this.debugLog((0, super_stringify_1.default)(device.bot?.mode));
652
594
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
653
595
  existingAccessory.context.model = device.deviceType;
654
596
  existingAccessory.context.deviceID = device.deviceId;
655
- existingAccessory.displayName = device.deviceName;
597
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
656
598
  existingAccessory.context.firmwareRevision = device.firmware;
657
599
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
658
- await this.connectionTypeExistingAccessory(device, existingAccessory);
600
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
601
+ existingAccessory.context.connectionType = await this.connectionType(device);
659
602
  this.api.updatePlatformAccessories([existingAccessory]);
660
603
  // create the accessory handler for the restored accessory
661
604
  // this is imported from `platformAccessory.ts`
@@ -666,10 +609,12 @@ class SwitchBotPlatform {
666
609
  this.unregisterPlatformAccessories(existingAccessory);
667
610
  }
668
611
  }
669
- else if (this.registerDevice(device)) {
612
+ else if (await this.registerDevice(device)) {
670
613
  // the accessory does not yet exist, so we need to create it
671
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
672
- this.debugLog(JSON.stringify(device.bot?.mode));
614
+ if (!device.external) {
615
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
616
+ }
617
+ this.debugLog((0, super_stringify_1.default)(device.bot?.mode));
673
618
  // create a new accessory
674
619
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
675
620
  // store a copy of the device object in the `accessory.context`
@@ -679,18 +624,18 @@ class SwitchBotPlatform {
679
624
  accessory.context.deviceID = device.deviceId;
680
625
  accessory.context.firmwareRevision = device.firmware;
681
626
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
682
- await this.connectionTypeNewAccessory(device, accessory);
627
+ accessory.context.connectionType = await this.connectionType(device);
683
628
  // accessory.context.firmwareRevision = findaccessories.accessoryAttribute.softwareRevision;
684
629
  // create the accessory handler for the newly create accessory
685
630
  // this is imported from `platformAccessory.ts`
686
631
  new bot_1.Bot(this, accessory, device);
687
632
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
688
- // link the accessory to your platform
689
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
633
+ // publish device externally or link the accessory to your platform
634
+ this.externalOrPlatform(device, accessory);
690
635
  this.accessories.push(accessory);
691
636
  }
692
637
  else {
693
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
638
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
694
639
  }
695
640
  }
696
641
  async createMeter(device) {
@@ -700,15 +645,15 @@ class SwitchBotPlatform {
700
645
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
701
646
  if (existingAccessory) {
702
647
  // the accessory already exists
703
- if (this.registerDevice(device)) {
704
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
648
+ if (await this.registerDevice(device)) {
705
649
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
706
650
  existingAccessory.context.model = device.deviceType;
707
651
  existingAccessory.context.deviceID = device.deviceId;
708
- existingAccessory.displayName = device.deviceName;
652
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
709
653
  existingAccessory.context.firmwareRevision = device.firmware;
710
654
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
711
- await this.connectionTypeExistingAccessory(device, existingAccessory);
655
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
656
+ existingAccessory.context.connectionType = await this.connectionType(device);
712
657
  this.api.updatePlatformAccessories([existingAccessory]);
713
658
  // create the accessory handler for the restored accessory
714
659
  // this is imported from `platformAccessory.ts`
@@ -719,9 +664,11 @@ class SwitchBotPlatform {
719
664
  this.unregisterPlatformAccessories(existingAccessory);
720
665
  }
721
666
  }
722
- else if (this.registerDevice(device)) {
667
+ else if (await this.registerDevice(device)) {
723
668
  // the accessory does not yet exist, so we need to create it
724
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
669
+ if (!device.external) {
670
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
671
+ }
725
672
  // create a new accessory
726
673
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
727
674
  // store a copy of the device object in the `accessory.context`
@@ -731,17 +678,17 @@ class SwitchBotPlatform {
731
678
  accessory.context.deviceID = device.deviceId;
732
679
  accessory.context.firmwareRevision = device.firmware;
733
680
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
734
- await this.connectionTypeNewAccessory(device, accessory);
681
+ accessory.context.connectionType = await this.connectionType(device);
735
682
  // create the accessory handler for the newly create accessory
736
683
  // this is imported from `platformAccessory.ts`
737
684
  new meter_1.Meter(this, accessory, device);
738
685
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
739
- // link the accessory to your platform
740
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
686
+ // publish device externally or link the accessory to your platform
687
+ this.externalOrPlatform(device, accessory);
741
688
  this.accessories.push(accessory);
742
689
  }
743
690
  else {
744
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
691
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
745
692
  }
746
693
  }
747
694
  async createMeterPlus(device) {
@@ -751,15 +698,15 @@ class SwitchBotPlatform {
751
698
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
752
699
  if (existingAccessory) {
753
700
  // the accessory already exists
754
- if (this.registerDevice(device)) {
755
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
701
+ if (await this.registerDevice(device)) {
756
702
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
757
703
  existingAccessory.context.model = device.deviceType;
758
704
  existingAccessory.context.deviceID = device.deviceId;
759
- existingAccessory.displayName = device.deviceName;
705
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
760
706
  existingAccessory.context.firmwareRevision = device.firmware;
761
707
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
762
- await this.connectionTypeExistingAccessory(device, existingAccessory);
708
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
709
+ existingAccessory.context.connectionType = await this.connectionType(device);
763
710
  this.api.updatePlatformAccessories([existingAccessory]);
764
711
  // create the accessory handler for the restored accessory
765
712
  // this is imported from `platformAccessory.ts`
@@ -770,9 +717,11 @@ class SwitchBotPlatform {
770
717
  this.unregisterPlatformAccessories(existingAccessory);
771
718
  }
772
719
  }
773
- else if (this.registerDevice(device)) {
720
+ else if (await this.registerDevice(device)) {
774
721
  // the accessory does not yet exist, so we need to create it
775
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
722
+ if (!device.external) {
723
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
724
+ }
776
725
  // create a new accessory
777
726
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
778
727
  // store a copy of the device object in the `accessory.context`
@@ -782,17 +731,17 @@ class SwitchBotPlatform {
782
731
  accessory.context.deviceID = device.deviceId;
783
732
  accessory.context.firmwareRevision = device.firmware;
784
733
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
785
- await this.connectionTypeNewAccessory(device, accessory);
734
+ accessory.context.connectionType = await this.connectionType(device);
786
735
  // create the accessory handler for the newly create accessory
787
736
  // this is imported from `platformAccessory.ts`
788
737
  new meterplus_1.MeterPlus(this, accessory, device);
789
738
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
790
- // link the accessory to your platform
791
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
739
+ // publish device externally or link the accessory to your platform
740
+ this.externalOrPlatform(device, accessory);
792
741
  this.accessories.push(accessory);
793
742
  }
794
743
  else {
795
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
744
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
796
745
  }
797
746
  }
798
747
  async createMotion(device) {
@@ -802,15 +751,15 @@ class SwitchBotPlatform {
802
751
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
803
752
  if (existingAccessory) {
804
753
  // the accessory already exists
805
- if (this.registerDevice(device)) {
806
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
754
+ if (await this.registerDevice(device)) {
807
755
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
808
756
  existingAccessory.context.model = device.deviceType;
809
757
  existingAccessory.context.deviceID = device.deviceId;
810
- existingAccessory.displayName = device.deviceName;
758
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
811
759
  existingAccessory.context.firmwareRevision = device.firmware;
812
760
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
813
- await this.connectionTypeExistingAccessory(device, existingAccessory);
761
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
762
+ existingAccessory.context.connectionType = await this.connectionType(device);
814
763
  this.api.updatePlatformAccessories([existingAccessory]);
815
764
  // create the accessory handler for the restored accessory
816
765
  // this is imported from `platformAccessory.ts`
@@ -821,9 +770,11 @@ class SwitchBotPlatform {
821
770
  this.unregisterPlatformAccessories(existingAccessory);
822
771
  }
823
772
  }
824
- else if (this.registerDevice(device)) {
773
+ else if (await this.registerDevice(device)) {
825
774
  // the accessory does not yet exist, so we need to create it
826
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
775
+ if (!device.external) {
776
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
777
+ }
827
778
  // create a new accessory
828
779
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
829
780
  // store a copy of the device object in the `accessory.context`
@@ -833,17 +784,17 @@ class SwitchBotPlatform {
833
784
  accessory.context.deviceID = device.deviceId;
834
785
  accessory.context.firmwareRevision = device.firmware;
835
786
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
836
- await this.connectionTypeNewAccessory(device, accessory);
787
+ accessory.context.connectionType = await this.connectionType(device);
837
788
  // create the accessory handler for the newly create accessory
838
789
  // this is imported from `platformAccessory.ts`
839
790
  new motion_1.Motion(this, accessory, device);
840
791
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
841
- // link the accessory to your platform
842
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
792
+ // publish device externally or link the accessory to your platform
793
+ this.externalOrPlatform(device, accessory);
843
794
  this.accessories.push(accessory);
844
795
  }
845
796
  else {
846
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
797
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
847
798
  }
848
799
  }
849
800
  async createContact(device) {
@@ -853,15 +804,15 @@ class SwitchBotPlatform {
853
804
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
854
805
  if (existingAccessory) {
855
806
  // the accessory already exists
856
- if (this.registerDevice(device)) {
857
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
807
+ if (await this.registerDevice(device)) {
858
808
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
859
809
  existingAccessory.context.model = device.deviceType;
860
810
  existingAccessory.context.deviceID = device.deviceId;
861
- existingAccessory.displayName = device.deviceName;
811
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
862
812
  existingAccessory.context.firmwareRevision = device.firmware;
863
813
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
864
- await this.connectionTypeExistingAccessory(device, existingAccessory);
814
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
815
+ existingAccessory.context.connectionType = await this.connectionType(device);
865
816
  this.api.updatePlatformAccessories([existingAccessory]);
866
817
  // create the accessory handler for the restored accessory
867
818
  // this is imported from `platformAccessory.ts`
@@ -872,9 +823,11 @@ class SwitchBotPlatform {
872
823
  this.unregisterPlatformAccessories(existingAccessory);
873
824
  }
874
825
  }
875
- else if (this.registerDevice(device)) {
826
+ else if (await this.registerDevice(device)) {
876
827
  // the accessory does not yet exist, so we need to create it
877
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
828
+ if (!device.external) {
829
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
830
+ }
878
831
  // create a new accessory
879
832
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
880
833
  // store a copy of the device object in the `accessory.context`
@@ -884,17 +837,17 @@ class SwitchBotPlatform {
884
837
  accessory.context.deviceID = device.deviceId;
885
838
  accessory.context.firmwareRevision = device.firmware;
886
839
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
887
- await this.connectionTypeNewAccessory(device, accessory);
840
+ accessory.context.connectionType = await this.connectionType(device);
888
841
  // create the accessory handler for the newly create accessory
889
842
  // this is imported from `platformAccessory.ts`
890
843
  new contact_1.Contact(this, accessory, device);
891
844
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
892
- // link the accessory to your platform
893
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
845
+ // publish device externally or link the accessory to your platform
846
+ this.externalOrPlatform(device, accessory);
894
847
  this.accessories.push(accessory);
895
848
  }
896
849
  else {
897
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
850
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
898
851
  }
899
852
  }
900
853
  async createCurtain(device) {
@@ -904,15 +857,15 @@ class SwitchBotPlatform {
904
857
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
905
858
  if (existingAccessory) {
906
859
  // the accessory already exists
907
- if (this.isCurtainGrouped(device)) {
908
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
860
+ if (await this.registerDevice(device)) {
909
861
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
910
862
  existingAccessory.context.model = device.deviceType;
911
863
  existingAccessory.context.deviceID = device.deviceId;
912
- existingAccessory.displayName = device.deviceName;
864
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
913
865
  existingAccessory.context.firmwareRevision = device.firmware;
914
866
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
915
- await this.connectionTypeExistingAccessory(device, existingAccessory);
867
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
868
+ existingAccessory.context.connectionType = await this.connectionType(device);
916
869
  this.api.updatePlatformAccessories([existingAccessory]);
917
870
  // create the accessory handler for the restored accessory
918
871
  // this is imported from `platformAccessory.ts`
@@ -923,19 +876,21 @@ class SwitchBotPlatform {
923
876
  this.unregisterPlatformAccessories(existingAccessory);
924
877
  }
925
878
  }
926
- else if (this.isCurtainGrouped(device)) {
879
+ else if (await this.registerDevice(device)) {
927
880
  // the accessory does not yet exist, so we need to create it
928
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
881
+ if (!device.external) {
882
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
883
+ }
929
884
  if (device.group && !device.curtain?.disable_group) {
930
885
  this.debugLog(`Your Curtains are grouped
931
886
  , Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
932
887
  }
933
888
  else {
934
889
  if (device.master) {
935
- this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
890
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
936
891
  }
937
892
  else {
938
- this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
893
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
939
894
  }
940
895
  }
941
896
  // create a new accessory
@@ -947,29 +902,17 @@ class SwitchBotPlatform {
947
902
  accessory.context.deviceID = device.deviceId;
948
903
  accessory.context.firmwareRevision = device.firmware;
949
904
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
950
- await this.connectionTypeNewAccessory(device, accessory);
905
+ accessory.context.connectionType = await this.connectionType(device);
951
906
  // create the accessory handler for the newly create accessory
952
907
  // this is imported from `platformAccessory.ts`
953
908
  new curtain_1.Curtain(this, accessory, device);
954
909
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
955
- // link the accessory to your platform
956
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
910
+ // publish device externally or link the accessory to your platform
911
+ this.externalOrPlatform(device, accessory);
957
912
  this.accessories.push(accessory);
958
913
  }
959
914
  else {
960
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
961
- }
962
- }
963
- isCurtainGrouped(device) {
964
- this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
965
- ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
966
- if (device.group && !device.curtain?.disable_group) {
967
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
968
- return device.master && this.registerDevice(device);
969
- }
970
- else {
971
- this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
972
- return this.registerDevice(device);
915
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
973
916
  }
974
917
  }
975
918
  async createPlug(device) {
@@ -979,15 +922,15 @@ class SwitchBotPlatform {
979
922
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
980
923
  if (existingAccessory) {
981
924
  // the accessory already exists
982
- if (this.registerDevice(device)) {
983
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
925
+ if (await this.registerDevice(device)) {
984
926
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
985
927
  existingAccessory.context.model = device.deviceType;
986
928
  existingAccessory.context.deviceID = device.deviceId;
987
- existingAccessory.displayName = device.deviceName;
929
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
988
930
  existingAccessory.context.firmwareRevision = device.firmware;
989
931
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
990
- await this.connectionTypeExistingAccessory(device, existingAccessory);
932
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
933
+ existingAccessory.context.connectionType = await this.connectionType(device);
991
934
  this.api.updatePlatformAccessories([existingAccessory]);
992
935
  // create the accessory handler for the restored accessory
993
936
  // this is imported from `platformAccessory.ts`
@@ -998,9 +941,11 @@ class SwitchBotPlatform {
998
941
  this.unregisterPlatformAccessories(existingAccessory);
999
942
  }
1000
943
  }
1001
- else if (this.registerDevice(device)) {
944
+ else if (await this.registerDevice(device)) {
1002
945
  // the accessory does not yet exist, so we need to create it
1003
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
946
+ if (!device.external) {
947
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
948
+ }
1004
949
  // create a new accessory
1005
950
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1006
951
  // store a copy of the device object in the `accessory.context`
@@ -1010,17 +955,17 @@ class SwitchBotPlatform {
1010
955
  accessory.context.deviceID = device.deviceId;
1011
956
  accessory.context.firmwareRevision = device.firmware;
1012
957
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1013
- await this.connectionTypeNewAccessory(device, accessory);
958
+ accessory.context.connectionType = await this.connectionType(device);
1014
959
  // create the accessory handler for the newly create accessory
1015
960
  // this is imported from `platformAccessory.ts`
1016
961
  new plug_1.Plug(this, accessory, device);
1017
962
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1018
- // link the accessory to your platform
1019
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
963
+ // publish device externally or link the accessory to your platform
964
+ this.externalOrPlatform(device, accessory);
1020
965
  this.accessories.push(accessory);
1021
966
  }
1022
967
  else {
1023
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
968
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1024
969
  }
1025
970
  }
1026
971
  async createLock(device) {
@@ -1030,15 +975,15 @@ class SwitchBotPlatform {
1030
975
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1031
976
  if (existingAccessory) {
1032
977
  // the accessory already exists
1033
- if (this.registerDevice(device)) {
1034
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
978
+ if (await this.registerDevice(device)) {
1035
979
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1036
980
  existingAccessory.context.model = device.deviceType;
1037
981
  existingAccessory.context.deviceID = device.deviceId;
1038
- existingAccessory.displayName = device.deviceName;
982
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1039
983
  existingAccessory.context.firmwareRevision = device.firmware;
1040
984
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1041
- await this.connectionTypeExistingAccessory(device, existingAccessory);
985
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
986
+ existingAccessory.context.connectionType = await this.connectionType(device);
1042
987
  this.api.updatePlatformAccessories([existingAccessory]);
1043
988
  // create the accessory handler for the restored accessory
1044
989
  // this is imported from `platformAccessory.ts`
@@ -1049,9 +994,11 @@ class SwitchBotPlatform {
1049
994
  this.unregisterPlatformAccessories(existingAccessory);
1050
995
  }
1051
996
  }
1052
- else if (this.registerDevice(device)) {
997
+ else if (await this.registerDevice(device)) {
1053
998
  // the accessory does not yet exist, so we need to create it
1054
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
999
+ if (!device.external) {
1000
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1001
+ }
1055
1002
  // create a new accessory
1056
1003
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1057
1004
  // store a copy of the device object in the `accessory.context`
@@ -1061,17 +1008,17 @@ class SwitchBotPlatform {
1061
1008
  accessory.context.deviceID = device.deviceId;
1062
1009
  accessory.context.firmwareRevision = device.firmware;
1063
1010
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1064
- await this.connectionTypeNewAccessory(device, accessory);
1011
+ accessory.context.connectionType = await this.connectionType(device);
1065
1012
  // create the accessory handler for the newly create accessory
1066
1013
  // this is imported from `platformAccessory.ts`
1067
1014
  new lock_1.Lock(this, accessory, device);
1068
1015
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1069
- // link the accessory to your platform
1070
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1016
+ // publish device externally or link the accessory to your platform
1017
+ this.externalOrPlatform(device, accessory);
1071
1018
  this.accessories.push(accessory);
1072
1019
  }
1073
1020
  else {
1074
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1021
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1075
1022
  }
1076
1023
  }
1077
1024
  async createColorBulb(device) {
@@ -1081,15 +1028,15 @@ class SwitchBotPlatform {
1081
1028
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1082
1029
  if (existingAccessory) {
1083
1030
  // the accessory already exists
1084
- if (this.registerDevice(device)) {
1085
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1031
+ if (await this.registerDevice(device)) {
1086
1032
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1087
1033
  existingAccessory.context.model = device.deviceType;
1088
1034
  existingAccessory.context.deviceID = device.deviceId;
1089
- existingAccessory.displayName = device.deviceName;
1035
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1090
1036
  existingAccessory.context.firmwareRevision = device.firmware;
1091
1037
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1092
- await this.connectionTypeExistingAccessory(device, existingAccessory);
1038
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1039
+ existingAccessory.context.connectionType = await this.connectionType(device);
1093
1040
  this.api.updatePlatformAccessories([existingAccessory]);
1094
1041
  // create the accessory handler for the restored accessory
1095
1042
  // this is imported from `platformAccessory.ts`
@@ -1100,9 +1047,11 @@ class SwitchBotPlatform {
1100
1047
  this.unregisterPlatformAccessories(existingAccessory);
1101
1048
  }
1102
1049
  }
1103
- else if (this.registerDevice(device)) {
1050
+ else if (await this.registerDevice(device)) {
1104
1051
  // the accessory does not yet exist, so we need to create it
1105
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1052
+ if (!device.external) {
1053
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1054
+ }
1106
1055
  // create a new accessory
1107
1056
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1108
1057
  // store a copy of the device object in the `accessory.context`
@@ -1112,35 +1061,88 @@ class SwitchBotPlatform {
1112
1061
  accessory.context.deviceID = device.deviceId;
1113
1062
  accessory.context.firmwareRevision = device.firmware;
1114
1063
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1115
- await this.connectionTypeNewAccessory(device, accessory);
1064
+ accessory.context.connectionType = await this.connectionType(device);
1116
1065
  // create the accessory handler for the newly create accessory
1117
1066
  // this is imported from `platformAccessory.ts`
1118
1067
  new colorbulb_1.ColorBulb(this, accessory, device);
1119
1068
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1120
- // link the accessory to your platform
1121
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1069
+ // publish device externally or link the accessory to your platform
1070
+ this.externalOrPlatform(device, accessory);
1122
1071
  this.accessories.push(accessory);
1123
1072
  }
1124
1073
  else {
1125
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1074
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1126
1075
  }
1127
1076
  }
1128
- async createStripLight(device) {
1077
+ async createCeilingLight(device) {
1129
1078
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1130
1079
  // see if an accessory with the same uuid has already been registered and restored from
1131
1080
  // the cached devices we stored in the `configureAccessory` method above
1132
1081
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1133
1082
  if (existingAccessory) {
1134
1083
  // the accessory already exists
1135
- if (this.registerDevice(device)) {
1084
+ if (await this.registerDevice(device)) {
1085
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1086
+ existingAccessory.context.model = device.deviceType;
1087
+ existingAccessory.context.deviceID = device.deviceId;
1088
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1089
+ existingAccessory.context.firmwareRevision = device.firmware;
1090
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1136
1091
  this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1092
+ existingAccessory.context.connectionType = await this.connectionType(device);
1093
+ this.api.updatePlatformAccessories([existingAccessory]);
1094
+ // create the accessory handler for the restored accessory
1095
+ // this is imported from `platformAccessory.ts`
1096
+ new ceilinglight_1.CeilingLight(this, existingAccessory, device);
1097
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1098
+ }
1099
+ else {
1100
+ this.unregisterPlatformAccessories(existingAccessory);
1101
+ }
1102
+ }
1103
+ else if (await this.registerDevice(device)) {
1104
+ // the accessory does not yet exist, so we need to create it
1105
+ if (!device.external) {
1106
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1107
+ }
1108
+ // create a new accessory
1109
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1110
+ // store a copy of the device object in the `accessory.context`
1111
+ // the `context` property can be used to store any data about the accessory you may need
1112
+ accessory.context.device = device;
1113
+ accessory.context.model = device.deviceType;
1114
+ accessory.context.deviceID = device.deviceId;
1115
+ accessory.context.firmwareRevision = device.firmware;
1116
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1117
+ accessory.context.connectionType = await this.connectionType(device);
1118
+ // create the accessory handler for the newly create accessory
1119
+ // this is imported from `platformAccessory.ts`
1120
+ new ceilinglight_1.CeilingLight(this, accessory, device);
1121
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1122
+ // publish device externally or link the accessory to your platform
1123
+ this.externalOrPlatform(device, accessory);
1124
+ this.accessories.push(accessory);
1125
+ }
1126
+ else {
1127
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1128
+ }
1129
+ }
1130
+ async createStripLight(device) {
1131
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1132
+ // see if an accessory with the same uuid has already been registered and restored from
1133
+ // the cached devices we stored in the `configureAccessory` method above
1134
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1135
+ if (existingAccessory) {
1136
+ // the accessory already exists
1137
+ if (await this.registerDevice(device)) {
1137
1138
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1138
1139
  existingAccessory.context.model = device.deviceType;
1139
1140
  existingAccessory.context.deviceID = device.deviceId;
1140
- existingAccessory.displayName = device.deviceName;
1141
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1141
1142
  existingAccessory.context.firmwareRevision = device.firmware;
1142
1143
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1143
- await this.connectionTypeExistingAccessory(device, existingAccessory);
1144
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1145
+ existingAccessory.context.connectionType = await this.connectionType(device);
1144
1146
  this.api.updatePlatformAccessories([existingAccessory]);
1145
1147
  // create the accessory handler for the restored accessory
1146
1148
  // this is imported from `platformAccessory.ts`
@@ -1151,9 +1153,11 @@ class SwitchBotPlatform {
1151
1153
  this.unregisterPlatformAccessories(existingAccessory);
1152
1154
  }
1153
1155
  }
1154
- else if (this.registerDevice(device)) {
1156
+ else if (await this.registerDevice(device)) {
1155
1157
  // the accessory does not yet exist, so we need to create it
1156
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1158
+ if (!device.external) {
1159
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1160
+ }
1157
1161
  // create a new accessory
1158
1162
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1159
1163
  // store a copy of the device object in the `accessory.context`
@@ -1163,17 +1167,17 @@ class SwitchBotPlatform {
1163
1167
  accessory.context.deviceID = device.deviceId;
1164
1168
  accessory.context.firmwareRevision = device.firmware;
1165
1169
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1166
- await this.connectionTypeNewAccessory(device, accessory);
1170
+ accessory.context.connectionType = await this.connectionType(device);
1167
1171
  // create the accessory handler for the newly create accessory
1168
1172
  // this is imported from `platformAccessory.ts`
1169
1173
  new striplight_1.StripLight(this, accessory, device);
1170
1174
  this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1171
- // link the accessory to your platform
1172
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1175
+ // publish device externally or link the accessory to your platform
1176
+ this.externalOrPlatform(device, accessory);
1173
1177
  this.accessories.push(accessory);
1174
1178
  }
1175
1179
  else {
1176
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1180
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1177
1181
  }
1178
1182
  }
1179
1183
  async createTV(device) {
@@ -1182,14 +1186,14 @@ class SwitchBotPlatform {
1182
1186
  // the cached devices we stored in the `configureAccessory` method above
1183
1187
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1184
1188
  if (!device.hide_device && existingAccessory) {
1185
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1186
1189
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1187
1190
  existingAccessory.context.model = device.remoteType;
1188
1191
  existingAccessory.context.deviceID = device.deviceId;
1189
- existingAccessory.displayName = device.deviceName;
1192
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1190
1193
  existingAccessory.context.firmwareRevision = device.firmware;
1191
1194
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1192
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1195
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1196
+ existingAccessory.context.connectionType = await this.connectionType(device);
1193
1197
  this.api.updatePlatformAccessories([existingAccessory]);
1194
1198
  // create the accessory handler for the restored accessory
1195
1199
  // this is imported from `platformAccessory.ts`
@@ -1198,7 +1202,9 @@ class SwitchBotPlatform {
1198
1202
  }
1199
1203
  else if (!device.hide_device && device.hubDeviceId) {
1200
1204
  // the accessory does not yet exist, so we need to create it
1201
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1205
+ if (!device.external) {
1206
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1207
+ }
1202
1208
  // create a new accessory
1203
1209
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1204
1210
  // store a copy of the device object in the `accessory.context`
@@ -1208,7 +1214,7 @@ class SwitchBotPlatform {
1208
1214
  accessory.context.deviceID = device.deviceId;
1209
1215
  accessory.context.firmwareRevision = device.firmware;
1210
1216
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1211
- await this.connectionTypeNewIRAccessory(accessory);
1217
+ accessory.context.connectionType = await this.connectionType(device);
1212
1218
  // create the accessory handler for the newly create accessory
1213
1219
  // this is imported from `platformAccessory.ts`
1214
1220
  new tv_1.TV(this, accessory, device);
@@ -1218,11 +1224,11 @@ class SwitchBotPlatform {
1218
1224
  * Only one TV can exist per bridge, to bypass this limitation, you should
1219
1225
  * publish your TV as an external accessory.
1220
1226
  */
1221
- this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]);
1227
+ this.externalAccessory(accessory);
1222
1228
  this.accessories.push(accessory);
1223
1229
  }
1224
1230
  else {
1225
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1231
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1226
1232
  }
1227
1233
  }
1228
1234
  async createFan(device) {
@@ -1233,14 +1239,14 @@ class SwitchBotPlatform {
1233
1239
  if (existingAccessory) {
1234
1240
  // the accessory already exists
1235
1241
  if (!device.hide_device && device.hubDeviceId) {
1236
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1237
1242
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1238
1243
  existingAccessory.context.model = device.remoteType;
1239
1244
  existingAccessory.context.deviceID = device.deviceId;
1240
- existingAccessory.displayName = device.deviceName;
1245
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1241
1246
  existingAccessory.context.firmwareRevision = device.firmware;
1242
1247
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1243
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1248
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1249
+ existingAccessory.context.connectionType = await this.connectionType(device);
1244
1250
  this.api.updatePlatformAccessories([existingAccessory]);
1245
1251
  // create the accessory handler for the restored accessory
1246
1252
  // this is imported from `platformAccessory.ts`
@@ -1253,7 +1259,9 @@ class SwitchBotPlatform {
1253
1259
  }
1254
1260
  else if (!device.hide_device && device.hubDeviceId) {
1255
1261
  // the accessory does not yet exist, so we need to create it
1256
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1262
+ if (!device.external) {
1263
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1264
+ }
1257
1265
  // create a new accessory
1258
1266
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1259
1267
  // store a copy of the device object in the `accessory.context`
@@ -1263,17 +1271,17 @@ class SwitchBotPlatform {
1263
1271
  accessory.context.deviceID = device.deviceId;
1264
1272
  accessory.context.firmwareRevision = device.firmware;
1265
1273
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1266
- await this.connectionTypeNewIRAccessory(accessory);
1274
+ accessory.context.connectionType = await this.connectionType(device);
1267
1275
  // create the accessory handler for the newly create accessory
1268
1276
  // this is imported from `platformAccessory.ts`
1269
1277
  new fan_1.Fan(this, accessory, device);
1270
1278
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1271
- // link the accessory to your platform
1272
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1279
+ // publish device externally or link the accessory to your platform
1280
+ this.externalOrPlatform(device, accessory);
1273
1281
  this.accessories.push(accessory);
1274
1282
  }
1275
1283
  else {
1276
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1284
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1277
1285
  }
1278
1286
  }
1279
1287
  async createLight(device) {
@@ -1284,14 +1292,14 @@ class SwitchBotPlatform {
1284
1292
  if (existingAccessory) {
1285
1293
  // the accessory already exists
1286
1294
  if (!device.hide_device && device.hubDeviceId) {
1287
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1288
1295
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1289
1296
  existingAccessory.context.model = device.remoteType;
1290
1297
  existingAccessory.context.deviceID = device.deviceId;
1291
- existingAccessory.displayName = device.deviceName;
1298
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1292
1299
  existingAccessory.context.firmwareRevision = device.firmware;
1293
1300
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1294
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1301
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1302
+ existingAccessory.context.connectionType = await this.connectionType(device);
1295
1303
  this.api.updatePlatformAccessories([existingAccessory]);
1296
1304
  // create the accessory handler for the restored accessory
1297
1305
  // this is imported from `platformAccessory.ts`
@@ -1304,7 +1312,9 @@ class SwitchBotPlatform {
1304
1312
  }
1305
1313
  else if (!device.hide_device && device.hubDeviceId) {
1306
1314
  // the accessory does not yet exist, so we need to create it
1307
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1315
+ if (!device.external) {
1316
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1317
+ }
1308
1318
  // create a new accessory
1309
1319
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1310
1320
  // store a copy of the device object in the `accessory.context`
@@ -1314,17 +1324,17 @@ class SwitchBotPlatform {
1314
1324
  accessory.context.deviceID = device.deviceId;
1315
1325
  accessory.context.firmwareRevision = device.firmware;
1316
1326
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1317
- await this.connectionTypeNewIRAccessory(accessory);
1327
+ accessory.context.connectionType = await this.connectionType(device);
1318
1328
  // create the accessory handler for the newly create accessory
1319
1329
  // this is imported from `platformAccessory.ts`
1320
1330
  new light_1.Light(this, accessory, device);
1321
1331
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1322
- // link the accessory to your platform
1323
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1332
+ // publish device externally or link the accessory to your platform
1333
+ this.externalOrPlatform(device, accessory);
1324
1334
  this.accessories.push(accessory);
1325
1335
  }
1326
1336
  else {
1327
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1337
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1328
1338
  }
1329
1339
  }
1330
1340
  async createAirConditioner(device) {
@@ -1335,14 +1345,14 @@ class SwitchBotPlatform {
1335
1345
  if (existingAccessory) {
1336
1346
  // the accessory already exists
1337
1347
  if (!device.hide_device && device.hubDeviceId) {
1338
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1339
1348
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1340
1349
  existingAccessory.context.model = device.remoteType;
1341
1350
  existingAccessory.context.deviceID = device.deviceId;
1342
- existingAccessory.displayName = device.deviceName;
1351
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1343
1352
  existingAccessory.context.firmwareRevision = device.firmware;
1344
1353
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1345
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1354
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1355
+ existingAccessory.context.connectionType = await this.connectionType(device);
1346
1356
  this.api.updatePlatformAccessories([existingAccessory]);
1347
1357
  // create the accessory handler for the restored accessory
1348
1358
  // this is imported from `platformAccessory.ts`
@@ -1355,7 +1365,9 @@ class SwitchBotPlatform {
1355
1365
  }
1356
1366
  else if (!device.hide_device && device.hubDeviceId) {
1357
1367
  // the accessory does not yet exist, so we need to create it
1358
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1368
+ if (!device.external) {
1369
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1370
+ }
1359
1371
  // create a new accessory
1360
1372
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1361
1373
  // store a copy of the device object in the `accessory.context`
@@ -1365,17 +1377,17 @@ class SwitchBotPlatform {
1365
1377
  accessory.context.deviceID = device.deviceId;
1366
1378
  accessory.context.firmwareRevision = device.firmware;
1367
1379
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1368
- await this.connectionTypeNewIRAccessory(accessory);
1380
+ accessory.context.connectionType = await this.connectionType(device);
1369
1381
  // create the accessory handler for the newly create accessory
1370
1382
  // this is imported from `platformAccessory.ts`
1371
1383
  new airconditioner_1.AirConditioner(this, accessory, device);
1372
1384
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1373
- // link the accessory to your platform
1374
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1385
+ // publish device externally or link the accessory to your platform
1386
+ this.externalOrPlatform(device, accessory);
1375
1387
  this.accessories.push(accessory);
1376
1388
  }
1377
1389
  else {
1378
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1390
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1379
1391
  }
1380
1392
  }
1381
1393
  async createAirPurifier(device) {
@@ -1386,14 +1398,14 @@ class SwitchBotPlatform {
1386
1398
  if (existingAccessory) {
1387
1399
  // the accessory already exists
1388
1400
  if (!device.hide_device && device.hubDeviceId) {
1389
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1390
1401
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1391
1402
  existingAccessory.context.model = device.remoteType;
1392
1403
  existingAccessory.context.deviceID = device.deviceId;
1393
- existingAccessory.displayName = device.deviceName;
1404
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1394
1405
  existingAccessory.context.firmwareRevision = device.firmware;
1395
1406
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1396
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1407
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1408
+ existingAccessory.context.connectionType = await this.connectionType(device);
1397
1409
  this.api.updatePlatformAccessories([existingAccessory]);
1398
1410
  // create the accessory handler for the restored accessory
1399
1411
  // this is imported from `platformAccessory.ts`
@@ -1406,7 +1418,9 @@ class SwitchBotPlatform {
1406
1418
  }
1407
1419
  else if (!device.hide_device && device.hubDeviceId) {
1408
1420
  // the accessory does not yet exist, so we need to create it
1409
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1421
+ if (!device.external) {
1422
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1423
+ }
1410
1424
  // create a new accessory
1411
1425
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1412
1426
  // store a copy of the device object in the `accessory.context`
@@ -1416,17 +1430,17 @@ class SwitchBotPlatform {
1416
1430
  accessory.context.deviceID = device.deviceId;
1417
1431
  accessory.context.firmwareRevision = device.firmware;
1418
1432
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1419
- await this.connectionTypeNewIRAccessory(accessory);
1433
+ accessory.context.connectionType = await this.connectionType(device);
1420
1434
  // create the accessory handler for the newly create accessory
1421
1435
  // this is imported from `platformAccessory.ts`
1422
1436
  new airpurifier_1.AirPurifier(this, accessory, device);
1423
1437
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1424
- // link the accessory to your platform
1425
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1438
+ // publish device externally or link the accessory to your platform
1439
+ this.externalOrPlatform(device, accessory);
1426
1440
  this.accessories.push(accessory);
1427
1441
  }
1428
1442
  else {
1429
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1443
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1430
1444
  }
1431
1445
  }
1432
1446
  async createWaterHeater(device) {
@@ -1437,14 +1451,14 @@ class SwitchBotPlatform {
1437
1451
  if (existingAccessory) {
1438
1452
  // the accessory already exists
1439
1453
  if (!device.hide_device && device.hubDeviceId) {
1440
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1441
1454
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1442
1455
  existingAccessory.context.model = device.remoteType;
1443
1456
  existingAccessory.context.deviceID = device.deviceId;
1444
- existingAccessory.displayName = device.deviceName;
1457
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1445
1458
  existingAccessory.context.firmwareRevision = device.firmware;
1446
1459
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1447
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1460
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1461
+ existingAccessory.context.connectionType = await this.connectionType(device);
1448
1462
  this.api.updatePlatformAccessories([existingAccessory]);
1449
1463
  // create the accessory handler for the restored accessory
1450
1464
  // this is imported from `platformAccessory.ts`
@@ -1457,7 +1471,9 @@ class SwitchBotPlatform {
1457
1471
  }
1458
1472
  else if (!device.hide_device && device.hubDeviceId) {
1459
1473
  // the accessory does not yet exist, so we need to create it
1460
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1474
+ if (!device.external) {
1475
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1476
+ }
1461
1477
  // create a new accessory
1462
1478
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1463
1479
  // store a copy of the device object in the `accessory.context`
@@ -1467,17 +1483,17 @@ class SwitchBotPlatform {
1467
1483
  accessory.context.deviceID = device.deviceId;
1468
1484
  accessory.context.firmwareRevision = device.firmware;
1469
1485
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1470
- await this.connectionTypeNewIRAccessory(accessory);
1486
+ accessory.context.connectionType = await this.connectionType(device);
1471
1487
  // create the accessory handler for the newly create accessory
1472
1488
  // this is imported from `platformAccessory.ts`
1473
1489
  new waterheater_1.WaterHeater(this, accessory, device);
1474
1490
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1475
- // link the accessory to your platform
1476
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1491
+ // publish device externally or link the accessory to your platform
1492
+ this.externalOrPlatform(device, accessory);
1477
1493
  this.accessories.push(accessory);
1478
1494
  }
1479
1495
  else {
1480
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1496
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1481
1497
  }
1482
1498
  }
1483
1499
  async createVacuumCleaner(device) {
@@ -1488,14 +1504,14 @@ class SwitchBotPlatform {
1488
1504
  if (existingAccessory) {
1489
1505
  // the accessory already exists
1490
1506
  if (!device.hide_device && device.hubDeviceId) {
1491
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1492
1507
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1493
1508
  existingAccessory.context.model = device.remoteType;
1494
1509
  existingAccessory.context.deviceID = device.deviceId;
1495
- existingAccessory.displayName = device.deviceName;
1510
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1496
1511
  existingAccessory.context.firmwareRevision = device.firmware;
1497
1512
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1498
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1513
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1514
+ existingAccessory.context.connectionType = await this.connectionType(device);
1499
1515
  this.api.updatePlatformAccessories([existingAccessory]);
1500
1516
  // create the accessory handler for the restored accessory
1501
1517
  // this is imported from `platformAccessory.ts`
@@ -1508,7 +1524,9 @@ class SwitchBotPlatform {
1508
1524
  }
1509
1525
  else if (!device.hide_device && device.hubDeviceId) {
1510
1526
  // the accessory does not yet exist, so we need to create it
1511
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1527
+ if (!device.external) {
1528
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1529
+ }
1512
1530
  // create a new accessory
1513
1531
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1514
1532
  // store a copy of the device object in the `accessory.context`
@@ -1518,17 +1536,17 @@ class SwitchBotPlatform {
1518
1536
  accessory.context.deviceID = device.deviceId;
1519
1537
  accessory.context.firmwareRevision = device.firmware;
1520
1538
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1521
- await this.connectionTypeNewIRAccessory(accessory);
1539
+ accessory.context.connectionType = await this.connectionType(device);
1522
1540
  // create the accessory handler for the newly create accessory
1523
1541
  // this is imported from `platformAccessory.ts`
1524
1542
  new vacuumcleaner_1.VacuumCleaner(this, accessory, device);
1525
1543
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1526
- // link the accessory to your platform
1527
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1544
+ // publish device externally or link the accessory to your platform
1545
+ this.externalOrPlatform(device, accessory);
1528
1546
  this.accessories.push(accessory);
1529
1547
  }
1530
1548
  else {
1531
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1549
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1532
1550
  }
1533
1551
  }
1534
1552
  async createCamera(device) {
@@ -1539,14 +1557,14 @@ class SwitchBotPlatform {
1539
1557
  if (existingAccessory) {
1540
1558
  // the accessory already exists
1541
1559
  if (!device.hide_device && device.hubDeviceId) {
1542
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1543
1560
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1544
1561
  existingAccessory.context.model = device.remoteType;
1545
1562
  existingAccessory.context.deviceID = device.deviceId;
1546
- existingAccessory.displayName = device.deviceName;
1563
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1547
1564
  existingAccessory.context.firmwareRevision = device.firmware;
1548
1565
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1549
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1566
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1567
+ existingAccessory.context.connectionType = await this.connectionType(device);
1550
1568
  this.api.updatePlatformAccessories([existingAccessory]);
1551
1569
  // create the accessory handler for the restored accessory
1552
1570
  // this is imported from `platformAccessory.ts`
@@ -1559,7 +1577,9 @@ class SwitchBotPlatform {
1559
1577
  }
1560
1578
  else if (!device.hide_device && device.hubDeviceId) {
1561
1579
  // the accessory does not yet exist, so we need to create it
1562
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1580
+ if (!device.external) {
1581
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1582
+ }
1563
1583
  // create a new accessory
1564
1584
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1565
1585
  // store a copy of the device object in the `accessory.context`
@@ -1569,17 +1589,17 @@ class SwitchBotPlatform {
1569
1589
  accessory.context.deviceID = device.deviceId;
1570
1590
  accessory.context.firmwareRevision = device.firmware;
1571
1591
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1572
- await this.connectionTypeNewIRAccessory(accessory);
1592
+ accessory.context.connectionType = await this.connectionType(device);
1573
1593
  // create the accessory handler for the newly create accessory
1574
1594
  // this is imported from `platformAccessory.ts`
1575
1595
  new camera_1.Camera(this, accessory, device);
1576
1596
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1577
- // link the accessory to your platform
1578
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1597
+ // publish device externally or link the accessory to your platform
1598
+ this.externalOrPlatform(device, accessory);
1579
1599
  this.accessories.push(accessory);
1580
1600
  }
1581
1601
  else {
1582
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1602
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1583
1603
  }
1584
1604
  }
1585
1605
  async createOthers(device) {
@@ -1590,14 +1610,14 @@ class SwitchBotPlatform {
1590
1610
  if (existingAccessory) {
1591
1611
  // the accessory already exists
1592
1612
  if (!device.hide_device && device.hubDeviceId) {
1593
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1594
1613
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1595
1614
  existingAccessory.context.model = device.remoteType;
1596
1615
  existingAccessory.context.deviceID = device.deviceId;
1597
- existingAccessory.displayName = device.deviceName;
1616
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1598
1617
  existingAccessory.context.firmwareRevision = device.firmware;
1599
1618
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1600
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1619
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1620
+ existingAccessory.context.connectionType = await this.connectionType(device);
1601
1621
  this.api.updatePlatformAccessories([existingAccessory]);
1602
1622
  // create the accessory handler for the restored accessory
1603
1623
  // this is imported from `platformAccessory.ts`
@@ -1610,7 +1630,9 @@ class SwitchBotPlatform {
1610
1630
  }
1611
1631
  else if (!device.hide_device && device.hubDeviceId) {
1612
1632
  // the accessory does not yet exist, so we need to create it
1613
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1633
+ if (!device.external) {
1634
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1635
+ }
1614
1636
  // create a new accessory
1615
1637
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1616
1638
  // store a copy of the device object in the `accessory.context`
@@ -1620,91 +1642,160 @@ class SwitchBotPlatform {
1620
1642
  accessory.context.deviceID = device.deviceId;
1621
1643
  accessory.context.firmwareRevision = device.firmware;
1622
1644
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1623
- await this.connectionTypeNewIRAccessory(accessory);
1645
+ accessory.context.connectionType = await this.connectionType(device);
1624
1646
  // create the accessory handler for the newly create accessory
1625
1647
  // this is imported from `platformAccessory.ts`
1626
1648
  new other_1.Others(this, accessory, device);
1627
1649
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1628
- // link the accessory to your platform
1629
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1650
+ // publish device externally or link the accessory to your platform
1651
+ this.externalOrPlatform(device, accessory);
1630
1652
  this.accessories.push(accessory);
1631
1653
  }
1632
1654
  else {
1633
- this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1655
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1634
1656
  }
1635
1657
  }
1636
- async connectionTypeNewAccessory(device, accessory) {
1637
- if (device.ble) {
1638
- accessory.context.connectionType = 'BLE';
1658
+ async registerCurtains(device) {
1659
+ this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1660
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1661
+ let registerCurtain;
1662
+ if (device.group && !device.curtain?.disable_group) {
1663
+ registerCurtain = true;
1664
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1665
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1666
+ }
1667
+ else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
1668
+ registerCurtain = true;
1669
+ this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
1670
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1639
1671
  }
1640
1672
  else {
1641
- accessory.context.connectionType = 'OpenAPI';
1673
+ registerCurtain = false;
1674
+ this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1675
+ this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1642
1676
  }
1677
+ return registerCurtain;
1643
1678
  }
1644
- async connectionTypeExistingAccessory(device, existingAccessory) {
1645
- if (device.ble) {
1646
- existingAccessory.context.connectionType = 'BLE';
1679
+ async connectionType(device) {
1680
+ let connectionType;
1681
+ if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1682
+ connectionType = 'OpenAPI';
1683
+ }
1684
+ else {
1685
+ connectionType = device.connectionType;
1686
+ }
1687
+ return connectionType;
1688
+ }
1689
+ async registerDevice(device) {
1690
+ device.connectionType = await this.connectionType(device);
1691
+ let registerDevice;
1692
+ if (!device.hide_device && device.enableCloudService && device.connectionType === 'BLE/OpenAPI') {
1693
+ if (device.deviceType === 'Curtain') {
1694
+ registerDevice = await this.registerCurtains(device);
1695
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1696
+ }
1697
+ else {
1698
+ registerDevice = true;
1699
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1700
+ }
1701
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1702
+ }
1703
+ else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1704
+ && device.connectionType === 'BLE') {
1705
+ if (device.deviceType === 'Curtain') {
1706
+ registerDevice = await this.registerCurtains(device);
1707
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1708
+ }
1709
+ else {
1710
+ registerDevice = true;
1711
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1712
+ }
1713
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1714
+ }
1715
+ else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
1716
+ if (device.deviceType === 'Curtain') {
1717
+ registerDevice = await this.registerCurtains(device);
1718
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1719
+ }
1720
+ else {
1721
+ registerDevice = true;
1722
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1723
+ }
1724
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1725
+ }
1726
+ else if (!device.hide_device && device.connectionType === 'Disabled') {
1727
+ if (device.deviceType === 'Curtain') {
1728
+ registerDevice = await this.registerCurtains(device);
1729
+ this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1730
+ }
1731
+ else {
1732
+ registerDevice = true;
1733
+ this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1734
+ }
1735
+ this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
1736
+ }
1737
+ else if (!device.connectionType && !device.hide_device) {
1738
+ registerDevice = false;
1739
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
1740
+ }
1741
+ else if (device.hide_device) {
1742
+ registerDevice = false;
1743
+ this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
1647
1744
  }
1648
1745
  else {
1649
- existingAccessory.context.connectionType = 'OpenAPI';
1746
+ registerDevice = false;
1747
+ this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
1748
+ + `${device.hide_device}, will not display in HomeKit`);
1650
1749
  }
1750
+ return registerDevice;
1651
1751
  }
1652
- async connectionTypeNewIRAccessory(accessory) {
1653
- accessory.context.connectionType = 'IR wirth OpenAPI';
1752
+ async externalOrPlatform(device, accessory) {
1753
+ if (device.external) {
1754
+ this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
1755
+ this.externalAccessory(accessory);
1756
+ }
1757
+ else {
1758
+ this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
1759
+ this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1760
+ }
1654
1761
  }
1655
- async connectionTypeExistingIRAccessory(existingAccessory) {
1656
- existingAccessory.context.connectionType = 'IR with OpenAPI';
1762
+ async externalAccessory(accessory) {
1763
+ this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]);
1657
1764
  }
1658
1765
  unregisterPlatformAccessories(existingAccessory) {
1659
1766
  // remove platform accessories when no longer present
1660
1767
  this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [existingAccessory]);
1661
1768
  this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
1662
1769
  }
1663
- deviceListInfo(devices) {
1664
- if (this.platformLogging?.includes('debug')) {
1665
- this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
1666
- }
1667
- }
1668
- async deviceInfo(device) {
1669
- if (this.platformLogging?.includes('debug')) {
1670
- this.warnLog(JSON.stringify(device));
1671
- const t = Date.now();
1672
- const nonce = 'requestID';
1673
- const data = this.config.credentials?.token + t + nonce;
1674
- const signTerm = crypto_1.default.createHmac('sha256', this.config.credentials?.secret).update(buffer_1.Buffer.from(data, 'utf-8')).digest();
1675
- const sign = signTerm.toString('base64');
1676
- this.debugLog(sign);
1677
- const options = {
1678
- hostname: settings_1.HostDomain,
1679
- port: 443,
1680
- path: `${settings_1.DevicePath}/${device.deviceId}/status`,
1681
- method: 'GET',
1682
- headers: {
1683
- Authorization: this.config.credentials?.token,
1684
- sign: sign,
1685
- nonce: nonce,
1686
- t: t,
1687
- 'Content-Type': 'application/json',
1688
- },
1689
- };
1690
- const req = https_1.default.request(options, (res) => {
1691
- this.debugLog(`statusCode: ${res.statusCode}`);
1692
- res.on('data', (d) => {
1693
- process.stdout.write(d);
1694
- });
1695
- });
1696
- req.on('error', (error) => {
1697
- this.errorLog(error);
1698
- });
1699
- req.end();
1700
- this.deviceStatus = req;
1701
- if (this.deviceStatus.message === 'success') {
1702
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1703
- }
1704
- else {
1705
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
1706
- this.warnLog('Unable to retreive deviceInfoStatus.');
1707
- }
1770
+ async statusCode({ res }) {
1771
+ switch (res.statusCode) {
1772
+ case 151:
1773
+ this.errorLog('Command not supported by this device type.');
1774
+ break;
1775
+ case 152:
1776
+ this.errorLog('Device not found.');
1777
+ break;
1778
+ case 160:
1779
+ this.errorLog('Command is not supported.');
1780
+ break;
1781
+ case 161:
1782
+ this.errorLog('Device is offline.');
1783
+ break;
1784
+ case 171:
1785
+ this.errorLog('is offline');
1786
+ break;
1787
+ case 190:
1788
+ this.errorLog('Requests reached the daily limit');
1789
+ break;
1790
+ case 100:
1791
+ if (this.debugMode) {
1792
+ this.debugLog('Command successfully sent.');
1793
+ }
1794
+ break;
1795
+ default:
1796
+ if (this.debugMode) {
1797
+ this.debugLog('Unknown statusCode.');
1798
+ }
1708
1799
  }
1709
1800
  }
1710
1801
  // BLE Connection
@@ -1721,6 +1812,21 @@ class SwitchBotPlatform {
1721
1812
  }
1722
1813
  return switchbot;
1723
1814
  }
1815
+ logs() {
1816
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
1817
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
1818
+ this.platformLogging = this.config.options.logging;
1819
+ this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
1820
+ }
1821
+ else if (this.debugMode) {
1822
+ this.platformLogging = 'debugMode';
1823
+ this.debugWarnLog(`Using ${this.platformLogging} Logging`);
1824
+ }
1825
+ else {
1826
+ this.platformLogging = 'standard';
1827
+ this.debugWarnLog(`Using ${this.platformLogging} Logging`);
1828
+ }
1829
+ }
1724
1830
  /**
1725
1831
  * If device level logging is turned on, log to log.warn
1726
1832
  * Otherwise send debug logs to log.debug
@@ -1735,11 +1841,25 @@ class SwitchBotPlatform {
1735
1841
  this.log.warn(String(...log));
1736
1842
  }
1737
1843
  }
1844
+ debugWarnLog(...log) {
1845
+ if (this.enablingPlatfromLogging()) {
1846
+ if (this.platformLogging?.includes('debug')) {
1847
+ this.log.warn('[DEBUG]', String(...log));
1848
+ }
1849
+ }
1850
+ }
1738
1851
  errorLog(...log) {
1739
1852
  if (this.enablingPlatfromLogging()) {
1740
1853
  this.log.error(String(...log));
1741
1854
  }
1742
1855
  }
1856
+ debugErrorLog(...log) {
1857
+ if (this.enablingPlatfromLogging()) {
1858
+ if (this.platformLogging?.includes('debug')) {
1859
+ this.log.error('[DEBUG]', String(...log));
1860
+ }
1861
+ }
1862
+ }
1743
1863
  debugLog(...log) {
1744
1864
  if (this.enablingPlatfromLogging()) {
1745
1865
  if (this.platformLogging === 'debugMode') {