@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.20
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.
- package/CHANGELOG.md +8 -1
- package/README.md +1 -2
- package/config.schema.json +75 -20
- package/dist/device/bot.d.ts +32 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +646 -648
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +34 -19
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +429 -304
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -7
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +288 -230
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +519 -489
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +22 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +415 -360
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +22 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +253 -147
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +21 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +325 -255
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +23 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +346 -208
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +17 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +261 -209
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +24 -16
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +267 -242
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +51 -16
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +527 -185
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +7 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +261 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +137 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +116 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +143 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +120 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +128 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +10 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +126 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +115 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +115 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +3 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +203 -200
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +15 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -10
- package/src/device/bot.ts +641 -657
- package/src/device/colorbulb.ts +440 -339
- package/src/device/contact.ts +289 -233
- package/src/device/curtain.ts +523 -503
- package/src/device/humidifier.ts +421 -396
- package/src/device/lock.ts +257 -147
- package/src/device/meter.ts +335 -268
- package/src/device/meterplus.ts +354 -213
- package/src/device/motion.ts +264 -213
- package/src/device/plug.ts +270 -251
- package/src/device/striplight.ts +552 -207
- package/src/irdevice/airconditioner.ts +263 -241
- package/src/irdevice/airpurifier.ts +132 -103
- package/src/irdevice/camera.ts +112 -85
- package/src/irdevice/fan.ts +138 -106
- package/src/irdevice/light.ts +116 -103
- package/src/irdevice/other.ts +124 -97
- package/src/irdevice/tv.ts +123 -93
- package/src/irdevice/vacuumcleaner.ts +112 -89
- package/src/irdevice/waterheater.ts +111 -89
- package/src/platform.ts +195 -216
- 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(
|
|
65
|
+
this.errorLog((0, super_stringify_1.default)(e.message));
|
|
65
66
|
if (this.platformLogging?.includes('debug')) {
|
|
66
|
-
this.errorLog(
|
|
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.',
|
|
93
|
+
this.errorLog('Failed to Discover Devices.', (0, super_stringify_1.default)(e.message));
|
|
89
94
|
if (this.platformLogging?.includes('debug')) {
|
|
90
|
-
this.errorLog(
|
|
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: ${
|
|
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.
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
}
|
|
193
|
+
if (!this.config.credentials) {
|
|
194
|
+
if (this.platformLogging?.includes('debug')) {
|
|
195
|
+
this.debugLog('Missing Credentials');
|
|
196
|
+
}
|
|
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');
|
|
191
202
|
}
|
|
192
|
-
|
|
203
|
+
}
|
|
204
|
+
if (this.config.credentials?.token) {
|
|
205
|
+
if (!this.config.credentials?.secret) {
|
|
193
206
|
if (this.platformLogging?.includes('debug')) {
|
|
194
|
-
this.errorLog('Missing
|
|
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.
|
|
237
|
-
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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
|
-
|
|
597
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
598
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
621
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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.
|
|
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
|
-
|
|
649
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
650
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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(
|
|
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
|
-
|
|
674
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
702
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
703
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
726
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
753
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
754
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
777
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
804
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
805
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
828
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
855
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
856
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
879
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
906
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
907
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
942
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
981
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
982
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1005
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1032
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1033
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1056
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1083
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1084
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1107
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1134
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1135
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1158
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1183
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1184
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1203
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1234
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1235
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1258
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1285
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1286
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1309
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1336
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1337
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1360
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1387
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1388
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1411
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1438
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1439
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1462
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1489
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1490
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1513
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1540
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1541
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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
|
-
|
|
1564
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1591
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1592
|
+
existingAccessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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,51 @@ 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
|
-
|
|
1615
|
+
accessory.context.connectionType = device.connectionType || 'OpenAPI';
|
|
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.
|
|
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
|
-
|
|
1637
|
-
if (device.
|
|
1638
|
-
|
|
1628
|
+
registerDevice(device) {
|
|
1629
|
+
if (!device.hide_device && device.enableCloudService && device.connectionType === 'Both') {
|
|
1630
|
+
this.registeringDevice = true;
|
|
1631
|
+
this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
|
|
1632
|
+
}
|
|
1633
|
+
else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
|
|
1634
|
+
&& !device.enableCloudService && device.connectionType === 'BLE') {
|
|
1635
|
+
this.registeringDevice = true;
|
|
1636
|
+
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
1637
|
+
}
|
|
1638
|
+
else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
|
|
1639
|
+
this.registeringDevice = true;
|
|
1640
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
1639
1641
|
}
|
|
1640
1642
|
else {
|
|
1641
|
-
|
|
1643
|
+
this.registeringDevice = false;
|
|
1644
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
|
|
1642
1645
|
}
|
|
1646
|
+
return this.registeringDevice;
|
|
1643
1647
|
}
|
|
1644
|
-
async
|
|
1645
|
-
|
|
1646
|
-
|
|
1648
|
+
async externalOrPlatform(device, accessory) {
|
|
1649
|
+
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
1650
|
+
if (device.external) {
|
|
1651
|
+
this.warnLog(`${accessory.displayName} External Accessory Mode`);
|
|
1652
|
+
this.externalAccessory(accessory);
|
|
1647
1653
|
}
|
|
1648
1654
|
else {
|
|
1649
|
-
|
|
1655
|
+
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
|
|
1650
1656
|
}
|
|
1651
1657
|
}
|
|
1652
|
-
async
|
|
1653
|
-
|
|
1654
|
-
}
|
|
1655
|
-
async connectionTypeExistingIRAccessory(existingAccessory) {
|
|
1656
|
-
existingAccessory.context.connectionType = 'IR with OpenAPI';
|
|
1658
|
+
async externalAccessory(accessory) {
|
|
1659
|
+
this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]);
|
|
1657
1660
|
}
|
|
1658
1661
|
unregisterPlatformAccessories(existingAccessory) {
|
|
1659
1662
|
// remove platform accessories when no longer present
|
|
@@ -1662,12 +1665,12 @@ class SwitchBotPlatform {
|
|
|
1662
1665
|
}
|
|
1663
1666
|
deviceListInfo(devices) {
|
|
1664
1667
|
if (this.platformLogging?.includes('debug')) {
|
|
1665
|
-
this.warnLog(`deviceListInfoStatus: ${
|
|
1668
|
+
this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
|
|
1666
1669
|
}
|
|
1667
1670
|
}
|
|
1668
1671
|
async deviceInfo(device) {
|
|
1669
1672
|
if (this.platformLogging?.includes('debug')) {
|
|
1670
|
-
this.warnLog(
|
|
1673
|
+
this.warnLog((0, super_stringify_1.default)(device));
|
|
1671
1674
|
const t = Date.now();
|
|
1672
1675
|
const nonce = 'requestID';
|
|
1673
1676
|
const data = this.config.credentials?.token + t + nonce;
|
|
@@ -1699,10 +1702,10 @@ class SwitchBotPlatform {
|
|
|
1699
1702
|
req.end();
|
|
1700
1703
|
this.deviceStatus = req;
|
|
1701
1704
|
if (this.deviceStatus.message === 'success') {
|
|
1702
|
-
this.warnLog(`${device.deviceName} deviceInfoStatus: ${
|
|
1705
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
1703
1706
|
}
|
|
1704
1707
|
else {
|
|
1705
|
-
this.warnLog(`${device.deviceName} deviceInfoStatus: ${
|
|
1708
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${(0, super_stringify_1.default)(this.deviceStatus.message)}`);
|
|
1706
1709
|
this.warnLog('Unable to retreive deviceInfoStatus.');
|
|
1707
1710
|
}
|
|
1708
1711
|
}
|