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