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