@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.21

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 (113) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +1 -2
  3. package/config.schema.json +75 -20
  4. package/dist/device/bot.d.ts +32 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +646 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/colorbulb.d.ts +34 -19
  9. package/dist/device/colorbulb.d.ts.map +1 -1
  10. package/dist/device/colorbulb.js +429 -304
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts +16 -7
  13. package/dist/device/contact.d.ts.map +1 -1
  14. package/dist/device/contact.js +288 -230
  15. package/dist/device/contact.js.map +1 -1
  16. package/dist/device/curtain.d.ts +21 -16
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +519 -489
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/humidifier.d.ts +22 -18
  21. package/dist/device/humidifier.d.ts.map +1 -1
  22. package/dist/device/humidifier.js +415 -360
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/lock.d.ts +22 -8
  25. package/dist/device/lock.d.ts.map +1 -1
  26. package/dist/device/lock.js +253 -147
  27. package/dist/device/lock.js.map +1 -1
  28. package/dist/device/meter.d.ts +21 -16
  29. package/dist/device/meter.d.ts.map +1 -1
  30. package/dist/device/meter.js +325 -255
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.d.ts +23 -12
  33. package/dist/device/meterplus.d.ts.map +1 -1
  34. package/dist/device/meterplus.js +346 -208
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/motion.d.ts +17 -8
  37. package/dist/device/motion.d.ts.map +1 -1
  38. package/dist/device/motion.js +261 -209
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts +24 -16
  41. package/dist/device/plug.d.ts.map +1 -1
  42. package/dist/device/plug.js +267 -242
  43. package/dist/device/plug.js.map +1 -1
  44. package/dist/device/striplight.d.ts +51 -16
  45. package/dist/device/striplight.d.ts.map +1 -1
  46. package/dist/device/striplight.js +527 -185
  47. package/dist/device/striplight.js.map +1 -1
  48. package/dist/irdevice/airconditioner.d.ts +7 -12
  49. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  50. package/dist/irdevice/airconditioner.js +261 -230
  51. package/dist/irdevice/airconditioner.js.map +1 -1
  52. package/dist/irdevice/airpurifier.d.ts +3 -3
  53. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  54. package/dist/irdevice/airpurifier.js +137 -104
  55. package/dist/irdevice/airpurifier.js.map +1 -1
  56. package/dist/irdevice/camera.d.ts +9 -8
  57. package/dist/irdevice/camera.d.ts.map +1 -1
  58. package/dist/irdevice/camera.js +116 -86
  59. package/dist/irdevice/camera.js.map +1 -1
  60. package/dist/irdevice/fan.d.ts +8 -7
  61. package/dist/irdevice/fan.d.ts.map +1 -1
  62. package/dist/irdevice/fan.js +143 -109
  63. package/dist/irdevice/fan.js.map +1 -1
  64. package/dist/irdevice/light.d.ts +9 -8
  65. package/dist/irdevice/light.d.ts.map +1 -1
  66. package/dist/irdevice/light.js +120 -103
  67. package/dist/irdevice/light.js.map +1 -1
  68. package/dist/irdevice/other.d.ts +9 -8
  69. package/dist/irdevice/other.d.ts.map +1 -1
  70. package/dist/irdevice/other.js +128 -98
  71. package/dist/irdevice/other.js.map +1 -1
  72. package/dist/irdevice/tv.d.ts +10 -9
  73. package/dist/irdevice/tv.d.ts.map +1 -1
  74. package/dist/irdevice/tv.js +126 -93
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.d.ts +7 -10
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +115 -89
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts +6 -9
  81. package/dist/irdevice/waterheater.d.ts.map +1 -1
  82. package/dist/irdevice/waterheater.js +115 -89
  83. package/dist/irdevice/waterheater.js.map +1 -1
  84. package/dist/platform.d.ts +5 -5
  85. package/dist/platform.d.ts.map +1 -1
  86. package/dist/platform.js +227 -199
  87. package/dist/platform.js.map +1 -1
  88. package/dist/settings.d.ts +15 -11
  89. package/dist/settings.d.ts.map +1 -1
  90. package/dist/settings.js.map +1 -1
  91. package/package.json +12 -10
  92. package/src/device/bot.ts +641 -657
  93. package/src/device/colorbulb.ts +440 -339
  94. package/src/device/contact.ts +289 -233
  95. package/src/device/curtain.ts +523 -503
  96. package/src/device/humidifier.ts +421 -396
  97. package/src/device/lock.ts +257 -147
  98. package/src/device/meter.ts +335 -268
  99. package/src/device/meterplus.ts +354 -213
  100. package/src/device/motion.ts +264 -213
  101. package/src/device/plug.ts +270 -251
  102. package/src/device/striplight.ts +552 -207
  103. package/src/irdevice/airconditioner.ts +263 -241
  104. package/src/irdevice/airpurifier.ts +132 -103
  105. package/src/irdevice/camera.ts +112 -85
  106. package/src/irdevice/fan.ts +138 -106
  107. package/src/irdevice/light.ts +116 -103
  108. package/src/irdevice/other.ts +124 -97
  109. package/src/irdevice/tv.ts +123 -93
  110. package/src/irdevice/vacuumcleaner.ts +112 -89
  111. package/src/irdevice/waterheater.ts +111 -89
  112. package/src/platform.ts +216 -214
  113. package/src/settings.ts +15 -11
package/dist/platform.js CHANGED
@@ -28,6 +28,7 @@ const https_1 = __importDefault(require("https"));
28
28
  const crypto_1 = __importDefault(require("crypto"));
29
29
  const buffer_1 = require("buffer");
30
30
  const fakegato_history_1 = __importDefault(require("fakegato-history"));
31
+ const super_stringify_1 = __importDefault(require("super-stringify"));
31
32
  const fs_1 = require("fs");
32
33
  const settings_1 = require("./settings");
33
34
  /**
@@ -61,9 +62,9 @@ class SwitchBotPlatform {
61
62
  this.debugLog('Config OK');
62
63
  }
63
64
  catch (e) {
64
- this.errorLog(JSON.stringify(e.message));
65
+ this.errorLog((0, super_stringify_1.default)(e.message));
65
66
  if (this.platformLogging?.includes('debug')) {
66
- this.errorLog(JSON.stringify(e));
67
+ this.errorLog((0, super_stringify_1.default)(e));
67
68
  }
68
69
  return;
69
70
  }
@@ -80,14 +81,18 @@ class SwitchBotPlatform {
80
81
  if (this.config.credentials?.openToken && !this.config.credentials.token) {
81
82
  await this.updateToken();
82
83
  }
84
+ else if (!this.config.credentials?.secret) {
85
+ // eslint-disable-next-line no-useless-escape
86
+ this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
87
+ }
83
88
  else {
84
89
  this.discoverDevices();
85
90
  }
86
91
  }
87
92
  catch (e) {
88
- this.errorLog('Failed to Discover Devices.', JSON.stringify(e.message));
93
+ this.errorLog('Failed to Discover Devices.', (0, super_stringify_1.default)(e.message));
89
94
  if (this.platformLogging?.includes('debug')) {
90
- this.errorLog(JSON.stringify(e));
95
+ this.errorLog((0, super_stringify_1.default)(e));
91
96
  }
92
97
  }
93
98
  });
@@ -131,14 +136,14 @@ class SwitchBotPlatform {
131
136
  if (this.config.options.logging) {
132
137
  platformConfig['logging'] = this.config.options.logging;
133
138
  }
134
- if (this.config.options.logging) {
139
+ if (this.config.options.logging && this.config.options.refreshRate) {
135
140
  platformConfig['refreshRate'] = this.config.options.refreshRate;
136
141
  }
137
- if (this.config.options.logging) {
142
+ if (this.config.options.logging && this.config.options.pushRate) {
138
143
  platformConfig['pushRate'] = this.config.options.pushRate;
139
144
  }
140
145
  if (Object.entries(platformConfig).length !== 0) {
141
- this.infoLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
146
+ this.infoLog(`Platform Config: ${(0, super_stringify_1.default)(platformConfig)}`);
142
147
  }
143
148
  if (this.config.options) {
144
149
  // Device Config
@@ -148,7 +153,7 @@ class SwitchBotPlatform {
148
153
  if (!deviceConfig.deviceId) {
149
154
  throw new Error('The devices config section is missing the *Device ID* in the config. Please check your config.');
150
155
  }
151
- if (!deviceConfig.configDeviceType && deviceConfig.ble) {
156
+ if (!deviceConfig.configDeviceType && deviceConfig.connectionType) {
152
157
  throw new Error('The devices config section is missing the *Device Type* in the config. Please check your config.');
153
158
  }
154
159
  }
@@ -177,33 +182,32 @@ class SwitchBotPlatform {
177
182
  if (this.platformLogging?.includes('debug')) {
178
183
  this.debugLog('Using Default Refresh Rate (2 minutes).');
179
184
  }
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
- }
185
+ }
186
+ if (!this.config.options.pushRate) {
187
+ // default 100 milliseconds
188
+ this.config.options.pushRate = 0.1;
189
+ if (this.platformLogging?.includes('debug')) {
190
+ this.warnLog('Using Default Push Rate.');
186
191
  }
187
- if (!this.config.credentials) {
188
- if (this.platformLogging?.includes('debug')) {
189
- this.debugLog('Missing Credentials');
190
- }
192
+ }
193
+ if (!this.config.credentials) {
194
+ if (this.platformLogging?.includes('debug')) {
195
+ this.debugLog('Missing Credentials');
191
196
  }
192
- if (!this.config.credentials?.token) {
197
+ }
198
+ if (!this.config.credentials?.token) {
199
+ if (this.platformLogging?.includes('debug')) {
200
+ this.errorLog('Missing token');
201
+ this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
202
+ }
203
+ }
204
+ if (this.config.credentials?.token) {
205
+ if (!this.config.credentials?.secret) {
193
206
  if (this.platformLogging?.includes('debug')) {
194
- this.errorLog('Missing token');
207
+ this.errorLog('Missing secret');
195
208
  this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
196
209
  }
197
210
  }
198
- if (this.config.credentials?.token) {
199
- 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');
205
- }
206
- }
207
211
  }
208
212
  }
209
213
  /**
@@ -233,8 +237,16 @@ class SwitchBotPlatform {
233
237
  throw new Error('pluginConfig.credentials is not an object');
234
238
  }
235
239
  // 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.');
240
+ if (!this.config.credentials.secret) {
241
+ // eslint-disable-next-line no-useless-escape, max-len
242
+ 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');
243
+ // eslint-disable-next-line no-useless-escape
244
+ this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
245
+ }
246
+ else {
247
+ // eslint-disable-next-line no-useless-escape, max-len
248
+ 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.');
249
+ }
238
250
  // set the refresh token
239
251
  pluginConfig.credentials.token = this.config.credentials?.openToken;
240
252
  pluginConfig.credentials.openToken = 'Delete';
@@ -276,7 +288,7 @@ class SwitchBotPlatform {
276
288
  };
277
289
  const req = https_1.default.request(options, (res) => {
278
290
  this.debugLog(`statusCode: ${res.statusCode}`);
279
- this.debugLog(`headers: ${JSON.stringify(res.headers)}`);
291
+ this.debugLog(`headers: ${(0, super_stringify_1.default)(res.headers)}`);
280
292
  let rawData = '';
281
293
  res.on('data', (d) => {
282
294
  rawData += d;
@@ -285,7 +297,7 @@ class SwitchBotPlatform {
285
297
  res.on('end', () => {
286
298
  try {
287
299
  const devicesAPI = JSON.parse(rawData);
288
- this.debugLog(`devicesAPI: ${JSON.stringify(devicesAPI.body)}`);
300
+ this.debugLog(`devicesAPI: ${(0, super_stringify_1.default)(devicesAPI.body)}`);
289
301
  // SwitchBot Devices
290
302
  if (devicesAPI.body.deviceList.length !== 0) {
291
303
  this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
@@ -295,7 +307,7 @@ class SwitchBotPlatform {
295
307
  }
296
308
  const deviceLists = devicesAPI.body.deviceList;
297
309
  if (!this.config.options?.devices) {
298
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
310
+ this.debugLog(`SwitchBot Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
299
311
  const devices = deviceLists.map((v) => v);
300
312
  for (const device of devices) {
301
313
  if (device.deviceType) {
@@ -307,14 +319,14 @@ class SwitchBotPlatform {
307
319
  }
308
320
  }
309
321
  else if (this.config.credentials?.token && this.config.options.devices) {
310
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
322
+ this.debugLog(`SwitchBot Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
311
323
  const deviceConfigs = this.config.options?.devices;
312
324
  const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
313
325
  ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
314
326
  ...itm,
315
327
  }));
316
328
  const devices = mergeBydeviceId(deviceLists, deviceConfigs);
317
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
329
+ this.debugLog(`SwitchBot Devices: ${(0, super_stringify_1.default)(devices)}`);
318
330
  for (const device of devices) {
319
331
  if (device.deviceType) {
320
332
  if (device.configDeviceName) {
@@ -336,7 +348,7 @@ class SwitchBotPlatform {
336
348
  }
337
349
  const irDeviceLists = devicesAPI.body.infraredRemoteList;
338
350
  if (!this.config.options?.irdevices) {
339
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
351
+ this.debugLog(`IR Device Config Not Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
340
352
  const devices = irDeviceLists.map((v) => v);
341
353
  for (const device of devices) {
342
354
  if (device.remoteType) {
@@ -345,14 +357,14 @@ class SwitchBotPlatform {
345
357
  }
346
358
  }
347
359
  else {
348
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
360
+ this.debugLog(`IR Device Config Set: ${(0, super_stringify_1.default)(this.config.options?.irdevices)}`);
349
361
  const irDeviceConfig = this.config.options?.irdevices;
350
362
  const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
351
363
  ...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
352
364
  ...itm,
353
365
  }));
354
366
  const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
355
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
367
+ this.debugLog(`IR Devices: ${(0, super_stringify_1.default)(devices)}`);
356
368
  for (const device of devices) {
357
369
  if (device.remoteType) {
358
370
  this.createIRDevice(device);
@@ -371,7 +383,7 @@ class SwitchBotPlatform {
371
383
  req.end();
372
384
  }
373
385
  else if (!this.config.credentials?.token && this.config.options?.devices) {
374
- this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
386
+ this.debugLog(`SwitchBot Device Manual Config Set: ${(0, super_stringify_1.default)(this.config.options?.devices)}`);
375
387
  const deviceConfigs = this.config.options?.devices;
376
388
  const devices = deviceConfigs.map((v) => v);
377
389
  for (const device of devices) {
@@ -432,10 +444,10 @@ class SwitchBotPlatform {
432
444
  this.errorLog('Failed to Discover Devices');
433
445
  }
434
446
  if (this.platformLogging === 'debug') {
435
- this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
447
+ this.errorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
436
448
  }
437
449
  if (this.platformLogging === 'debugMode') {
438
- this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
450
+ this.errorLog(`Failed to Discover Devices, Error: ${(0, super_stringify_1.default)(e)}`);
439
451
  }
440
452
  }
441
453
  createDevice(device) {
@@ -568,25 +580,6 @@ class SwitchBotPlatform {
568
580
  this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
569
581
  }
570
582
  }
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
583
  async createHumidifier(device) {
591
584
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
592
585
  // see if an accessory with the same uuid has already been registered and restored from
@@ -595,15 +588,14 @@ class SwitchBotPlatform {
595
588
  if (existingAccessory) {
596
589
  // the accessory already exists
597
590
  if (this.registerDevice(device)) {
598
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
599
591
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
600
- //existingAccessory.context.firmwareRevision = firmware;
601
592
  existingAccessory.context.model = device.deviceType;
602
593
  existingAccessory.context.deviceID = device.deviceId;
603
- existingAccessory.displayName = device.deviceName;
594
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
604
595
  existingAccessory.context.firmwareRevision = device.firmware;
605
596
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
606
- await this.connectionTypeExistingAccessory(device, existingAccessory);
597
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
598
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
607
599
  this.api.updatePlatformAccessories([existingAccessory]);
608
600
  // create the accessory handler for the restored accessory
609
601
  // this is imported from `platformAccessory.ts`
@@ -626,13 +618,13 @@ class SwitchBotPlatform {
626
618
  accessory.context.deviceID = device.deviceId;
627
619
  accessory.context.firmwareRevision = device.firmware;
628
620
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
629
- await this.connectionTypeNewAccessory(device, accessory);
621
+ accessory.context.connectionType = await this.connectionTypeNew(device);
630
622
  // create the accessory handler for the newly create accessory
631
623
  // this is imported from `platformAccessory.ts`
632
624
  new humidifier_1.Humidifier(this, accessory, device);
633
625
  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]);
626
+ // publish device externally or link the accessory to your platform
627
+ this.externalOrPlatform(device, accessory);
636
628
  this.accessories.push(accessory);
637
629
  }
638
630
  else {
@@ -647,15 +639,15 @@ class SwitchBotPlatform {
647
639
  if (existingAccessory) {
648
640
  // the accessory already exists
649
641
  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));
642
+ this.debugLog((0, super_stringify_1.default)(device.bot?.mode));
652
643
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
653
644
  existingAccessory.context.model = device.deviceType;
654
645
  existingAccessory.context.deviceID = device.deviceId;
655
- existingAccessory.displayName = device.deviceName;
646
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
656
647
  existingAccessory.context.firmwareRevision = device.firmware;
657
648
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
658
- await this.connectionTypeExistingAccessory(device, existingAccessory);
649
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
650
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
659
651
  this.api.updatePlatformAccessories([existingAccessory]);
660
652
  // create the accessory handler for the restored accessory
661
653
  // this is imported from `platformAccessory.ts`
@@ -669,7 +661,7 @@ class SwitchBotPlatform {
669
661
  else if (this.registerDevice(device)) {
670
662
  // the accessory does not yet exist, so we need to create it
671
663
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
672
- this.debugLog(JSON.stringify(device.bot?.mode));
664
+ this.debugLog((0, super_stringify_1.default)(device.bot?.mode));
673
665
  // create a new accessory
674
666
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
675
667
  // store a copy of the device object in the `accessory.context`
@@ -679,14 +671,14 @@ class SwitchBotPlatform {
679
671
  accessory.context.deviceID = device.deviceId;
680
672
  accessory.context.firmwareRevision = device.firmware;
681
673
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
682
- await this.connectionTypeNewAccessory(device, accessory);
674
+ accessory.context.connectionType = await this.connectionTypeNew(device);
683
675
  // accessory.context.firmwareRevision = findaccessories.accessoryAttribute.softwareRevision;
684
676
  // create the accessory handler for the newly create accessory
685
677
  // this is imported from `platformAccessory.ts`
686
678
  new bot_1.Bot(this, accessory, device);
687
679
  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]);
680
+ // publish device externally or link the accessory to your platform
681
+ this.externalOrPlatform(device, accessory);
690
682
  this.accessories.push(accessory);
691
683
  }
692
684
  else {
@@ -701,14 +693,14 @@ class SwitchBotPlatform {
701
693
  if (existingAccessory) {
702
694
  // the accessory already exists
703
695
  if (this.registerDevice(device)) {
704
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
705
696
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
706
697
  existingAccessory.context.model = device.deviceType;
707
698
  existingAccessory.context.deviceID = device.deviceId;
708
- existingAccessory.displayName = device.deviceName;
699
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
709
700
  existingAccessory.context.firmwareRevision = device.firmware;
710
701
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
711
- await this.connectionTypeExistingAccessory(device, existingAccessory);
702
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
703
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
712
704
  this.api.updatePlatformAccessories([existingAccessory]);
713
705
  // create the accessory handler for the restored accessory
714
706
  // this is imported from `platformAccessory.ts`
@@ -731,13 +723,13 @@ class SwitchBotPlatform {
731
723
  accessory.context.deviceID = device.deviceId;
732
724
  accessory.context.firmwareRevision = device.firmware;
733
725
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
734
- await this.connectionTypeNewAccessory(device, accessory);
726
+ accessory.context.connectionType = await this.connectionTypeNew(device);
735
727
  // create the accessory handler for the newly create accessory
736
728
  // this is imported from `platformAccessory.ts`
737
729
  new meter_1.Meter(this, accessory, device);
738
730
  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]);
731
+ // publish device externally or link the accessory to your platform
732
+ this.externalOrPlatform(device, accessory);
741
733
  this.accessories.push(accessory);
742
734
  }
743
735
  else {
@@ -752,14 +744,14 @@ class SwitchBotPlatform {
752
744
  if (existingAccessory) {
753
745
  // the accessory already exists
754
746
  if (this.registerDevice(device)) {
755
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
756
747
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
757
748
  existingAccessory.context.model = device.deviceType;
758
749
  existingAccessory.context.deviceID = device.deviceId;
759
- existingAccessory.displayName = device.deviceName;
750
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
760
751
  existingAccessory.context.firmwareRevision = device.firmware;
761
752
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
762
- await this.connectionTypeExistingAccessory(device, existingAccessory);
753
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
754
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
763
755
  this.api.updatePlatformAccessories([existingAccessory]);
764
756
  // create the accessory handler for the restored accessory
765
757
  // this is imported from `platformAccessory.ts`
@@ -782,13 +774,13 @@ class SwitchBotPlatform {
782
774
  accessory.context.deviceID = device.deviceId;
783
775
  accessory.context.firmwareRevision = device.firmware;
784
776
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
785
- await this.connectionTypeNewAccessory(device, accessory);
777
+ accessory.context.connectionType = await this.connectionTypeNew(device);
786
778
  // create the accessory handler for the newly create accessory
787
779
  // this is imported from `platformAccessory.ts`
788
780
  new meterplus_1.MeterPlus(this, accessory, device);
789
781
  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]);
782
+ // publish device externally or link the accessory to your platform
783
+ this.externalOrPlatform(device, accessory);
792
784
  this.accessories.push(accessory);
793
785
  }
794
786
  else {
@@ -803,14 +795,14 @@ class SwitchBotPlatform {
803
795
  if (existingAccessory) {
804
796
  // the accessory already exists
805
797
  if (this.registerDevice(device)) {
806
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
807
798
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
808
799
  existingAccessory.context.model = device.deviceType;
809
800
  existingAccessory.context.deviceID = device.deviceId;
810
- existingAccessory.displayName = device.deviceName;
801
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
811
802
  existingAccessory.context.firmwareRevision = device.firmware;
812
803
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
813
- await this.connectionTypeExistingAccessory(device, existingAccessory);
804
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
805
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
814
806
  this.api.updatePlatformAccessories([existingAccessory]);
815
807
  // create the accessory handler for the restored accessory
816
808
  // this is imported from `platformAccessory.ts`
@@ -833,13 +825,13 @@ class SwitchBotPlatform {
833
825
  accessory.context.deviceID = device.deviceId;
834
826
  accessory.context.firmwareRevision = device.firmware;
835
827
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
836
- await this.connectionTypeNewAccessory(device, accessory);
828
+ accessory.context.connectionType = await this.connectionTypeNew(device);
837
829
  // create the accessory handler for the newly create accessory
838
830
  // this is imported from `platformAccessory.ts`
839
831
  new motion_1.Motion(this, accessory, device);
840
832
  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]);
833
+ // publish device externally or link the accessory to your platform
834
+ this.externalOrPlatform(device, accessory);
843
835
  this.accessories.push(accessory);
844
836
  }
845
837
  else {
@@ -854,14 +846,14 @@ class SwitchBotPlatform {
854
846
  if (existingAccessory) {
855
847
  // the accessory already exists
856
848
  if (this.registerDevice(device)) {
857
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
858
849
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
859
850
  existingAccessory.context.model = device.deviceType;
860
851
  existingAccessory.context.deviceID = device.deviceId;
861
- existingAccessory.displayName = device.deviceName;
852
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
862
853
  existingAccessory.context.firmwareRevision = device.firmware;
863
854
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
864
- await this.connectionTypeExistingAccessory(device, existingAccessory);
855
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
856
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
865
857
  this.api.updatePlatformAccessories([existingAccessory]);
866
858
  // create the accessory handler for the restored accessory
867
859
  // this is imported from `platformAccessory.ts`
@@ -884,13 +876,13 @@ class SwitchBotPlatform {
884
876
  accessory.context.deviceID = device.deviceId;
885
877
  accessory.context.firmwareRevision = device.firmware;
886
878
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
887
- await this.connectionTypeNewAccessory(device, accessory);
879
+ accessory.context.connectionType = await this.connectionTypeNew(device);
888
880
  // create the accessory handler for the newly create accessory
889
881
  // this is imported from `platformAccessory.ts`
890
882
  new contact_1.Contact(this, accessory, device);
891
883
  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]);
884
+ // publish device externally or link the accessory to your platform
885
+ this.externalOrPlatform(device, accessory);
894
886
  this.accessories.push(accessory);
895
887
  }
896
888
  else {
@@ -905,14 +897,14 @@ class SwitchBotPlatform {
905
897
  if (existingAccessory) {
906
898
  // the accessory already exists
907
899
  if (this.isCurtainGrouped(device)) {
908
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
909
900
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
910
901
  existingAccessory.context.model = device.deviceType;
911
902
  existingAccessory.context.deviceID = device.deviceId;
912
- existingAccessory.displayName = device.deviceName;
903
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
913
904
  existingAccessory.context.firmwareRevision = device.firmware;
914
905
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
915
- await this.connectionTypeExistingAccessory(device, existingAccessory);
906
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
907
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
916
908
  this.api.updatePlatformAccessories([existingAccessory]);
917
909
  // create the accessory handler for the restored accessory
918
910
  // this is imported from `platformAccessory.ts`
@@ -947,13 +939,13 @@ class SwitchBotPlatform {
947
939
  accessory.context.deviceID = device.deviceId;
948
940
  accessory.context.firmwareRevision = device.firmware;
949
941
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
950
- await this.connectionTypeNewAccessory(device, accessory);
942
+ accessory.context.connectionType = await this.connectionTypeNew(device);
951
943
  // create the accessory handler for the newly create accessory
952
944
  // this is imported from `platformAccessory.ts`
953
945
  new curtain_1.Curtain(this, accessory, device);
954
946
  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]);
947
+ // publish device externally or link the accessory to your platform
948
+ this.externalOrPlatform(device, accessory);
957
949
  this.accessories.push(accessory);
958
950
  }
959
951
  else {
@@ -980,14 +972,14 @@ class SwitchBotPlatform {
980
972
  if (existingAccessory) {
981
973
  // the accessory already exists
982
974
  if (this.registerDevice(device)) {
983
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
984
975
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
985
976
  existingAccessory.context.model = device.deviceType;
986
977
  existingAccessory.context.deviceID = device.deviceId;
987
- existingAccessory.displayName = device.deviceName;
978
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
988
979
  existingAccessory.context.firmwareRevision = device.firmware;
989
980
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
990
- await this.connectionTypeExistingAccessory(device, existingAccessory);
981
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
982
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
991
983
  this.api.updatePlatformAccessories([existingAccessory]);
992
984
  // create the accessory handler for the restored accessory
993
985
  // this is imported from `platformAccessory.ts`
@@ -1010,13 +1002,13 @@ class SwitchBotPlatform {
1010
1002
  accessory.context.deviceID = device.deviceId;
1011
1003
  accessory.context.firmwareRevision = device.firmware;
1012
1004
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1013
- await this.connectionTypeNewAccessory(device, accessory);
1005
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1014
1006
  // create the accessory handler for the newly create accessory
1015
1007
  // this is imported from `platformAccessory.ts`
1016
1008
  new plug_1.Plug(this, accessory, device);
1017
1009
  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]);
1010
+ // publish device externally or link the accessory to your platform
1011
+ this.externalOrPlatform(device, accessory);
1020
1012
  this.accessories.push(accessory);
1021
1013
  }
1022
1014
  else {
@@ -1031,14 +1023,14 @@ class SwitchBotPlatform {
1031
1023
  if (existingAccessory) {
1032
1024
  // the accessory already exists
1033
1025
  if (this.registerDevice(device)) {
1034
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1035
1026
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1036
1027
  existingAccessory.context.model = device.deviceType;
1037
1028
  existingAccessory.context.deviceID = device.deviceId;
1038
- existingAccessory.displayName = device.deviceName;
1029
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1039
1030
  existingAccessory.context.firmwareRevision = device.firmware;
1040
1031
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1041
- await this.connectionTypeExistingAccessory(device, existingAccessory);
1032
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1033
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1042
1034
  this.api.updatePlatformAccessories([existingAccessory]);
1043
1035
  // create the accessory handler for the restored accessory
1044
1036
  // this is imported from `platformAccessory.ts`
@@ -1061,13 +1053,13 @@ class SwitchBotPlatform {
1061
1053
  accessory.context.deviceID = device.deviceId;
1062
1054
  accessory.context.firmwareRevision = device.firmware;
1063
1055
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1064
- await this.connectionTypeNewAccessory(device, accessory);
1056
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1065
1057
  // create the accessory handler for the newly create accessory
1066
1058
  // this is imported from `platformAccessory.ts`
1067
1059
  new lock_1.Lock(this, accessory, device);
1068
1060
  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]);
1061
+ // publish device externally or link the accessory to your platform
1062
+ this.externalOrPlatform(device, accessory);
1071
1063
  this.accessories.push(accessory);
1072
1064
  }
1073
1065
  else {
@@ -1082,14 +1074,14 @@ class SwitchBotPlatform {
1082
1074
  if (existingAccessory) {
1083
1075
  // the accessory already exists
1084
1076
  if (this.registerDevice(device)) {
1085
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1086
1077
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1087
1078
  existingAccessory.context.model = device.deviceType;
1088
1079
  existingAccessory.context.deviceID = device.deviceId;
1089
- existingAccessory.displayName = device.deviceName;
1080
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1090
1081
  existingAccessory.context.firmwareRevision = device.firmware;
1091
1082
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1092
- await this.connectionTypeExistingAccessory(device, existingAccessory);
1083
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1084
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1093
1085
  this.api.updatePlatformAccessories([existingAccessory]);
1094
1086
  // create the accessory handler for the restored accessory
1095
1087
  // this is imported from `platformAccessory.ts`
@@ -1112,13 +1104,13 @@ class SwitchBotPlatform {
1112
1104
  accessory.context.deviceID = device.deviceId;
1113
1105
  accessory.context.firmwareRevision = device.firmware;
1114
1106
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1115
- await this.connectionTypeNewAccessory(device, accessory);
1107
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1116
1108
  // create the accessory handler for the newly create accessory
1117
1109
  // this is imported from `platformAccessory.ts`
1118
1110
  new colorbulb_1.ColorBulb(this, accessory, device);
1119
1111
  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]);
1112
+ // publish device externally or link the accessory to your platform
1113
+ this.externalOrPlatform(device, accessory);
1122
1114
  this.accessories.push(accessory);
1123
1115
  }
1124
1116
  else {
@@ -1133,14 +1125,14 @@ class SwitchBotPlatform {
1133
1125
  if (existingAccessory) {
1134
1126
  // the accessory already exists
1135
1127
  if (this.registerDevice(device)) {
1136
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1137
1128
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1138
1129
  existingAccessory.context.model = device.deviceType;
1139
1130
  existingAccessory.context.deviceID = device.deviceId;
1140
- existingAccessory.displayName = device.deviceName;
1131
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1141
1132
  existingAccessory.context.firmwareRevision = device.firmware;
1142
1133
  existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1143
- await this.connectionTypeExistingAccessory(device, existingAccessory);
1134
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1135
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1144
1136
  this.api.updatePlatformAccessories([existingAccessory]);
1145
1137
  // create the accessory handler for the restored accessory
1146
1138
  // this is imported from `platformAccessory.ts`
@@ -1163,13 +1155,13 @@ class SwitchBotPlatform {
1163
1155
  accessory.context.deviceID = device.deviceId;
1164
1156
  accessory.context.firmwareRevision = device.firmware;
1165
1157
  accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1166
- await this.connectionTypeNewAccessory(device, accessory);
1158
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1167
1159
  // create the accessory handler for the newly create accessory
1168
1160
  // this is imported from `platformAccessory.ts`
1169
1161
  new striplight_1.StripLight(this, accessory, device);
1170
1162
  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]);
1163
+ // publish device externally or link the accessory to your platform
1164
+ this.externalOrPlatform(device, accessory);
1173
1165
  this.accessories.push(accessory);
1174
1166
  }
1175
1167
  else {
@@ -1182,14 +1174,14 @@ class SwitchBotPlatform {
1182
1174
  // the cached devices we stored in the `configureAccessory` method above
1183
1175
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1184
1176
  if (!device.hide_device && existingAccessory) {
1185
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1186
1177
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1187
1178
  existingAccessory.context.model = device.remoteType;
1188
1179
  existingAccessory.context.deviceID = device.deviceId;
1189
- existingAccessory.displayName = device.deviceName;
1180
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1190
1181
  existingAccessory.context.firmwareRevision = device.firmware;
1191
1182
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1192
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1183
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1184
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1193
1185
  this.api.updatePlatformAccessories([existingAccessory]);
1194
1186
  // create the accessory handler for the restored accessory
1195
1187
  // this is imported from `platformAccessory.ts`
@@ -1208,7 +1200,7 @@ class SwitchBotPlatform {
1208
1200
  accessory.context.deviceID = device.deviceId;
1209
1201
  accessory.context.firmwareRevision = device.firmware;
1210
1202
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1211
- await this.connectionTypeNewIRAccessory(accessory);
1203
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1212
1204
  // create the accessory handler for the newly create accessory
1213
1205
  // this is imported from `platformAccessory.ts`
1214
1206
  new tv_1.TV(this, accessory, device);
@@ -1218,7 +1210,7 @@ class SwitchBotPlatform {
1218
1210
  * Only one TV can exist per bridge, to bypass this limitation, you should
1219
1211
  * publish your TV as an external accessory.
1220
1212
  */
1221
- this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]);
1213
+ this.externalAccessory(accessory);
1222
1214
  this.accessories.push(accessory);
1223
1215
  }
1224
1216
  else {
@@ -1233,14 +1225,14 @@ class SwitchBotPlatform {
1233
1225
  if (existingAccessory) {
1234
1226
  // the accessory already exists
1235
1227
  if (!device.hide_device && device.hubDeviceId) {
1236
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1237
1228
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1238
1229
  existingAccessory.context.model = device.remoteType;
1239
1230
  existingAccessory.context.deviceID = device.deviceId;
1240
- existingAccessory.displayName = device.deviceName;
1231
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1241
1232
  existingAccessory.context.firmwareRevision = device.firmware;
1242
1233
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1243
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1234
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1235
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1244
1236
  this.api.updatePlatformAccessories([existingAccessory]);
1245
1237
  // create the accessory handler for the restored accessory
1246
1238
  // this is imported from `platformAccessory.ts`
@@ -1263,13 +1255,13 @@ class SwitchBotPlatform {
1263
1255
  accessory.context.deviceID = device.deviceId;
1264
1256
  accessory.context.firmwareRevision = device.firmware;
1265
1257
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1266
- await this.connectionTypeNewIRAccessory(accessory);
1258
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1267
1259
  // create the accessory handler for the newly create accessory
1268
1260
  // this is imported from `platformAccessory.ts`
1269
1261
  new fan_1.Fan(this, accessory, device);
1270
1262
  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]);
1263
+ // publish device externally or link the accessory to your platform
1264
+ this.externalOrPlatform(device, accessory);
1273
1265
  this.accessories.push(accessory);
1274
1266
  }
1275
1267
  else {
@@ -1284,14 +1276,14 @@ class SwitchBotPlatform {
1284
1276
  if (existingAccessory) {
1285
1277
  // the accessory already exists
1286
1278
  if (!device.hide_device && device.hubDeviceId) {
1287
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1288
1279
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1289
1280
  existingAccessory.context.model = device.remoteType;
1290
1281
  existingAccessory.context.deviceID = device.deviceId;
1291
- existingAccessory.displayName = device.deviceName;
1282
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1292
1283
  existingAccessory.context.firmwareRevision = device.firmware;
1293
1284
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1294
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1285
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1286
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1295
1287
  this.api.updatePlatformAccessories([existingAccessory]);
1296
1288
  // create the accessory handler for the restored accessory
1297
1289
  // this is imported from `platformAccessory.ts`
@@ -1314,13 +1306,13 @@ class SwitchBotPlatform {
1314
1306
  accessory.context.deviceID = device.deviceId;
1315
1307
  accessory.context.firmwareRevision = device.firmware;
1316
1308
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1317
- await this.connectionTypeNewIRAccessory(accessory);
1309
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1318
1310
  // create the accessory handler for the newly create accessory
1319
1311
  // this is imported from `platformAccessory.ts`
1320
1312
  new light_1.Light(this, accessory, device);
1321
1313
  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]);
1314
+ // publish device externally or link the accessory to your platform
1315
+ this.externalOrPlatform(device, accessory);
1324
1316
  this.accessories.push(accessory);
1325
1317
  }
1326
1318
  else {
@@ -1335,14 +1327,14 @@ class SwitchBotPlatform {
1335
1327
  if (existingAccessory) {
1336
1328
  // the accessory already exists
1337
1329
  if (!device.hide_device && device.hubDeviceId) {
1338
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1339
1330
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1340
1331
  existingAccessory.context.model = device.remoteType;
1341
1332
  existingAccessory.context.deviceID = device.deviceId;
1342
- existingAccessory.displayName = device.deviceName;
1333
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1343
1334
  existingAccessory.context.firmwareRevision = device.firmware;
1344
1335
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1345
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1336
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1337
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1346
1338
  this.api.updatePlatformAccessories([existingAccessory]);
1347
1339
  // create the accessory handler for the restored accessory
1348
1340
  // this is imported from `platformAccessory.ts`
@@ -1365,13 +1357,13 @@ class SwitchBotPlatform {
1365
1357
  accessory.context.deviceID = device.deviceId;
1366
1358
  accessory.context.firmwareRevision = device.firmware;
1367
1359
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1368
- await this.connectionTypeNewIRAccessory(accessory);
1360
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1369
1361
  // create the accessory handler for the newly create accessory
1370
1362
  // this is imported from `platformAccessory.ts`
1371
1363
  new airconditioner_1.AirConditioner(this, accessory, device);
1372
1364
  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]);
1365
+ // publish device externally or link the accessory to your platform
1366
+ this.externalOrPlatform(device, accessory);
1375
1367
  this.accessories.push(accessory);
1376
1368
  }
1377
1369
  else {
@@ -1386,14 +1378,14 @@ class SwitchBotPlatform {
1386
1378
  if (existingAccessory) {
1387
1379
  // the accessory already exists
1388
1380
  if (!device.hide_device && device.hubDeviceId) {
1389
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1390
1381
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1391
1382
  existingAccessory.context.model = device.remoteType;
1392
1383
  existingAccessory.context.deviceID = device.deviceId;
1393
- existingAccessory.displayName = device.deviceName;
1384
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1394
1385
  existingAccessory.context.firmwareRevision = device.firmware;
1395
1386
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1396
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1387
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1388
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1397
1389
  this.api.updatePlatformAccessories([existingAccessory]);
1398
1390
  // create the accessory handler for the restored accessory
1399
1391
  // this is imported from `platformAccessory.ts`
@@ -1416,13 +1408,13 @@ class SwitchBotPlatform {
1416
1408
  accessory.context.deviceID = device.deviceId;
1417
1409
  accessory.context.firmwareRevision = device.firmware;
1418
1410
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1419
- await this.connectionTypeNewIRAccessory(accessory);
1411
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1420
1412
  // create the accessory handler for the newly create accessory
1421
1413
  // this is imported from `platformAccessory.ts`
1422
1414
  new airpurifier_1.AirPurifier(this, accessory, device);
1423
1415
  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]);
1416
+ // publish device externally or link the accessory to your platform
1417
+ this.externalOrPlatform(device, accessory);
1426
1418
  this.accessories.push(accessory);
1427
1419
  }
1428
1420
  else {
@@ -1437,14 +1429,14 @@ class SwitchBotPlatform {
1437
1429
  if (existingAccessory) {
1438
1430
  // the accessory already exists
1439
1431
  if (!device.hide_device && device.hubDeviceId) {
1440
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1441
1432
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1442
1433
  existingAccessory.context.model = device.remoteType;
1443
1434
  existingAccessory.context.deviceID = device.deviceId;
1444
- existingAccessory.displayName = device.deviceName;
1435
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1445
1436
  existingAccessory.context.firmwareRevision = device.firmware;
1446
1437
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1447
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1438
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1439
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1448
1440
  this.api.updatePlatformAccessories([existingAccessory]);
1449
1441
  // create the accessory handler for the restored accessory
1450
1442
  // this is imported from `platformAccessory.ts`
@@ -1467,13 +1459,13 @@ class SwitchBotPlatform {
1467
1459
  accessory.context.deviceID = device.deviceId;
1468
1460
  accessory.context.firmwareRevision = device.firmware;
1469
1461
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1470
- await this.connectionTypeNewIRAccessory(accessory);
1462
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1471
1463
  // create the accessory handler for the newly create accessory
1472
1464
  // this is imported from `platformAccessory.ts`
1473
1465
  new waterheater_1.WaterHeater(this, accessory, device);
1474
1466
  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]);
1467
+ // publish device externally or link the accessory to your platform
1468
+ this.externalOrPlatform(device, accessory);
1477
1469
  this.accessories.push(accessory);
1478
1470
  }
1479
1471
  else {
@@ -1488,14 +1480,14 @@ class SwitchBotPlatform {
1488
1480
  if (existingAccessory) {
1489
1481
  // the accessory already exists
1490
1482
  if (!device.hide_device && device.hubDeviceId) {
1491
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1492
1483
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1493
1484
  existingAccessory.context.model = device.remoteType;
1494
1485
  existingAccessory.context.deviceID = device.deviceId;
1495
- existingAccessory.displayName = device.deviceName;
1486
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1496
1487
  existingAccessory.context.firmwareRevision = device.firmware;
1497
1488
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1498
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1489
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1490
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1499
1491
  this.api.updatePlatformAccessories([existingAccessory]);
1500
1492
  // create the accessory handler for the restored accessory
1501
1493
  // this is imported from `platformAccessory.ts`
@@ -1518,13 +1510,13 @@ class SwitchBotPlatform {
1518
1510
  accessory.context.deviceID = device.deviceId;
1519
1511
  accessory.context.firmwareRevision = device.firmware;
1520
1512
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1521
- await this.connectionTypeNewIRAccessory(accessory);
1513
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1522
1514
  // create the accessory handler for the newly create accessory
1523
1515
  // this is imported from `platformAccessory.ts`
1524
1516
  new vacuumcleaner_1.VacuumCleaner(this, accessory, device);
1525
1517
  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]);
1518
+ // publish device externally or link the accessory to your platform
1519
+ this.externalOrPlatform(device, accessory);
1528
1520
  this.accessories.push(accessory);
1529
1521
  }
1530
1522
  else {
@@ -1539,14 +1531,14 @@ class SwitchBotPlatform {
1539
1531
  if (existingAccessory) {
1540
1532
  // the accessory already exists
1541
1533
  if (!device.hide_device && device.hubDeviceId) {
1542
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1543
1534
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1544
1535
  existingAccessory.context.model = device.remoteType;
1545
1536
  existingAccessory.context.deviceID = device.deviceId;
1546
- existingAccessory.displayName = device.deviceName;
1537
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1547
1538
  existingAccessory.context.firmwareRevision = device.firmware;
1548
1539
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1549
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1540
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1541
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1550
1542
  this.api.updatePlatformAccessories([existingAccessory]);
1551
1543
  // create the accessory handler for the restored accessory
1552
1544
  // this is imported from `platformAccessory.ts`
@@ -1569,13 +1561,13 @@ class SwitchBotPlatform {
1569
1561
  accessory.context.deviceID = device.deviceId;
1570
1562
  accessory.context.firmwareRevision = device.firmware;
1571
1563
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1572
- await this.connectionTypeNewIRAccessory(accessory);
1564
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1573
1565
  // create the accessory handler for the newly create accessory
1574
1566
  // this is imported from `platformAccessory.ts`
1575
1567
  new camera_1.Camera(this, accessory, device);
1576
1568
  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]);
1569
+ // publish device externally or link the accessory to your platform
1570
+ this.externalOrPlatform(device, accessory);
1579
1571
  this.accessories.push(accessory);
1580
1572
  }
1581
1573
  else {
@@ -1590,14 +1582,14 @@ class SwitchBotPlatform {
1590
1582
  if (existingAccessory) {
1591
1583
  // the accessory already exists
1592
1584
  if (!device.hide_device && device.hubDeviceId) {
1593
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1594
1585
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1595
1586
  existingAccessory.context.model = device.remoteType;
1596
1587
  existingAccessory.context.deviceID = device.deviceId;
1597
- existingAccessory.displayName = device.deviceName;
1588
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1598
1589
  existingAccessory.context.firmwareRevision = device.firmware;
1599
1590
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1600
- await this.connectionTypeExistingIRAccessory(existingAccessory);
1591
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1592
+ existingAccessory.context.connectionType = await this.connectionTypeExisting(device);
1601
1593
  this.api.updatePlatformAccessories([existingAccessory]);
1602
1594
  // create the accessory handler for the restored accessory
1603
1595
  // this is imported from `platformAccessory.ts`
@@ -1620,40 +1612,76 @@ class SwitchBotPlatform {
1620
1612
  accessory.context.deviceID = device.deviceId;
1621
1613
  accessory.context.firmwareRevision = device.firmware;
1622
1614
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1623
- await this.connectionTypeNewIRAccessory(accessory);
1615
+ accessory.context.connectionType = await this.connectionTypeNew(device);
1624
1616
  // create the accessory handler for the newly create accessory
1625
1617
  // this is imported from `platformAccessory.ts`
1626
1618
  new other_1.Others(this, accessory, device);
1627
1619
  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]);
1620
+ // publish device externally or link the accessory to your platform
1621
+ this.externalOrPlatform(device, accessory);
1630
1622
  this.accessories.push(accessory);
1631
1623
  }
1632
1624
  else {
1633
1625
  this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1634
1626
  }
1635
1627
  }
1636
- async connectionTypeNewAccessory(device, accessory) {
1637
- if (device.ble) {
1638
- accessory.context.connectionType = 'BLE';
1628
+ connectionTypeNew(device) {
1629
+ let connectionType = '';
1630
+ if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
1631
+ connectionType = 'OpenAPI';
1639
1632
  }
1640
1633
  else {
1641
- accessory.context.connectionType = 'OpenAPI';
1634
+ connectionType = device.connectionType;
1642
1635
  }
1636
+ return connectionType;
1637
+ }
1638
+ connectionTypeExisting(device) {
1639
+ return device.connectionType || 'OpenAPI';
1643
1640
  }
1644
- async connectionTypeExistingAccessory(device, existingAccessory) {
1645
- if (device.ble) {
1646
- existingAccessory.context.connectionType = 'BLE';
1641
+ registerDevice(device) {
1642
+ if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI & BLE') {
1643
+ this.registeringDevice = true;
1644
+ this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
1645
+ }
1646
+ else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1647
+ && !device.enableCloudService && device.connectionType === 'BLE') {
1648
+ this.registeringDevice = true;
1649
+ this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
1650
+ }
1651
+ else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
1652
+ this.registeringDevice = true;
1653
+ this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
1654
+ }
1655
+ else if (!device.hide_device && device.enableCloudService && device.connectionType === 'Disable') {
1656
+ this.registeringDevice = true;
1657
+ this.debugLog(`Device: ${device.deviceName} Device connection Disabled, will continue to display in HomeKit`);
1658
+ }
1659
+ else if (!device.connectionType) {
1660
+ this.registeringDevice = false;
1661
+ this.debugLog(`Device: ${device.deviceName} Connection Type not Set, will not display in HomeKit`);
1662
+ }
1663
+ else if (device.hide_device) {
1664
+ this.registeringDevice = false;
1665
+ this.debugLog(`Device: ${device.deviceName} Device Set to Hidden, will not display in HomeKit`);
1647
1666
  }
1648
1667
  else {
1649
- existingAccessory.context.connectionType = 'OpenAPI';
1668
+ this.registeringDevice = false;
1669
+ this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
1650
1670
  }
1671
+ return this.registeringDevice;
1651
1672
  }
1652
- async connectionTypeNewIRAccessory(accessory) {
1653
- accessory.context.connectionType = 'IR wirth OpenAPI';
1673
+ async externalOrPlatform(device, accessory) {
1674
+ this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
1675
+ if (device.external) {
1676
+ this.warnLog(`${accessory.displayName} External Accessory Mode`);
1677
+ this.externalAccessory(accessory);
1678
+ }
1679
+ else {
1680
+ this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
1681
+ }
1654
1682
  }
1655
- async connectionTypeExistingIRAccessory(existingAccessory) {
1656
- existingAccessory.context.connectionType = 'IR with OpenAPI';
1683
+ async externalAccessory(accessory) {
1684
+ this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]);
1657
1685
  }
1658
1686
  unregisterPlatformAccessories(existingAccessory) {
1659
1687
  // remove platform accessories when no longer present
@@ -1662,12 +1690,12 @@ class SwitchBotPlatform {
1662
1690
  }
1663
1691
  deviceListInfo(devices) {
1664
1692
  if (this.platformLogging?.includes('debug')) {
1665
- this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
1693
+ this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
1666
1694
  }
1667
1695
  }
1668
1696
  async deviceInfo(device) {
1669
1697
  if (this.platformLogging?.includes('debug')) {
1670
- this.warnLog(JSON.stringify(device));
1698
+ this.warnLog((0, super_stringify_1.default)(device));
1671
1699
  const t = Date.now();
1672
1700
  const nonce = 'requestID';
1673
1701
  const data = this.config.credentials?.token + t + nonce;
@@ -1699,10 +1727,10 @@ class SwitchBotPlatform {
1699
1727
  req.end();
1700
1728
  this.deviceStatus = req;
1701
1729
  if (this.deviceStatus.message === 'success') {
1702
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1730
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
1703
1731
  }
1704
1732
  else {
1705
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
1733
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus.message)}`);
1706
1734
  this.warnLog('Unable to retreive deviceInfoStatus.');
1707
1735
  }
1708
1736
  }