@switchbot/homebridge-switchbot 2.8.0-beta.2 → 2.8.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -2
- package/README.md +1 -1
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +9 -6
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +66 -52
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +12 -9
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +8 -5
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +45 -34
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +33 -36
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +3 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +30 -5
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +9 -6
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +10 -6
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +9 -6
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +11 -6
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +12 -8
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +56 -54
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +46 -31
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +9 -6
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +2 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +27 -2
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +71 -88
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +3 -3
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +3 -3
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +3 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +3 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +3 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +3 -3
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +3 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +67 -65
- package/dist/platform.js.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +10 -8
- package/src/device/bot.ts +66 -50
- package/src/device/ceilinglight.ts +17 -11
- package/src/device/colorbulb.ts +15 -10
- package/src/device/contact.ts +45 -31
- package/src/device/curtain.ts +34 -35
- package/src/device/hub.ts +32 -6
- package/src/device/humidifier.ts +12 -9
- package/src/device/iosensor.ts +11 -7
- package/src/device/lightstrip.ts +14 -9
- package/src/device/lock.ts +14 -7
- package/src/device/meter.ts +13 -8
- package/src/device/meterplus.ts +62 -55
- package/src/device/motion.ts +46 -28
- package/src/device/plug.ts +10 -7
- package/src/device/robotvacuumcleaner.ts +34 -5
- package/src/irdevice/airconditioner.ts +84 -96
- package/src/irdevice/airpurifier.ts +6 -6
- package/src/irdevice/camera.ts +6 -6
- package/src/irdevice/fan.ts +6 -6
- package/src/irdevice/light.ts +6 -6
- package/src/irdevice/other.ts +6 -6
- package/src/irdevice/tv.ts +6 -6
- package/src/irdevice/vacuumcleaner.ts +6 -6
- package/src/irdevice/waterheater.ts +6 -6
- package/src/platform.ts +76 -75
- package/src/settings.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig, irdevice
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -27,10 +27,10 @@ export class WaterHeater {
|
|
|
27
27
|
) {
|
|
28
28
|
// default placeholders
|
|
29
29
|
this.logs({ device });
|
|
30
|
-
this.config({ device });
|
|
31
30
|
this.context();
|
|
32
31
|
this.disablePushOnChanges({ device });
|
|
33
32
|
this.disablePushOffChanges({ device });
|
|
33
|
+
this.config({ device });
|
|
34
34
|
|
|
35
35
|
// set accessory information
|
|
36
36
|
accessory
|
|
@@ -121,14 +121,14 @@ export class WaterHeater {
|
|
|
121
121
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
122
122
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
123
123
|
if (this.device.connectionType === 'OpenAPI') {
|
|
124
|
-
this.
|
|
124
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
125
125
|
try {
|
|
126
126
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
127
127
|
body: bodyChange,
|
|
128
128
|
method: 'POST',
|
|
129
129
|
headers: this.platform.generateHeaders(),
|
|
130
130
|
});
|
|
131
|
-
const deviceStatus = await body.json();
|
|
131
|
+
const deviceStatus: any = await body.json();
|
|
132
132
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
133
133
|
this.statusCode(statusCode);
|
|
134
134
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -303,7 +303,7 @@ export class WaterHeater {
|
|
|
303
303
|
config['disablePushOff'] = device.disablePushOff;
|
|
304
304
|
}
|
|
305
305
|
if (Object.entries(config).length !== 0) {
|
|
306
|
-
this.
|
|
306
|
+
this.debugWarnLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`] });
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
package/src/platform.ts
CHANGED
|
@@ -138,7 +138,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
138
138
|
platformConfig['pushRate'] = this.config.options.pushRate;
|
|
139
139
|
}
|
|
140
140
|
if (Object.entries(platformConfig).length !== 0) {
|
|
141
|
-
this.
|
|
141
|
+
this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (this.config.options) {
|
|
@@ -245,7 +245,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
245
245
|
} else {
|
|
246
246
|
// eslint-disable-next-line no-useless-escape, max-len
|
|
247
247
|
this.warnLog(
|
|
248
|
-
'This plugin has been updated to use OpenAPI v1.1, config is set with openToken,
|
|
248
|
+
'This plugin has been updated to use OpenAPI v1.1, config is set with openToken, '
|
|
249
|
+
+ '"openToken" config has been moved to the "token" config, please restart Homebridge.',
|
|
249
250
|
);
|
|
250
251
|
}
|
|
251
252
|
|
|
@@ -299,18 +300,42 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
299
300
|
const { body, statusCode, headers } = await request(Devices, {
|
|
300
301
|
headers: this.generateHeaders(),
|
|
301
302
|
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
303
|
+
if (statusCode === 200) {
|
|
304
|
+
const devicesAPI: any = await body.json();
|
|
305
|
+
this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
|
|
306
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
307
|
+
// SwitchBot Devices
|
|
308
|
+
const deviceLists = devicesAPI.body.deviceList;
|
|
309
|
+
if (!this.config.options?.devices) {
|
|
310
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
311
|
+
if (deviceLists.length === 0) {
|
|
312
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
313
|
+
} else {
|
|
314
|
+
const devices = deviceLists.map((v: any) => v);
|
|
315
|
+
for (const device of devices) {
|
|
316
|
+
if (device.deviceType) {
|
|
317
|
+
if (device.configDeviceName) {
|
|
318
|
+
device.deviceName = device.configDeviceName;
|
|
319
|
+
}
|
|
320
|
+
this.createDevice(device);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
325
|
+
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
326
|
+
const deviceConfigs = this.config.options?.devices;
|
|
327
|
+
|
|
328
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
329
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
330
|
+
...a2.find(
|
|
331
|
+
(item: { deviceId: string }) =>
|
|
332
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
333
|
+
),
|
|
334
|
+
...itm,
|
|
335
|
+
}));
|
|
336
|
+
|
|
337
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
338
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
314
339
|
for (const device of devices) {
|
|
315
340
|
if (device.deviceType) {
|
|
316
341
|
if (device.configDeviceName) {
|
|
@@ -319,72 +344,51 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
319
344
|
this.createDevice(device);
|
|
320
345
|
}
|
|
321
346
|
}
|
|
347
|
+
} else {
|
|
348
|
+
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
322
349
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
328
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
329
|
-
...a2.find(
|
|
330
|
-
(item: { deviceId: string }) =>
|
|
331
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
332
|
-
),
|
|
333
|
-
...itm,
|
|
334
|
-
}));
|
|
335
|
-
|
|
336
|
-
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
337
|
-
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
338
|
-
for (const device of devices) {
|
|
339
|
-
if (device.deviceType) {
|
|
340
|
-
if (device.configDeviceName) {
|
|
341
|
-
device.deviceName = device.configDeviceName;
|
|
342
|
-
}
|
|
343
|
-
this.createDevice(device);
|
|
344
|
-
}
|
|
350
|
+
if (devicesAPI.body.deviceList.length !== 0) {
|
|
351
|
+
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
352
|
+
} else {
|
|
353
|
+
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
345
354
|
}
|
|
346
|
-
} else {
|
|
347
|
-
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
348
|
-
}
|
|
349
|
-
if (devicesAPI.body.deviceList.length !== 0) {
|
|
350
|
-
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
351
|
-
} else {
|
|
352
|
-
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
353
|
-
}
|
|
354
355
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
356
|
+
// IR Devices
|
|
357
|
+
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
358
|
+
if (!this.config.options?.irdevices) {
|
|
359
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
360
|
+
const devices = irDeviceLists.map((v: any) => v);
|
|
361
|
+
for (const device of devices) {
|
|
362
|
+
if (device.remoteType) {
|
|
363
|
+
this.createIRDevice(device);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
368
|
+
const irDeviceConfig = this.config.options?.irdevices;
|
|
369
|
+
|
|
370
|
+
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
371
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
372
|
+
...a2.find(
|
|
373
|
+
(item: { deviceId: string }) =>
|
|
374
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
375
|
+
),
|
|
376
|
+
...itm,
|
|
377
|
+
}));
|
|
378
|
+
|
|
379
|
+
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
380
|
+
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
381
|
+
for (const device of devices) {
|
|
362
382
|
this.createIRDevice(device);
|
|
363
383
|
}
|
|
364
384
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
370
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
371
|
-
...a2.find(
|
|
372
|
-
(item: { deviceId: string }) =>
|
|
373
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
374
|
-
),
|
|
375
|
-
...itm,
|
|
376
|
-
}));
|
|
377
|
-
|
|
378
|
-
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
379
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
380
|
-
for (const device of devices) {
|
|
381
|
-
this.createIRDevice(device);
|
|
385
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
386
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
387
|
+
} else {
|
|
388
|
+
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
382
389
|
}
|
|
383
|
-
}
|
|
384
|
-
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
385
|
-
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
386
390
|
} else {
|
|
387
|
-
this.
|
|
391
|
+
this.statusCode(statusCode);
|
|
388
392
|
}
|
|
389
393
|
} catch (e: any) {
|
|
390
394
|
this.debugErrorLog(
|
|
@@ -1664,9 +1668,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1664
1668
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1665
1669
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1666
1670
|
|
|
1667
|
-
if (device.irair?.meterType && device.irair?.meterId) {
|
|
1668
|
-
device.irair.meterUuid = this.api.hap.uuid.generate(`${device.irair.meterId}-${device.irair.meterType}`);
|
|
1669
|
-
}
|
|
1670
1671
|
if (existingAccessory) {
|
|
1671
1672
|
// the accessory already exists
|
|
1672
1673
|
if (!device.hide_device && device.hubDeviceId) {
|
package/src/settings.ts
CHANGED
|
@@ -286,7 +286,7 @@ export type deviceStatus = {
|
|
|
286
286
|
childLock?: boolean; //determines if a Humidifier's safety lock is on or not. (Used by the following deviceTypes: Humidifier)
|
|
287
287
|
sound?: boolean; //determines if a Humidifier is muted or not. (Used by the following deviceTypes: Humidifier)
|
|
288
288
|
lackWater?: boolean; //determines if the water tank is empty or not. (Used by the following deviceTypes: Humidifier)
|
|
289
|
-
version?: number; //the version of the device. (Used by the following deviceTypes: Blind Tilt)
|
|
289
|
+
version?: number; //the version of the device. (Used by the following deviceTypes: Blind Tilt, Meter, MeterPlus, IOSensor)
|
|
290
290
|
direction?: string; //the opening direction of a Blind Tilt device. (Used by the following deviceTypes: Blind Tilt)
|
|
291
291
|
runStatus?: string; //'static' when not moving. (Used by the following deviceTypes: Blind Tilt)
|
|
292
292
|
mode?: number; //available for devices. the fan mode. (Used by the following deviceTypes: Smart Fan)
|