@switchbot/homebridge-switchbot 2.1.0-beta.1 → 2.1.0-beta.10
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 +7 -2
- package/config.schema.json +10 -0
- package/dist/device/bot.d.ts +2 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +33 -8
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +15 -11
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +15 -10
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +8 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +17 -6
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +12 -3
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +15 -4
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +8 -2
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +8 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +8 -2
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +15 -4
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +15 -11
- package/dist/device/striplight.js.map +1 -1
- package/dist/platform.d.ts +0 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +90 -93
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +3 -3
- package/src/device/bot.ts +31 -12
- package/src/device/ceilinglight.ts +12 -11
- package/src/device/colorbulb.ts +12 -10
- package/src/device/contact.ts +6 -2
- package/src/device/curtain.ts +14 -6
- package/src/device/humidifier.ts +9 -3
- package/src/device/lock.ts +12 -4
- package/src/device/meter.ts +6 -2
- package/src/device/meterplus.ts +6 -2
- package/src/device/motion.ts +6 -2
- package/src/device/plug.ts +12 -4
- package/src/device/striplight.ts +12 -11
- package/src/platform.ts +93 -98
- package/src/settings.ts +1 -0
package/src/platform.ts
CHANGED
|
@@ -42,7 +42,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
42
42
|
public readonly accessories: PlatformAccessory[] = [];
|
|
43
43
|
|
|
44
44
|
version = require('../package.json').version || '1.12.8'; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
45
|
-
deviceStatus!: any;
|
|
46
45
|
debugMode!: boolean;
|
|
47
46
|
platformLogging?: string;
|
|
48
47
|
|
|
@@ -235,9 +234,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
235
234
|
|
|
236
235
|
// set the refresh token
|
|
237
236
|
pluginConfig.credentials.token = this.config.credentials?.openToken;
|
|
238
|
-
pluginConfig.credentials.
|
|
237
|
+
if (pluginConfig.credentials.token) {
|
|
238
|
+
pluginConfig.credentials.openToken = undefined;
|
|
239
|
+
}
|
|
239
240
|
|
|
240
|
-
this.debugWarnLog(`
|
|
241
|
+
this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
241
242
|
|
|
242
243
|
// save the config, ensuring we maintain pretty json
|
|
243
244
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
@@ -279,117 +280,95 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
279
280
|
let rawData = '';
|
|
280
281
|
res.on('data', (d) => {
|
|
281
282
|
rawData += d;
|
|
282
|
-
this.deviceStatus = d;
|
|
283
283
|
this.debugLog(`d: ${d}`);
|
|
284
284
|
});
|
|
285
285
|
res.on('end', () => {
|
|
286
286
|
try {
|
|
287
287
|
const devicesAPI = JSON.parse(rawData);
|
|
288
288
|
this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
|
|
289
|
-
|
|
290
289
|
// SwitchBot Devices
|
|
291
|
-
|
|
290
|
+
if (devicesAPI.body.deviceList.length !== 0) {
|
|
292
291
|
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
293
292
|
} else {
|
|
294
293
|
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
295
|
-
}
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.infoLog(`Total SwitchBot Devices Found: ${deviceLists.length}`);
|
|
305
|
-
}
|
|
306
|
-
if (!this.config.options?.devices) {
|
|
307
|
-
this.debugLog(`SwitchBot Device Config Not Set: ${superStringify(this.config.options?.devices)}`);
|
|
308
|
-
const devices = deviceLists.map((v: any) => v);
|
|
309
|
-
for (const device of devices) {
|
|
310
|
-
if (device.deviceType) {
|
|
311
|
-
if (device.configDeviceName) {
|
|
312
|
-
device.deviceName = device.configDeviceName;
|
|
313
|
-
}
|
|
314
|
-
this.createDevice(device);
|
|
294
|
+
}
|
|
295
|
+
const deviceLists = devicesAPI.body.deviceList;
|
|
296
|
+
if (!this.config.options?.devices) {
|
|
297
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
298
|
+
const devices = deviceLists.map((v: any) => v);
|
|
299
|
+
for (const device of devices) {
|
|
300
|
+
if (device.deviceType) {
|
|
301
|
+
if (device.configDeviceName) {
|
|
302
|
+
device.deviceName = device.configDeviceName;
|
|
315
303
|
}
|
|
304
|
+
this.createDevice(device);
|
|
316
305
|
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.createDevice(device);
|
|
306
|
+
}
|
|
307
|
+
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
308
|
+
this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
|
|
309
|
+
const deviceConfigs = this.config.options?.devices;
|
|
310
|
+
|
|
311
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
312
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
313
|
+
...a2.find(
|
|
314
|
+
(item: { deviceId: string }) =>
|
|
315
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
316
|
+
),
|
|
317
|
+
...itm,
|
|
318
|
+
}));
|
|
319
|
+
|
|
320
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
321
|
+
this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
|
|
322
|
+
for (const device of devices) {
|
|
323
|
+
if (device.deviceType) {
|
|
324
|
+
if (device.configDeviceName) {
|
|
325
|
+
device.deviceName = device.configDeviceName;
|
|
338
326
|
}
|
|
327
|
+
this.createDevice(device);
|
|
339
328
|
}
|
|
340
|
-
} else {
|
|
341
|
-
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
342
329
|
}
|
|
343
330
|
} else {
|
|
344
|
-
this.errorLog(
|
|
331
|
+
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
345
332
|
}
|
|
333
|
+
|
|
346
334
|
// IR Devices
|
|
347
|
-
|
|
335
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
348
336
|
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
349
337
|
} else {
|
|
350
338
|
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const devices = irDeviceLists.map((v: any) => v);
|
|
365
|
-
for (const device of devices) {
|
|
366
|
-
if (device.remoteType) {
|
|
367
|
-
this.createIRDevice(device);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
} else {
|
|
371
|
-
this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
|
|
372
|
-
const irDeviceConfig = this.config.options?.irdevices;
|
|
373
|
-
|
|
374
|
-
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
375
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
376
|
-
...a2.find(
|
|
377
|
-
(item: { deviceId: string }) =>
|
|
378
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
379
|
-
),
|
|
380
|
-
...itm,
|
|
381
|
-
}));
|
|
382
|
-
|
|
383
|
-
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
384
|
-
this.debugLog(`IR Devices: ${superStringify(devices)}`);
|
|
385
|
-
for (const device of devices) {
|
|
386
|
-
if (device.remoteType) {
|
|
387
|
-
this.createIRDevice(device);
|
|
388
|
-
}
|
|
339
|
+
}
|
|
340
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
341
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
342
|
+
} else {
|
|
343
|
+
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
344
|
+
}
|
|
345
|
+
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
346
|
+
if (!this.config.options?.irdevices) {
|
|
347
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
348
|
+
const devices = irDeviceLists.map((v: any) => v);
|
|
349
|
+
for (const device of devices) {
|
|
350
|
+
if (device.remoteType) {
|
|
351
|
+
this.createIRDevice(device);
|
|
389
352
|
}
|
|
390
353
|
}
|
|
391
354
|
} else {
|
|
392
|
-
this.
|
|
355
|
+
this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
|
|
356
|
+
const irDeviceConfig = this.config.options?.irdevices;
|
|
357
|
+
|
|
358
|
+
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
359
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
360
|
+
...a2.find(
|
|
361
|
+
(item: { deviceId: string }) =>
|
|
362
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
363
|
+
),
|
|
364
|
+
...itm,
|
|
365
|
+
}));
|
|
366
|
+
|
|
367
|
+
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
368
|
+
this.debugLog(`IR Devices: ${superStringify(devices)}`);
|
|
369
|
+
for (const device of devices) {
|
|
370
|
+
this.createIRDevice(device);
|
|
371
|
+
}
|
|
393
372
|
}
|
|
394
373
|
} catch (e:any) {
|
|
395
374
|
this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
@@ -472,6 +451,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
472
451
|
this.createColorBulb(device);
|
|
473
452
|
break;
|
|
474
453
|
case 'Ceiling Light':
|
|
454
|
+
case 'Ceiling Light Pro':
|
|
475
455
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
476
456
|
this.createCeilingLight(device);
|
|
477
457
|
break;
|
|
@@ -494,7 +474,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
494
474
|
}
|
|
495
475
|
|
|
496
476
|
private createIRDevice(device: irdevice & devicesConfig) {
|
|
497
|
-
switch (device.remoteType
|
|
477
|
+
switch (device.remoteType) {
|
|
498
478
|
case 'TV':
|
|
499
479
|
case 'DIY TV':
|
|
500
480
|
case 'Projector':
|
|
@@ -1752,19 +1732,34 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1752
1732
|
`${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
1753
1733
|
|
|
1754
1734
|
let registerCurtain: boolean;
|
|
1755
|
-
if (device.
|
|
1735
|
+
if (device.master && device.group) {
|
|
1736
|
+
// OpenAPI: Master Curtains in Group
|
|
1756
1737
|
registerCurtain = true;
|
|
1757
|
-
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config]
|
|
1738
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, device.group: ${device.group}`
|
|
1739
|
+
+ ` connectionType; ${device.connectionType}`);
|
|
1758
1740
|
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1759
|
-
} else if (device.
|
|
1741
|
+
} else if (!device.master && device.curtain?.disable_group) { //!device.group && device.connectionType === 'BLE'
|
|
1742
|
+
// OpenAPI: Non-Master Curtain that has Disable Grouping Checked
|
|
1743
|
+
registerCurtain = true;
|
|
1744
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, disable_group: `
|
|
1745
|
+
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
1746
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1747
|
+
} else if (device.master && !device.group) {
|
|
1748
|
+
// OpenAPI: Master Curtains not in Group
|
|
1749
|
+
registerCurtain = true;
|
|
1750
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, device.group: ${device.group}`
|
|
1751
|
+
+ ` connectionType; ${device.connectionType}`);
|
|
1752
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1753
|
+
} else if (device.connectionType === 'BLE') {
|
|
1754
|
+
// BLE: Curtains
|
|
1760
1755
|
registerCurtain = true;
|
|
1761
1756
|
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
|
|
1762
1757
|
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1763
1758
|
} else {
|
|
1764
1759
|
registerCurtain = false;
|
|
1765
1760
|
this.debugErrorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group},`
|
|
1766
|
-
+ `
|
|
1767
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1761
|
+
+ ` device.master: ${device.master}, device.group: ${device.group}`);
|
|
1762
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
1768
1763
|
}
|
|
1769
1764
|
return registerCurtain;
|
|
1770
1765
|
}
|
|
@@ -1782,7 +1777,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1782
1777
|
async registerDevice(device: device & devicesConfig) {
|
|
1783
1778
|
device.connectionType = await this.connectionType(device);
|
|
1784
1779
|
let registerDevice: boolean;
|
|
1785
|
-
if (!device.hide_device && device.
|
|
1780
|
+
if (!device.hide_device && device.connectionType === 'BLE/OpenAPI') {
|
|
1786
1781
|
if (device.deviceType === 'Curtain') {
|
|
1787
1782
|
registerDevice = await this.registerCurtains(device);
|
|
1788
1783
|
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
@@ -1801,7 +1796,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1801
1796
|
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1802
1797
|
}
|
|
1803
1798
|
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1804
|
-
} else if (!device.hide_device && device.
|
|
1799
|
+
} else if (!device.hide_device && device.connectionType === 'OpenAPI') {
|
|
1805
1800
|
if (device.deviceType === 'Curtain') {
|
|
1806
1801
|
registerDevice = await this.registerCurtains(device);
|
|
1807
1802
|
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|