homebridge-tsvesync 1.0.0 → 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/config.schema.json +77 -0
- package/dist/platform.d.ts +7 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +69 -21
- 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 +34 -10
- package/src/platform.ts +87 -22
- package/src/platformAccessory.ts +104 -51
- package/tsvesync-1.0.11.tgz +0 -0
package/src/platformAccessory.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
2
2
|
import { TSVESyncPlatform } from './platform';
|
|
3
|
-
import {
|
|
3
|
+
import { VeSyncBaseDevice } from 'tsvesync/dist/src/lib/vesyncBaseDevice';
|
|
4
|
+
|
|
5
|
+
interface VeSyncDeviceWithPower extends VeSyncBaseDevice {
|
|
6
|
+
deviceStatus: string;
|
|
7
|
+
turnOn(): Promise<boolean>;
|
|
8
|
+
turnOff(): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface VeSyncDeviceWithBrightness extends VeSyncDeviceWithPower {
|
|
12
|
+
brightness: number;
|
|
13
|
+
setBrightness(value: number): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface VeSyncDeviceWithSpeed extends VeSyncDeviceWithPower {
|
|
17
|
+
speed: number;
|
|
18
|
+
maxSpeed: number;
|
|
19
|
+
setSpeed(value: number): Promise<boolean>;
|
|
20
|
+
}
|
|
4
21
|
|
|
5
22
|
export class TSVESyncAccessory {
|
|
6
23
|
private service!: Service;
|
|
@@ -8,51 +25,81 @@ export class TSVESyncAccessory {
|
|
|
8
25
|
constructor(
|
|
9
26
|
private readonly platform: TSVESyncPlatform,
|
|
10
27
|
private readonly accessory: PlatformAccessory,
|
|
11
|
-
private readonly
|
|
28
|
+
private readonly device: VeSyncBaseDevice,
|
|
12
29
|
) {
|
|
13
|
-
// Get the device from context
|
|
14
|
-
const device = accessory.context.device as Device;
|
|
15
|
-
|
|
16
30
|
// set accessory information
|
|
17
31
|
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
18
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer, '
|
|
19
|
-
.setCharacteristic(this.platform.Characteristic.Model, device.
|
|
20
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.
|
|
32
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'VeSync')
|
|
33
|
+
.setCharacteristic(this.platform.Characteristic.Model, device.deviceType)
|
|
34
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.cid);
|
|
21
35
|
|
|
22
36
|
// Set up the appropriate service based on device type
|
|
23
|
-
this.setupService(
|
|
37
|
+
this.setupService();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private setupService() {
|
|
41
|
+
const deviceType = this.device.deviceType;
|
|
42
|
+
|
|
43
|
+
if (deviceType.includes('BULB')) {
|
|
44
|
+
this.setupBulb();
|
|
45
|
+
} else if (deviceType.includes('FAN') || deviceType.includes('AIR')) {
|
|
46
|
+
this.setupFan();
|
|
47
|
+
} else {
|
|
48
|
+
this.setupSwitch();
|
|
49
|
+
}
|
|
24
50
|
}
|
|
25
51
|
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Set up as a lightbulb if it supports brightness
|
|
30
|
-
this.service = this.accessory.getService(this.platform.Service.Lightbulb)
|
|
31
|
-
|| this.accessory.addService(this.platform.Service.Lightbulb);
|
|
52
|
+
private setupBulb() {
|
|
53
|
+
this.service = this.accessory.getService(this.platform.Service.Lightbulb)
|
|
54
|
+
|| this.accessory.addService(this.platform.Service.Lightbulb);
|
|
32
55
|
|
|
33
|
-
|
|
56
|
+
// Add brightness characteristic if device supports it
|
|
57
|
+
const bulb = this.device as VeSyncDeviceWithBrightness;
|
|
58
|
+
if ('setBrightness' in bulb) {
|
|
34
59
|
this.service.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
35
60
|
.onSet(this.setBrightness.bind(this))
|
|
36
61
|
.onGet(this.getBrightness.bind(this));
|
|
37
|
-
} else {
|
|
38
|
-
// Set up as a switch for basic on/off functionality
|
|
39
|
-
this.service = this.accessory.getService(this.platform.Service.Switch)
|
|
40
|
-
|| this.accessory.addService(this.platform.Service.Switch);
|
|
41
62
|
}
|
|
42
63
|
|
|
43
|
-
// Add on/off characteristic (common to both switch and lightbulb)
|
|
44
64
|
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
45
65
|
.onSet(this.setOn.bind(this))
|
|
46
66
|
.onGet(this.getOn.bind(this));
|
|
47
67
|
}
|
|
48
68
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
private setupFan() {
|
|
70
|
+
this.service = this.accessory.getService(this.platform.Service.Fan)
|
|
71
|
+
|| this.accessory.addService(this.platform.Service.Fan);
|
|
72
|
+
|
|
73
|
+
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
74
|
+
.onSet(this.setOn.bind(this))
|
|
75
|
+
.onGet(this.getOn.bind(this));
|
|
76
|
+
|
|
77
|
+
const fan = this.device as VeSyncDeviceWithSpeed;
|
|
78
|
+
if ('setSpeed' in fan) {
|
|
79
|
+
this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
80
|
+
.onSet(this.setFanSpeed.bind(this))
|
|
81
|
+
.onGet(this.getFanSpeed.bind(this));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private setupSwitch() {
|
|
86
|
+
this.service = this.accessory.getService(this.platform.Service.Switch)
|
|
87
|
+
|| this.accessory.addService(this.platform.Service.Switch);
|
|
88
|
+
|
|
89
|
+
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
90
|
+
.onSet(this.setOn.bind(this))
|
|
91
|
+
.onGet(this.getOn.bind(this));
|
|
92
|
+
}
|
|
93
|
+
|
|
52
94
|
async setOn(value: CharacteristicValue) {
|
|
53
95
|
try {
|
|
54
|
-
const device = this.
|
|
55
|
-
|
|
96
|
+
const device = this.device as VeSyncDeviceWithPower;
|
|
97
|
+
const newState = value as boolean;
|
|
98
|
+
if (newState) {
|
|
99
|
+
await device.turnOn();
|
|
100
|
+
} else {
|
|
101
|
+
await device.turnOff();
|
|
102
|
+
}
|
|
56
103
|
this.platform.log.debug('Set power state ->', value);
|
|
57
104
|
} catch (error) {
|
|
58
105
|
this.platform.log.error('Failed to set power state:', error);
|
|
@@ -60,52 +107,58 @@ export class TSVESyncAccessory {
|
|
|
60
107
|
}
|
|
61
108
|
}
|
|
62
109
|
|
|
63
|
-
/**
|
|
64
|
-
* Handle "GET" requests from HomeKit for power state
|
|
65
|
-
*/
|
|
66
110
|
async getOn(): Promise<CharacteristicValue> {
|
|
67
111
|
try {
|
|
68
|
-
const device = this.
|
|
69
|
-
|
|
70
|
-
this.platform.log.debug('Get power state ->', state);
|
|
71
|
-
return state;
|
|
112
|
+
const device = this.device as VeSyncDeviceWithPower;
|
|
113
|
+
return device.deviceStatus === 'on';
|
|
72
114
|
} catch (error) {
|
|
73
115
|
this.platform.log.error('Failed to get power state:', error);
|
|
74
116
|
throw error;
|
|
75
117
|
}
|
|
76
118
|
}
|
|
77
119
|
|
|
78
|
-
/**
|
|
79
|
-
* Handle "SET" requests from HomeKit for brightness
|
|
80
|
-
*/
|
|
81
120
|
async setBrightness(value: CharacteristicValue) {
|
|
82
121
|
try {
|
|
83
|
-
const device = this.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.platform.log.debug('Set brightness ->', value);
|
|
87
|
-
}
|
|
122
|
+
const device = this.device as VeSyncDeviceWithBrightness;
|
|
123
|
+
await device.setBrightness(value as number);
|
|
124
|
+
this.platform.log.debug('Set brightness ->', value);
|
|
88
125
|
} catch (error) {
|
|
89
126
|
this.platform.log.error('Failed to set brightness:', error);
|
|
90
127
|
throw error;
|
|
91
128
|
}
|
|
92
129
|
}
|
|
93
130
|
|
|
94
|
-
/**
|
|
95
|
-
* Handle "GET" requests from HomeKit for brightness
|
|
96
|
-
*/
|
|
97
131
|
async getBrightness(): Promise<CharacteristicValue> {
|
|
98
132
|
try {
|
|
99
|
-
const device = this.
|
|
100
|
-
|
|
101
|
-
const brightness = await this.client.getBrightness(device.id);
|
|
102
|
-
this.platform.log.debug('Get brightness ->', brightness);
|
|
103
|
-
return brightness;
|
|
104
|
-
}
|
|
105
|
-
return 100;
|
|
133
|
+
const device = this.device as VeSyncDeviceWithBrightness;
|
|
134
|
+
return device.brightness || 100;
|
|
106
135
|
} catch (error) {
|
|
107
136
|
this.platform.log.error('Failed to get brightness:', error);
|
|
108
137
|
throw error;
|
|
109
138
|
}
|
|
110
139
|
}
|
|
140
|
+
|
|
141
|
+
async setFanSpeed(value: CharacteristicValue) {
|
|
142
|
+
try {
|
|
143
|
+
const device = this.device as VeSyncDeviceWithSpeed;
|
|
144
|
+
// Convert HomeKit 0-100 to device speed levels
|
|
145
|
+
const speed = Math.ceil((value as number) / (100 / device.maxSpeed));
|
|
146
|
+
await device.setSpeed(speed);
|
|
147
|
+
this.platform.log.debug('Set fan speed ->', speed);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
this.platform.log.error('Failed to set fan speed:', error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async getFanSpeed(): Promise<CharacteristicValue> {
|
|
155
|
+
try {
|
|
156
|
+
const device = this.device as VeSyncDeviceWithSpeed;
|
|
157
|
+
// Convert device speed levels to HomeKit 0-100
|
|
158
|
+
return (device.speed || 0) * (100 / device.maxSpeed);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
this.platform.log.error('Failed to get fan speed:', error);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
111
164
|
}
|
|
Binary file
|