@switchbot/homebridge-switchbot 2.8.1-beta.1 → 2.8.1-beta.11
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/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +22 -13
- package/dist/device/bot.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +13 -19
- package/dist/device/hub.js.map +1 -1
- package/dist/device/meterplus.js +2 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +28 -17
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +21 -13
- package/src/device/hub.ts +13 -21
- package/src/device/meterplus.ts +2 -2
- package/src/platform.ts +33 -23
package/src/platform.ts
CHANGED
|
@@ -300,12 +300,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
300
300
|
const { body, statusCode, headers } = await request(Devices, {
|
|
301
301
|
headers: this.generateHeaders(),
|
|
302
302
|
});
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
this.debugWarnLog(`body: ${JSON.stringify(body)}`);
|
|
304
|
+
this.debugWarnLog(`statusCode: ${JSON.stringify(statusCode)}`);
|
|
305
|
+
this.debugWarnLog(`headers: ${JSON.stringify(headers)}`);
|
|
306
|
+
const devicesAPI: any = await body.json();
|
|
307
|
+
if ((statusCode === 200 || statusCode === 100) && devicesAPI.statusCode === 200) {
|
|
305
308
|
this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
|
|
306
|
-
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
307
309
|
// SwitchBot Devices
|
|
310
|
+
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
311
|
+
this.debugWarnLog(`devicesAPI Length: ${devicesAPI.length}`);
|
|
308
312
|
const deviceLists = devicesAPI.body.deviceList;
|
|
313
|
+
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
314
|
+
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
309
315
|
if (!this.config.options?.devices) {
|
|
310
316
|
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
311
317
|
if (deviceLists.length === 0) {
|
|
@@ -323,25 +329,29 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
323
329
|
}
|
|
324
330
|
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
325
331
|
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
if (deviceLists.length === 0) {
|
|
333
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
334
|
+
} else {
|
|
335
|
+
const deviceConfigs = this.config.options?.devices;
|
|
336
|
+
|
|
337
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
338
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
339
|
+
...a2.find(
|
|
340
|
+
(item: { deviceId: string }) =>
|
|
341
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
342
|
+
),
|
|
343
|
+
...itm,
|
|
344
|
+
}));
|
|
345
|
+
|
|
346
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
347
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
348
|
+
for (const device of devices) {
|
|
349
|
+
if (device.deviceType) {
|
|
350
|
+
if (device.configDeviceName) {
|
|
351
|
+
device.deviceName = device.configDeviceName;
|
|
352
|
+
}
|
|
353
|
+
this.createDevice(device);
|
|
343
354
|
}
|
|
344
|
-
this.createDevice(device);
|
|
345
355
|
}
|
|
346
356
|
}
|
|
347
357
|
} else {
|
|
@@ -388,7 +398,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
388
398
|
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
389
399
|
}
|
|
390
400
|
} else {
|
|
391
|
-
this.statusCode(statusCode);
|
|
401
|
+
this.statusCode(devicesAPI.statusCode);
|
|
392
402
|
}
|
|
393
403
|
} catch (e: any) {
|
|
394
404
|
this.debugErrorLog(
|
|
@@ -2184,7 +2194,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2184
2194
|
this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2185
2195
|
break;
|
|
2186
2196
|
default:
|
|
2187
|
-
this.
|
|
2197
|
+
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2188
2198
|
}
|
|
2189
2199
|
}
|
|
2190
2200
|
|