homebridge-tsvesync 1.0.1 → 1.0.2
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/platform.d.ts +5 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +34 -16
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +8 -15
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +82 -50
- package/dist/platformAccessory.js.map +1 -1
- package/package/LICENSE +21 -0
- package/package/README.md +227 -0
- package/package/api/vesync/VeSync.yaml +33 -0
- package/package/api/vesyncbulb/ESL100.yaml +74 -0
- package/package/api/vesyncbulb/ESL100CW.yaml +123 -0
- package/package/api/vesyncbulb/ESL100MC.yaml +169 -0
- package/package/api/vesyncbulb/XYD0001.yaml +193 -0
- package/package/api/vesyncfan/Classic200S.yaml +280 -0
- package/package/api/vesyncfan/Classic300S.yaml +278 -0
- package/package/api/vesyncfan/Core200S.yaml +256 -0
- package/package/api/vesyncfan/Core300S.yaml +281 -0
- package/package/api/vesyncfan/Core400S.yaml +281 -0
- package/package/api/vesyncfan/Core600S.yaml +281 -0
- package/package/api/vesyncfan/Dual200S.yaml +278 -0
- package/package/api/vesyncfan/LAP-C201S-AUSR.yaml +256 -0
- package/package/api/vesyncfan/LAP-C202S-WUSR.yaml +256 -0
- package/package/api/vesyncfan/LAP-C301S-WAAA.yaml +281 -0
- package/package/api/vesyncfan/LAP-C301S-WJP.yaml +281 -0
- package/package/api/vesyncfan/LAP-C302S-WUSB.yaml +281 -0
- package/package/api/vesyncfan/LAP-C401S-WAAA.yaml +281 -0
- package/package/api/vesyncfan/LAP-C401S-WJP.yaml +281 -0
- package/package/api/vesyncfan/LAP-C401S-WUSR.yaml +281 -0
- package/package/api/vesyncfan/LAP-C601S-WEU.yaml +281 -0
- package/package/api/vesyncfan/LAP-C601S-WUS.yaml +281 -0
- package/package/api/vesyncfan/LAP-C601S-WUSR.yaml +281 -0
- package/package/api/vesyncfan/LAP-EL551S-AEUR.yaml +167 -0
- package/package/api/vesyncfan/LAP-EL551S-AUS.yaml +167 -0
- package/package/api/vesyncfan/LAP-EL551S-WEU.yaml +167 -0
- package/package/api/vesyncfan/LAP-EL551S-WUS.yaml +167 -0
- package/package/api/vesyncfan/LAP-V102S-AASR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V102S-AUSR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V102S-WEU.yaml +167 -0
- package/package/api/vesyncfan/LAP-V102S-WJP.yaml +167 -0
- package/package/api/vesyncfan/LAP-V102S-WUS.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201-AUSR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-AASR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-AEUR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-AUSR.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-WEU.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-WJP.yaml +167 -0
- package/package/api/vesyncfan/LAP-V201S-WUS.yaml +167 -0
- package/package/api/vesyncfan/LEH-S601S-WUS.yaml +303 -0
- package/package/api/vesyncfan/LEH-S601S-WUSR.yaml +82 -0
- package/package/api/vesyncfan/LTF-F422S-KEU.yaml +165 -0
- package/package/api/vesyncfan/LTF-F422S-WUS.yaml +165 -0
- package/package/api/vesyncfan/LTF-F422S-WUSR.yaml +167 -0
- package/package/api/vesyncfan/LTF-F422_WJP.yaml +165 -0
- package/package/api/vesyncfan/LUH-A601S-AUSW.yaml +82 -0
- package/package/api/vesyncfan/LUH-A601S-WUSB.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WEU.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WEUR.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WJP.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WUS.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WUSC.yaml +305 -0
- package/package/api/vesyncfan/LUH-A602S-WUSR.yaml +305 -0
- package/package/api/vesyncfan/LUH-D301S-WEU.yaml +305 -0
- package/package/api/vesyncfan/LUH-D301S-WJP.yaml +305 -0
- package/package/api/vesyncfan/LUH-D301S-WUSR.yaml +305 -0
- package/package/api/vesyncfan/LUH-M101S-WUS.yaml +278 -0
- package/package/api/vesyncfan/LUH-O451S-WEU.yaml +278 -0
- package/package/api/vesyncfan/LUH-O451S-WUS.yaml +278 -0
- package/package/api/vesyncfan/LUH-O451S-WUSR.yaml +305 -0
- package/package/api/vesyncfan/LUH-O601S-KUS.yaml +305 -0
- package/package/api/vesyncfan/LUH-O601S-WUS.yaml +305 -0
- package/package/api/vesyncfan/LV-PUR131S.yaml +108 -0
- package/package/api/vesyncfan/LV-RH131S.yaml +108 -0
- package/package/api/vesyncoutlet/ESO15-TB.yaml +124 -0
- package/package/api/vesyncoutlet/ESW01-EU.yaml +122 -0
- package/package/api/vesyncoutlet/ESW03-USA.yaml +122 -0
- package/package/api/vesyncoutlet/ESW15-USA.yaml +156 -0
- package/package/api/vesyncoutlet/wifi-switch-1.3.yaml +60 -0
- package/package/api/vesyncswitch/ESWD16.yaml +128 -0
- package/package/api/vesyncswitch/ESWL01.yaml +56 -0
- package/package/api/vesyncswitch/ESWL03.yaml +56 -0
- package/package/package.json +53 -0
- package/package/src/lib/helpers.ts +290 -0
- package/package/src/lib/vesync.ts +530 -0
- package/package/src/lib/vesyncBaseDevice.ts +114 -0
- package/package/src/lib/vesyncBulb.ts +252 -0
- package/package/src/lib/vesyncBulbImpl.ts +215 -0
- package/package/src/lib/vesyncFan.ts +447 -0
- package/package/src/lib/vesyncFanImpl.ts +848 -0
- package/package/src/lib/vesyncOutlet.ts +148 -0
- package/package/src/lib/vesyncOutletImpl.ts +284 -0
- package/package/src/lib/vesyncSwitch.ts +546 -0
- package/package/src/lib/vesyncSwitchImpl.ts +408 -0
- package/package.json +6 -5
- package/src/platform.ts +45 -17
- package/src/platformAccessory.ts +104 -51
- package/tsvesync-1.0.11.tgz +0 -0
package/dist/platform.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export declare class TSVESyncPlatform implements DynamicPlatformPlugin {
|
|
|
16
16
|
*/
|
|
17
17
|
configureAccessory(accessory: PlatformAccessory): void;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Get all devices from all categories
|
|
20
|
+
*/
|
|
21
|
+
private getAllDevices;
|
|
22
|
+
/**
|
|
23
|
+
* Discover VeSync devices and register them as accessories
|
|
20
24
|
*/
|
|
21
25
|
discoverDevices(): Promise<void>;
|
|
22
26
|
/**
|
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5H,qBAAa,gBAAiB,YAAW,qBAAqB;aAa1C,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAd1B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAEtD,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5H,qBAAa,gBAAiB,YAAW,qBAAqB;aAa1C,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAd1B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAEtD,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,oBAAoB,CAAC,CAAiB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;gBAGf,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IAqD1B;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAK/C;;OAEG;IACH,OAAO,CAAC,aAAa;IASrB;;OAEG;IACG,eAAe;IA0DrB;;OAEG;YACW,kBAAkB;CA6BjC"}
|
package/dist/platform.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TSVESyncPlatform = void 0;
|
|
4
4
|
const settings_1 = require("./settings");
|
|
5
5
|
const platformAccessory_1 = require("./platformAccessory");
|
|
6
|
-
const
|
|
6
|
+
const vesync_1 = require("tsvesync/dist/src/lib/vesync");
|
|
7
7
|
class TSVESyncPlatform {
|
|
8
8
|
constructor(log, config, api) {
|
|
9
9
|
this.log = log;
|
|
@@ -21,11 +21,8 @@ class TSVESyncPlatform {
|
|
|
21
21
|
// Get config values with defaults
|
|
22
22
|
this.updateInterval = config.updateInterval || 30;
|
|
23
23
|
this.debug = config.debug || false;
|
|
24
|
-
// Initialize
|
|
25
|
-
this.client = new
|
|
26
|
-
username: config.username,
|
|
27
|
-
password: config.password,
|
|
28
|
-
});
|
|
24
|
+
// Initialize VeSync client
|
|
25
|
+
this.client = new vesync_1.VeSync(config.username, config.password, Intl.DateTimeFormat().resolvedOptions().timeZone, this.debug);
|
|
29
26
|
if (this.debug) {
|
|
30
27
|
this.log.debug('Initialized platform with config:', {
|
|
31
28
|
name: config.name,
|
|
@@ -62,7 +59,18 @@ class TSVESyncPlatform {
|
|
|
62
59
|
this.accessories.push(accessory);
|
|
63
60
|
}
|
|
64
61
|
/**
|
|
65
|
-
*
|
|
62
|
+
* Get all devices from all categories
|
|
63
|
+
*/
|
|
64
|
+
getAllDevices() {
|
|
65
|
+
return [
|
|
66
|
+
...this.client.fans,
|
|
67
|
+
...this.client.outlets,
|
|
68
|
+
...this.client.switches,
|
|
69
|
+
...this.client.bulbs,
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Discover VeSync devices and register them as accessories
|
|
66
74
|
*/
|
|
67
75
|
async discoverDevices() {
|
|
68
76
|
try {
|
|
@@ -71,32 +79,37 @@ class TSVESyncPlatform {
|
|
|
71
79
|
}
|
|
72
80
|
// Login and get devices
|
|
73
81
|
await this.client.login();
|
|
74
|
-
const
|
|
82
|
+
const success = await this.client.getDevices();
|
|
83
|
+
if (!success) {
|
|
84
|
+
this.log.error('Failed to get devices');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const devices = this.getAllDevices();
|
|
75
88
|
if (this.debug) {
|
|
76
89
|
this.log.debug('Found devices:', devices.length);
|
|
77
90
|
}
|
|
78
91
|
// Loop over the discovered devices and register each one
|
|
79
92
|
for (const device of devices) {
|
|
80
|
-
const uuid = this.api.hap.uuid.generate(device.
|
|
93
|
+
const uuid = this.api.hap.uuid.generate(device.cid);
|
|
81
94
|
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
82
95
|
if (existingAccessory) {
|
|
83
96
|
if (this.debug) {
|
|
84
97
|
this.log.debug('Restoring existing accessory from cache:', existingAccessory.displayName);
|
|
85
98
|
}
|
|
86
99
|
existingAccessory.context.device = device;
|
|
87
|
-
new platformAccessory_1.TSVESyncAccessory(this, existingAccessory,
|
|
100
|
+
new platformAccessory_1.TSVESyncAccessory(this, existingAccessory, device);
|
|
88
101
|
}
|
|
89
102
|
else {
|
|
90
|
-
this.log.info('Adding new accessory:', device.
|
|
91
|
-
const accessory = new this.api.platformAccessory(device.
|
|
103
|
+
this.log.info('Adding new accessory:', device.deviceName);
|
|
104
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
92
105
|
accessory.context.device = device;
|
|
93
|
-
new platformAccessory_1.TSVESyncAccessory(this, accessory,
|
|
106
|
+
new platformAccessory_1.TSVESyncAccessory(this, accessory, device);
|
|
94
107
|
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
|
|
95
108
|
}
|
|
96
109
|
}
|
|
97
110
|
// Remove accessories that are no longer present
|
|
98
111
|
this.accessories.forEach(accessory => {
|
|
99
|
-
const device = devices.find(device => this.api.hap.uuid.generate(device.
|
|
112
|
+
const device = devices.find(device => this.api.hap.uuid.generate(device.cid) === accessory.UUID);
|
|
100
113
|
if (!device) {
|
|
101
114
|
if (this.debug) {
|
|
102
115
|
this.log.debug('Removing accessory no longer present:', accessory.displayName);
|
|
@@ -118,9 +131,14 @@ class TSVESyncPlatform {
|
|
|
118
131
|
this.log.debug('Updating device states');
|
|
119
132
|
}
|
|
120
133
|
await this.client.login();
|
|
121
|
-
const
|
|
134
|
+
const success = await this.client.getDevices();
|
|
135
|
+
if (!success) {
|
|
136
|
+
this.log.error('Failed to get devices');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const devices = this.getAllDevices();
|
|
122
140
|
this.accessories.forEach(accessory => {
|
|
123
|
-
const device = devices.find(d => this.api.hap.uuid.generate(d.
|
|
141
|
+
const device = devices.find(d => this.api.hap.uuid.generate(d.cid) === accessory.UUID);
|
|
124
142
|
if (device) {
|
|
125
143
|
if (this.debug) {
|
|
126
144
|
this.log.debug('Updated state for device:', accessory.displayName);
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;AACA,yCAAwD;AACxD,2DAAwD;A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AAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAE/C,IAAI,CAAC,OAAO,EAAE;gBACZ,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;gBACxC,OAAO;aACR;YAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAErC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBACnC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvF,IAAI,MAAM,EAAE;oBACV,IAAI,IAAI,CAAC,KAAK,EAAE;wBACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;qBACpE;oBACD,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;iBACnC;YACH,CAAC,CAAC,CAAC;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;SAC1D;IACH,CAAC;CACF;AArLD,4CAqLC"}
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import { PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
2
2
|
import { TSVESyncPlatform } from './platform';
|
|
3
|
-
import {
|
|
3
|
+
import { VeSyncBaseDevice } from 'tsvesync/dist/src/lib/vesyncBaseDevice';
|
|
4
4
|
export declare class TSVESyncAccessory {
|
|
5
5
|
private readonly platform;
|
|
6
6
|
private readonly accessory;
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly device;
|
|
8
8
|
private service;
|
|
9
|
-
constructor(platform: TSVESyncPlatform, accessory: PlatformAccessory,
|
|
9
|
+
constructor(platform: TSVESyncPlatform, accessory: PlatformAccessory, device: VeSyncBaseDevice);
|
|
10
10
|
private setupService;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
private setupBulb;
|
|
12
|
+
private setupFan;
|
|
13
|
+
private setupSwitch;
|
|
14
14
|
setOn(value: CharacteristicValue): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Handle "GET" requests from HomeKit for power state
|
|
17
|
-
*/
|
|
18
15
|
getOn(): Promise<CharacteristicValue>;
|
|
19
|
-
/**
|
|
20
|
-
* Handle "SET" requests from HomeKit for brightness
|
|
21
|
-
*/
|
|
22
16
|
setBrightness(value: CharacteristicValue): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Handle "GET" requests from HomeKit for brightness
|
|
25
|
-
*/
|
|
26
17
|
getBrightness(): Promise<CharacteristicValue>;
|
|
18
|
+
setFanSpeed(value: CharacteristicValue): Promise<void>;
|
|
19
|
+
getFanSpeed(): Promise<CharacteristicValue>;
|
|
27
20
|
}
|
|
28
21
|
//# sourceMappingURL=platformAccessory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAmB1E,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,OAAO,CAAW;gBAGP,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,gBAAgB;IAY3C,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,WAAW;IASb,KAAK,CAAC,KAAK,EAAE,mBAAmB;IAgBhC,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAUrC,aAAa,CAAC,KAAK,EAAE,mBAAmB;IAWxC,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAU7C,WAAW,CAAC,KAAK,EAAE,mBAAmB;IAatC,WAAW,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAUlD"}
|
|
@@ -2,48 +2,74 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TSVESyncAccessory = void 0;
|
|
4
4
|
class TSVESyncAccessory {
|
|
5
|
-
constructor(platform, accessory,
|
|
5
|
+
constructor(platform, accessory, device) {
|
|
6
6
|
this.platform = platform;
|
|
7
7
|
this.accessory = accessory;
|
|
8
|
-
this.
|
|
9
|
-
// Get the device from context
|
|
10
|
-
const device = accessory.context.device;
|
|
8
|
+
this.device = device;
|
|
11
9
|
// set accessory information
|
|
12
10
|
this.accessory.getService(this.platform.Service.AccessoryInformation)
|
|
13
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer, '
|
|
14
|
-
.setCharacteristic(this.platform.Characteristic.Model, device.
|
|
15
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.
|
|
11
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'VeSync')
|
|
12
|
+
.setCharacteristic(this.platform.Characteristic.Model, device.deviceType)
|
|
13
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.cid);
|
|
16
14
|
// Set up the appropriate service based on device type
|
|
17
|
-
this.setupService(
|
|
15
|
+
this.setupService();
|
|
18
16
|
}
|
|
19
|
-
setupService(
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
setupService() {
|
|
18
|
+
const deviceType = this.device.deviceType;
|
|
19
|
+
if (deviceType.includes('BULB')) {
|
|
20
|
+
this.setupBulb();
|
|
21
|
+
}
|
|
22
|
+
else if (deviceType.includes('FAN') || deviceType.includes('AIR')) {
|
|
23
|
+
this.setupFan();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.setupSwitch();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
setupBulb() {
|
|
30
|
+
this.service = this.accessory.getService(this.platform.Service.Lightbulb)
|
|
31
|
+
|| this.accessory.addService(this.platform.Service.Lightbulb);
|
|
32
|
+
// Add brightness characteristic if device supports it
|
|
33
|
+
const bulb = this.device;
|
|
34
|
+
if ('setBrightness' in bulb) {
|
|
26
35
|
this.service.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
27
36
|
.onSet(this.setBrightness.bind(this))
|
|
28
37
|
.onGet(this.getBrightness.bind(this));
|
|
29
38
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
40
|
+
.onSet(this.setOn.bind(this))
|
|
41
|
+
.onGet(this.getOn.bind(this));
|
|
42
|
+
}
|
|
43
|
+
setupFan() {
|
|
44
|
+
this.service = this.accessory.getService(this.platform.Service.Fan)
|
|
45
|
+
|| this.accessory.addService(this.platform.Service.Fan);
|
|
46
|
+
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
47
|
+
.onSet(this.setOn.bind(this))
|
|
48
|
+
.onGet(this.getOn.bind(this));
|
|
49
|
+
const fan = this.device;
|
|
50
|
+
if ('setSpeed' in fan) {
|
|
51
|
+
this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
52
|
+
.onSet(this.setFanSpeed.bind(this))
|
|
53
|
+
.onGet(this.getFanSpeed.bind(this));
|
|
34
54
|
}
|
|
35
|
-
|
|
55
|
+
}
|
|
56
|
+
setupSwitch() {
|
|
57
|
+
this.service = this.accessory.getService(this.platform.Service.Switch)
|
|
58
|
+
|| this.accessory.addService(this.platform.Service.Switch);
|
|
36
59
|
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
37
60
|
.onSet(this.setOn.bind(this))
|
|
38
61
|
.onGet(this.getOn.bind(this));
|
|
39
62
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Handle "SET" requests from HomeKit for power state
|
|
42
|
-
*/
|
|
43
63
|
async setOn(value) {
|
|
44
64
|
try {
|
|
45
|
-
const device = this.
|
|
46
|
-
|
|
65
|
+
const device = this.device;
|
|
66
|
+
const newState = value;
|
|
67
|
+
if (newState) {
|
|
68
|
+
await device.turnOn();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
await device.turnOff();
|
|
72
|
+
}
|
|
47
73
|
this.platform.log.debug('Set power state ->', value);
|
|
48
74
|
}
|
|
49
75
|
catch (error) {
|
|
@@ -51,55 +77,61 @@ class TSVESyncAccessory {
|
|
|
51
77
|
throw error;
|
|
52
78
|
}
|
|
53
79
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Handle "GET" requests from HomeKit for power state
|
|
56
|
-
*/
|
|
57
80
|
async getOn() {
|
|
58
81
|
try {
|
|
59
|
-
const device = this.
|
|
60
|
-
|
|
61
|
-
this.platform.log.debug('Get power state ->', state);
|
|
62
|
-
return state;
|
|
82
|
+
const device = this.device;
|
|
83
|
+
return device.deviceStatus === 'on';
|
|
63
84
|
}
|
|
64
85
|
catch (error) {
|
|
65
86
|
this.platform.log.error('Failed to get power state:', error);
|
|
66
87
|
throw error;
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Handle "SET" requests from HomeKit for brightness
|
|
71
|
-
*/
|
|
72
90
|
async setBrightness(value) {
|
|
73
91
|
try {
|
|
74
|
-
const device = this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.platform.log.debug('Set brightness ->', value);
|
|
78
|
-
}
|
|
92
|
+
const device = this.device;
|
|
93
|
+
await device.setBrightness(value);
|
|
94
|
+
this.platform.log.debug('Set brightness ->', value);
|
|
79
95
|
}
|
|
80
96
|
catch (error) {
|
|
81
97
|
this.platform.log.error('Failed to set brightness:', error);
|
|
82
98
|
throw error;
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Handle "GET" requests from HomeKit for brightness
|
|
87
|
-
*/
|
|
88
101
|
async getBrightness() {
|
|
89
102
|
try {
|
|
90
|
-
const device = this.
|
|
91
|
-
|
|
92
|
-
const brightness = await this.client.getBrightness(device.id);
|
|
93
|
-
this.platform.log.debug('Get brightness ->', brightness);
|
|
94
|
-
return brightness;
|
|
95
|
-
}
|
|
96
|
-
return 100;
|
|
103
|
+
const device = this.device;
|
|
104
|
+
return device.brightness || 100;
|
|
97
105
|
}
|
|
98
106
|
catch (error) {
|
|
99
107
|
this.platform.log.error('Failed to get brightness:', error);
|
|
100
108
|
throw error;
|
|
101
109
|
}
|
|
102
110
|
}
|
|
111
|
+
async setFanSpeed(value) {
|
|
112
|
+
try {
|
|
113
|
+
const device = this.device;
|
|
114
|
+
// Convert HomeKit 0-100 to device speed levels
|
|
115
|
+
const speed = Math.ceil(value / (100 / device.maxSpeed));
|
|
116
|
+
await device.setSpeed(speed);
|
|
117
|
+
this.platform.log.debug('Set fan speed ->', speed);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.platform.log.error('Failed to set fan speed:', error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async getFanSpeed() {
|
|
125
|
+
try {
|
|
126
|
+
const device = this.device;
|
|
127
|
+
// Convert device speed levels to HomeKit 0-100
|
|
128
|
+
return (device.speed || 0) * (100 / device.maxSpeed);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
this.platform.log.error('Failed to get fan speed:', error);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
103
135
|
}
|
|
104
136
|
exports.TSVESyncAccessory = TSVESyncAccessory;
|
|
105
137
|
//# sourceMappingURL=platformAccessory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;AAqBA,MAAa,iBAAiB;IAG5B,YACmB,QAA0B,EAC1B,SAA4B,EAC5B,MAAwB;QAFxB,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAkB;QAEzC,4BAA4B;QAC5B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACnE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,QAAQ,CAAC;aACtE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;aACxE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAE5E,sDAAsD;QACtD,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEO,YAAY;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;QAE1C,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copyright (c) 2024 Mick Giles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# TSVeSync
|
|
2
|
+
|
|
3
|
+
A TypeScript library for interacting with VeSync smart home devices. This library provides a modern, type-safe interface for controlling VeSync devices including air purifiers, outlets, and switches.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full TypeScript support with type definitions
|
|
8
|
+
- Support for multiple device types:
|
|
9
|
+
- Air Purifiers (Core200S, Core300S, Core400S, Core600S, LV-PUR131S, Vital100S, Vital200S, EverestAir)
|
|
10
|
+
- Humidifiers (Classic300S, Classic200S, Dual200S, LV600S, OasisMist series, Superior6000S)
|
|
11
|
+
- Smart Bulbs (ESL100, ESL100CW, ESL100MC, XYD0001)
|
|
12
|
+
- Outlets (15A, 10A, 7A models)
|
|
13
|
+
- Smart Tower Fans (LTF-F422S series)
|
|
14
|
+
- Real-time device status and control
|
|
15
|
+
- Energy monitoring for supported devices
|
|
16
|
+
- Air quality monitoring for supported purifiers
|
|
17
|
+
- Humidity control for supported humidifiers
|
|
18
|
+
- RGB and color temperature control for smart bulbs
|
|
19
|
+
- Fan speed and mode control
|
|
20
|
+
- Comprehensive error handling
|
|
21
|
+
- Modern async/await API
|
|
22
|
+
|
|
23
|
+
## Supported Devices
|
|
24
|
+
|
|
25
|
+
### Air Purifiers
|
|
26
|
+
- Core200S
|
|
27
|
+
- Features: Sleep mode, Manual mode, Filter life monitoring
|
|
28
|
+
- Fan speeds: 1-3
|
|
29
|
+
- Core300S
|
|
30
|
+
- Features: Auto mode, Sleep mode, Manual mode, Air quality monitoring
|
|
31
|
+
- Fan speeds: 1-4
|
|
32
|
+
- Core400S
|
|
33
|
+
- Features: Auto mode, Sleep mode, Manual mode, Air quality monitoring
|
|
34
|
+
- Fan speeds: 1-4
|
|
35
|
+
- Core600S
|
|
36
|
+
- Features: Auto mode, Sleep mode, Manual mode, Air quality monitoring
|
|
37
|
+
- Fan speeds: 1-4
|
|
38
|
+
- LV-PUR131S
|
|
39
|
+
- Features: Air quality monitoring
|
|
40
|
+
- Vital100S
|
|
41
|
+
- Features: Air quality monitoring, Pet mode
|
|
42
|
+
- Modes: Manual, Auto, Sleep, Pet
|
|
43
|
+
- Fan speeds: 1-4
|
|
44
|
+
- Vital200S
|
|
45
|
+
- Features: Air quality monitoring, Pet mode
|
|
46
|
+
- Modes: Manual, Auto, Sleep, Pet
|
|
47
|
+
- Fan speeds: 1-4
|
|
48
|
+
- EverestAir
|
|
49
|
+
- Features: Air quality monitoring, Fan rotation, Turbo mode
|
|
50
|
+
- Modes: Manual, Auto, Sleep, Turbo
|
|
51
|
+
- Fan speeds: 1-3
|
|
52
|
+
|
|
53
|
+
### Humidifiers
|
|
54
|
+
- Classic300S
|
|
55
|
+
- Features: Nightlight
|
|
56
|
+
- Modes: Auto, Sleep, Manual
|
|
57
|
+
- Mist levels: 1-9
|
|
58
|
+
- Classic200S
|
|
59
|
+
- Modes: Auto, Manual
|
|
60
|
+
- Mist levels: 1-9
|
|
61
|
+
- Dual200S
|
|
62
|
+
- Modes: Auto, Manual
|
|
63
|
+
- Mist levels: 1-2
|
|
64
|
+
- LV600S
|
|
65
|
+
- Features: Warm mist, Nightlight
|
|
66
|
+
- Modes: Humidity, Sleep, Manual
|
|
67
|
+
- Mist levels: 1-9
|
|
68
|
+
- Warm mist levels: 0-3
|
|
69
|
+
- OasisMist (EU)
|
|
70
|
+
- Features: Warm mist, Nightlight
|
|
71
|
+
- Modes: Auto, Manual
|
|
72
|
+
- Mist levels: 1-9
|
|
73
|
+
- Warm mist levels: 0-3
|
|
74
|
+
- OasisMist (US)
|
|
75
|
+
- Features: Warm mist
|
|
76
|
+
- Modes: Auto, Humidity, Sleep, Manual
|
|
77
|
+
- Mist levels: 1-9
|
|
78
|
+
- Warm mist levels: 0-3
|
|
79
|
+
- OasisMist1000S
|
|
80
|
+
- Modes: Auto, Sleep, Manual
|
|
81
|
+
- Mist levels: 1-9
|
|
82
|
+
- Superior6000S
|
|
83
|
+
- Modes: Auto, Humidity, Sleep, Manual
|
|
84
|
+
- Mist levels: 1-9
|
|
85
|
+
|
|
86
|
+
### Smart Bulbs
|
|
87
|
+
- ESL100
|
|
88
|
+
- Features: Basic white light
|
|
89
|
+
- Brightness control
|
|
90
|
+
- ESL100CW
|
|
91
|
+
- Features: Tunable white light
|
|
92
|
+
- Brightness control
|
|
93
|
+
- Color temperature control (warm to cool white)
|
|
94
|
+
- ESL100MC
|
|
95
|
+
- Features: Full RGB color
|
|
96
|
+
- White and color modes
|
|
97
|
+
- Brightness control
|
|
98
|
+
- RGB color control
|
|
99
|
+
- XYD0001
|
|
100
|
+
- Features: Full RGB color with HSV control
|
|
101
|
+
- White and color modes
|
|
102
|
+
- Brightness control
|
|
103
|
+
- Color temperature control
|
|
104
|
+
- HSV (Hue, Saturation, Value) color control
|
|
105
|
+
|
|
106
|
+
### Outlets
|
|
107
|
+
- 15A Outlet (ESO15-TB)
|
|
108
|
+
- Power monitoring
|
|
109
|
+
- Energy usage tracking (daily/weekly/monthly/yearly)
|
|
110
|
+
- Voltage monitoring
|
|
111
|
+
- Outdoor rated
|
|
112
|
+
- 15A Outlet (ESW15-USA)
|
|
113
|
+
- Power monitoring
|
|
114
|
+
- Energy usage tracking (daily/weekly/monthly/yearly)
|
|
115
|
+
- Voltage monitoring
|
|
116
|
+
- 10A Outlet (ESW03-USA)
|
|
117
|
+
- Power monitoring
|
|
118
|
+
- Energy usage tracking (daily/weekly/monthly/yearly)
|
|
119
|
+
- Voltage monitoring
|
|
120
|
+
- 10A Outlet (ESW01-EU)
|
|
121
|
+
- Power monitoring
|
|
122
|
+
- Energy usage tracking (daily/weekly/monthly/yearly)
|
|
123
|
+
- Voltage monitoring
|
|
124
|
+
- 7A Outlet (wifi-switch-1.3)
|
|
125
|
+
- Energy usage tracking (daily/weekly/monthly/yearly)
|
|
126
|
+
|
|
127
|
+
### Smart Tower Fan
|
|
128
|
+
- LTF-F422S Series
|
|
129
|
+
- Features: Fan speed control
|
|
130
|
+
- Modes: Normal, Auto, Advanced Sleep, Turbo
|
|
131
|
+
- Fan speeds: 1-12
|
|
132
|
+
|
|
133
|
+
## Installation
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm install tsvesync
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Usage
|
|
140
|
+
|
|
141
|
+
### Basic Setup
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { VeSync } from 'tsvesync';
|
|
145
|
+
|
|
146
|
+
// Create a VeSync manager instance
|
|
147
|
+
const manager = new VeSync(username, password);
|
|
148
|
+
|
|
149
|
+
// Login
|
|
150
|
+
await manager.login();
|
|
151
|
+
|
|
152
|
+
// Get all devices
|
|
153
|
+
await manager.getDevices();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Working with Devices
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Get device status
|
|
160
|
+
for (const device of manager.devices) {
|
|
161
|
+
await device.update();
|
|
162
|
+
console.log(`${device.deviceName}: ${device.deviceStatus}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Control an air purifier
|
|
166
|
+
const fan = manager.devices.find(d => d.deviceType === 'Core300S');
|
|
167
|
+
if (fan) {
|
|
168
|
+
await fan.setMode('auto'); // Available modes: auto, sleep, manual
|
|
169
|
+
await fan.setSpeed(2); // Speed range depends on model
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Control an outlet
|
|
173
|
+
const outlet = manager.devices.find(d => d.deviceType === 'ESO15-TB');
|
|
174
|
+
if (outlet) {
|
|
175
|
+
await outlet.turnOn();
|
|
176
|
+
const energy = await outlet.getEnergyUsage();
|
|
177
|
+
console.log('Current power usage:', energy.power, 'W');
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Environment Variables
|
|
182
|
+
|
|
183
|
+
The library supports configuration through environment variables:
|
|
184
|
+
|
|
185
|
+
```env
|
|
186
|
+
VESYNC_USERNAME=your_email@example.com
|
|
187
|
+
VESYNC_PASSWORD=your_password
|
|
188
|
+
VESYNC_API_URL=https://smartapi.vesync.com # Optional, defaults to standard API URL
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Testing
|
|
192
|
+
|
|
193
|
+
The project includes a comprehensive test suite:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Run the standard test suite
|
|
197
|
+
npm test
|
|
198
|
+
|
|
199
|
+
# Run the special device test (requires .env configuration)
|
|
200
|
+
npx ts-node test/testSpecial.ts
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
### Building
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm run build
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Linting
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm run lint
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT
|
|
224
|
+
|
|
225
|
+
## Acknowledgments
|
|
226
|
+
|
|
227
|
+
This project is inspired by the PyVeSync Python library and aims to provide similar functionality for TypeScript/JavaScript developers.
|