tsvesync 1.0.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/LICENSE +21 -0
- package/README.md +227 -0
- package/api/vesync/VeSync.yaml +33 -0
- package/api/vesyncbulb/ESL100.yaml +74 -0
- package/api/vesyncbulb/ESL100CW.yaml +123 -0
- package/api/vesyncbulb/ESL100MC.yaml +169 -0
- package/api/vesyncbulb/XYD0001.yaml +193 -0
- package/api/vesyncfan/Classic200S.yaml +280 -0
- package/api/vesyncfan/Classic300S.yaml +278 -0
- package/api/vesyncfan/Core200S.yaml +256 -0
- package/api/vesyncfan/Core300S.yaml +281 -0
- package/api/vesyncfan/Core400S.yaml +281 -0
- package/api/vesyncfan/Core600S.yaml +281 -0
- package/api/vesyncfan/Dual200S.yaml +278 -0
- package/api/vesyncfan/LAP-C201S-AUSR.yaml +256 -0
- package/api/vesyncfan/LAP-C202S-WUSR.yaml +256 -0
- package/api/vesyncfan/LAP-C301S-WAAA.yaml +281 -0
- package/api/vesyncfan/LAP-C301S-WJP.yaml +281 -0
- package/api/vesyncfan/LAP-C302S-WUSB.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WAAA.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WJP.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WUSR.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WEU.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WUS.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WUSR.yaml +281 -0
- package/api/vesyncfan/LAP-EL551S-AEUR.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-AUS.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-WUS.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-AASR.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WJP.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WUS.yaml +167 -0
- package/api/vesyncfan/LAP-V201-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AASR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AEUR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WJP.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WUS.yaml +167 -0
- package/api/vesyncfan/LEH-S601S-WUS.yaml +303 -0
- package/api/vesyncfan/LEH-S601S-WUSR.yaml +82 -0
- package/api/vesyncfan/LTF-F422S-KEU.yaml +165 -0
- package/api/vesyncfan/LTF-F422S-WUS.yaml +165 -0
- package/api/vesyncfan/LTF-F422S-WUSR.yaml +167 -0
- package/api/vesyncfan/LTF-F422_WJP.yaml +165 -0
- package/api/vesyncfan/LUH-A601S-AUSW.yaml +82 -0
- package/api/vesyncfan/LUH-A601S-WUSB.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WEU.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WEUR.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WJP.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUS.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUSC.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WEU.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WJP.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-M101S-WUS.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WEU.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WUS.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-O601S-KUS.yaml +305 -0
- package/api/vesyncfan/LUH-O601S-WUS.yaml +305 -0
- package/api/vesyncfan/LV-PUR131S.yaml +108 -0
- package/api/vesyncfan/LV-RH131S.yaml +108 -0
- package/api/vesyncoutlet/ESO15-TB.yaml +124 -0
- package/api/vesyncoutlet/ESW01-EU.yaml +122 -0
- package/api/vesyncoutlet/ESW03-USA.yaml +122 -0
- package/api/vesyncoutlet/ESW15-USA.yaml +156 -0
- package/api/vesyncoutlet/wifi-switch-1.3.yaml +60 -0
- package/api/vesyncswitch/ESWD16.yaml +128 -0
- package/api/vesyncswitch/ESWL01.yaml +56 -0
- package/api/vesyncswitch/ESWL03.yaml +56 -0
- package/dist/lib/helpers.d.ts +87 -0
- package/dist/lib/helpers.js +222 -0
- package/dist/lib/helpers.js.map +1 -0
- package/dist/lib/vesync.d.ts +47 -0
- package/dist/lib/vesync.js +309 -0
- package/dist/lib/vesync.js.map +1 -0
- package/dist/lib/vesyncBaseDevice.d.ts +68 -0
- package/dist/lib/vesyncBaseDevice.js +116 -0
- package/dist/lib/vesyncBaseDevice.js.map +1 -0
- package/dist/lib/vesyncBulb.d.ts +0 -0
- package/dist/lib/vesyncBulb.js +2 -0
- package/dist/lib/vesyncBulb.js.map +1 -0
- package/dist/lib/vesyncFan.d.ts +92 -0
- package/dist/lib/vesyncFan.js +265 -0
- package/dist/lib/vesyncFan.js.map +1 -0
- package/dist/lib/vesyncKitchen.d.ts +0 -0
- package/dist/lib/vesyncKitchen.js +2 -0
- package/dist/lib/vesyncKitchen.js.map +1 -0
- package/dist/lib/vesyncOutlet.d.ts +0 -0
- package/dist/lib/vesyncOutlet.js +2 -0
- package/dist/lib/vesyncOutlet.js.map +1 -0
- package/dist/lib/vesyncSwitch.d.ts +0 -0
- package/dist/lib/vesyncSwitch.js +2 -0
- package/dist/lib/vesyncSwitch.js.map +1 -0
- package/dist/src/lib/helpers.d.ts +88 -0
- package/dist/src/lib/helpers.js +244 -0
- package/dist/src/lib/vesync.d.ts +89 -0
- package/dist/src/lib/vesync.js +430 -0
- package/dist/src/lib/vesyncBaseDevice.d.ts +43 -0
- package/dist/src/lib/vesyncBaseDevice.js +87 -0
- package/dist/src/lib/vesyncBulb.d.ts +79 -0
- package/dist/src/lib/vesyncBulb.js +198 -0
- package/dist/src/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/src/lib/vesyncBulbImpl.js +161 -0
- package/dist/src/lib/vesyncFan.d.ts +80 -0
- package/dist/src/lib/vesyncFan.js +406 -0
- package/dist/src/lib/vesyncFanImpl.d.ts +137 -0
- package/dist/src/lib/vesyncFanImpl.js +643 -0
- package/dist/src/lib/vesyncOutlet.d.ts +53 -0
- package/dist/src/lib/vesyncOutlet.js +98 -0
- package/dist/src/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/src/lib/vesyncOutletImpl.js +206 -0
- package/dist/src/lib/vesyncSwitch.d.ts +169 -0
- package/dist/src/lib/vesyncSwitch.js +414 -0
- package/dist/src/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/src/lib/vesyncSwitchImpl.js +290 -0
- package/dist/test/testFeatures.d.ts +4 -0
- package/dist/test/testFeatures.js +394 -0
- package/dist/test/testService.d.ts +62 -0
- package/dist/test/testService.js +540 -0
- package/dist/test/testSpecial.d.ts +5 -0
- package/dist/test/testSpecial.js +227 -0
- package/package.json +53 -0
- package/src/lib/helpers.ts +290 -0
- package/src/lib/vesync.ts +530 -0
- package/src/lib/vesyncBaseDevice.ts +114 -0
- package/src/lib/vesyncBulb.ts +252 -0
- package/src/lib/vesyncBulbImpl.ts +215 -0
- package/src/lib/vesyncFan.ts +447 -0
- package/src/lib/vesyncFanImpl.ts +848 -0
- package/src/lib/vesyncOutlet.ts +148 -0
- package/src/lib/vesyncOutletImpl.ts +284 -0
- package/src/lib/vesyncSwitch.ts +546 -0
- package/src/lib/vesyncSwitchImpl.ts +408 -0
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeSync Switch Classes
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
6
|
+
import { VeSync } from './vesync';
|
|
7
|
+
import { Helpers } from './helpers';
|
|
8
|
+
|
|
9
|
+
type DeviceConstructor = new (config: Record<string, any>, manager: VeSync) => VeSyncBaseDevice;
|
|
10
|
+
|
|
11
|
+
interface SwitchConfig {
|
|
12
|
+
[key: string]: {
|
|
13
|
+
module: string;
|
|
14
|
+
features: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Switch configuration
|
|
19
|
+
export const switchConfig: SwitchConfig = {
|
|
20
|
+
'ESWL01': {
|
|
21
|
+
module: 'VeSyncWallSwitch',
|
|
22
|
+
features: []
|
|
23
|
+
},
|
|
24
|
+
'ESWD16': {
|
|
25
|
+
module: 'VeSyncDimmerSwitch',
|
|
26
|
+
features: ['dimmable']
|
|
27
|
+
},
|
|
28
|
+
'ESWL03': {
|
|
29
|
+
module: 'VeSyncWallSwitch',
|
|
30
|
+
features: []
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Base class for VeSync Switches
|
|
36
|
+
*/
|
|
37
|
+
export abstract class VeSyncSwitch extends VeSyncBaseDevice {
|
|
38
|
+
protected details: Record<string, any> = {};
|
|
39
|
+
protected features: string[] = [];
|
|
40
|
+
|
|
41
|
+
constructor(details: Record<string, any>, manager: VeSync) {
|
|
42
|
+
super(details, manager);
|
|
43
|
+
this.details = details;
|
|
44
|
+
this.features = switchConfig[this.deviceType]?.features || [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get active time of switch
|
|
49
|
+
*/
|
|
50
|
+
get activeTime(): number {
|
|
51
|
+
return this.details.active_time ?? 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Return true if switch is dimmable
|
|
56
|
+
*/
|
|
57
|
+
isDimmable(): boolean {
|
|
58
|
+
return this.features.includes('dimmable');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return formatted device info to stdout
|
|
63
|
+
*/
|
|
64
|
+
display(): void {
|
|
65
|
+
super.display();
|
|
66
|
+
const info = [
|
|
67
|
+
['Active Time:', this.activeTime]
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
for (const [key, value] of info) {
|
|
71
|
+
console.log(`${key.toString().padEnd(30, '.')} ${value}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Return JSON details for switch
|
|
77
|
+
*/
|
|
78
|
+
displayJSON(): string {
|
|
79
|
+
const baseInfo = JSON.parse(super.displayJSON());
|
|
80
|
+
return JSON.stringify({
|
|
81
|
+
...baseInfo,
|
|
82
|
+
'Active Time': this.activeTime
|
|
83
|
+
}, null, 4);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
abstract getDetails(): Promise<void>;
|
|
87
|
+
abstract getConfig(): Promise<void>;
|
|
88
|
+
abstract turnOn(): Promise<boolean>;
|
|
89
|
+
abstract turnOff(): Promise<boolean>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Update device details
|
|
93
|
+
*/
|
|
94
|
+
async update(): Promise<void> {
|
|
95
|
+
await this.getDetails();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* VeSync Wall Switch
|
|
101
|
+
*/
|
|
102
|
+
export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
103
|
+
constructor(details: Record<string, any>, manager: VeSync) {
|
|
104
|
+
super(details, manager);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get wall switch details
|
|
109
|
+
*/
|
|
110
|
+
async getDetails(): Promise<void> {
|
|
111
|
+
const body = Helpers.reqBody(this.manager, 'devicedetail');
|
|
112
|
+
body.uuid = this.uuid;
|
|
113
|
+
|
|
114
|
+
const [response] = await Helpers.callApi(
|
|
115
|
+
'/inwallswitch/v1/device/devicedetail',
|
|
116
|
+
'post',
|
|
117
|
+
body,
|
|
118
|
+
Helpers.reqHeaders(this.manager)
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
if (response?.code === 0 && response?.result) {
|
|
122
|
+
const result = response.result;
|
|
123
|
+
this.deviceStatus = result.deviceStatus ?? this.deviceStatus;
|
|
124
|
+
this.details.active_time = result.activeTime ?? 0;
|
|
125
|
+
this.connectionStatus = result.connectionStatus ?? this.connectionStatus;
|
|
126
|
+
} else {
|
|
127
|
+
console.debug(`Error getting ${this.deviceName} details`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get switch device configuration info
|
|
133
|
+
*/
|
|
134
|
+
async getConfig(): Promise<void> {
|
|
135
|
+
const body = Helpers.reqBody(this.manager, 'devicedetail');
|
|
136
|
+
body.method = 'configurations';
|
|
137
|
+
body.uuid = this.uuid;
|
|
138
|
+
|
|
139
|
+
const [response] = await Helpers.callApi(
|
|
140
|
+
'/inwallswitch/v1/device/configurations',
|
|
141
|
+
'post',
|
|
142
|
+
body,
|
|
143
|
+
Helpers.reqHeaders(this.manager)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
if (response?.code === 0) {
|
|
147
|
+
this.config = Helpers.buildConfigDict(response);
|
|
148
|
+
} else {
|
|
149
|
+
console.debug(`Unable to get ${this.deviceName} config info`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Turn off wall switch
|
|
155
|
+
*/
|
|
156
|
+
async turnOff(): Promise<boolean> {
|
|
157
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
158
|
+
body.status = 'off';
|
|
159
|
+
body.uuid = this.uuid;
|
|
160
|
+
|
|
161
|
+
const [response] = await Helpers.callApi(
|
|
162
|
+
'/inwallswitch/v1/device/devicestatus',
|
|
163
|
+
'put',
|
|
164
|
+
body,
|
|
165
|
+
Helpers.reqHeaders(this.manager)
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (response?.code === 0) {
|
|
169
|
+
this.deviceStatus = 'off';
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
console.debug(`Error turning ${this.deviceName} off`);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Turn on wall switch
|
|
178
|
+
*/
|
|
179
|
+
async turnOn(): Promise<boolean> {
|
|
180
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
181
|
+
body.status = 'on';
|
|
182
|
+
body.uuid = this.uuid;
|
|
183
|
+
|
|
184
|
+
const [response] = await Helpers.callApi(
|
|
185
|
+
'/inwallswitch/v1/device/devicestatus',
|
|
186
|
+
'put',
|
|
187
|
+
body,
|
|
188
|
+
Helpers.reqHeaders(this.manager)
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
if (response?.code === 0) {
|
|
192
|
+
this.deviceStatus = 'on';
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
console.debug(`Error turning ${this.deviceName} on`);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* VeSync Dimmer Switch
|
|
202
|
+
*/
|
|
203
|
+
export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
204
|
+
private _brightness: number = 0;
|
|
205
|
+
private _rgbValue: Record<string, number> = { red: 0, blue: 0, green: 0 };
|
|
206
|
+
private _rgbStatus: string = 'unknown';
|
|
207
|
+
private _indicatorLight: string = 'unknown';
|
|
208
|
+
|
|
209
|
+
constructor(details: Record<string, any>, manager: VeSync) {
|
|
210
|
+
super(details, manager);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Get dimmer switch details
|
|
215
|
+
*/
|
|
216
|
+
async getDetails(): Promise<void> {
|
|
217
|
+
const body = Helpers.reqBody(this.manager, 'devicedetail');
|
|
218
|
+
body.uuid = this.uuid;
|
|
219
|
+
|
|
220
|
+
const [response] = await Helpers.callApi(
|
|
221
|
+
'/dimmer/v1/device/devicedetail',
|
|
222
|
+
'post',
|
|
223
|
+
body,
|
|
224
|
+
Helpers.reqHeaders(this.manager)
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
if (response?.code === 0 && response?.result) {
|
|
228
|
+
const result = response.result;
|
|
229
|
+
this.deviceStatus = result.deviceStatus ?? this.deviceStatus;
|
|
230
|
+
this.details.active_time = result.activeTime ?? 0;
|
|
231
|
+
this.connectionStatus = result.connectionStatus ?? this.connectionStatus;
|
|
232
|
+
this._brightness = result.brightness ?? this._brightness;
|
|
233
|
+
this._rgbStatus = result.rgbStatus ?? this._rgbStatus;
|
|
234
|
+
this._indicatorLight = result.indicatorlightStatus ?? this._indicatorLight;
|
|
235
|
+
if (result.rgbValue) {
|
|
236
|
+
this._rgbValue = {
|
|
237
|
+
red: result.rgbValue.red ?? 0,
|
|
238
|
+
green: result.rgbValue.green ?? 0,
|
|
239
|
+
blue: result.rgbValue.blue ?? 0
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
console.debug(`Error getting ${this.deviceName} details`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get dimmer switch configuration info
|
|
249
|
+
*/
|
|
250
|
+
async getConfig(): Promise<void> {
|
|
251
|
+
const body = Helpers.reqBody(this.manager, 'devicedetail');
|
|
252
|
+
body.method = 'configurations';
|
|
253
|
+
body.uuid = this.uuid;
|
|
254
|
+
|
|
255
|
+
const [response] = await Helpers.callApi(
|
|
256
|
+
'/dimmer/v1/device/configurations',
|
|
257
|
+
'post',
|
|
258
|
+
body,
|
|
259
|
+
Helpers.reqHeaders(this.manager)
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
if (response?.code === 0) {
|
|
263
|
+
this.config = Helpers.buildConfigDict(response);
|
|
264
|
+
} else {
|
|
265
|
+
console.debug(`Unable to get ${this.deviceName} config info`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Turn off dimmer switch
|
|
271
|
+
*/
|
|
272
|
+
async turnOff(): Promise<boolean> {
|
|
273
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
274
|
+
body.status = 'off';
|
|
275
|
+
body.uuid = this.uuid;
|
|
276
|
+
|
|
277
|
+
const [response] = await Helpers.callApi(
|
|
278
|
+
'/dimmer/v1/device/devicestatus',
|
|
279
|
+
'put',
|
|
280
|
+
body,
|
|
281
|
+
Helpers.reqHeaders(this.manager)
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
if (response?.code === 0) {
|
|
285
|
+
this.deviceStatus = 'off';
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
console.debug(`Error turning ${this.deviceName} off`);
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Turn on dimmer switch
|
|
294
|
+
*/
|
|
295
|
+
async turnOn(): Promise<boolean> {
|
|
296
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
297
|
+
body.status = 'on';
|
|
298
|
+
body.uuid = this.uuid;
|
|
299
|
+
|
|
300
|
+
const [response] = await Helpers.callApi(
|
|
301
|
+
'/dimmer/v1/device/devicestatus',
|
|
302
|
+
'put',
|
|
303
|
+
body,
|
|
304
|
+
Helpers.reqHeaders(this.manager)
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
if (response?.code === 0) {
|
|
308
|
+
this.deviceStatus = 'on';
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
console.debug(`Error turning ${this.deviceName} on`);
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Return brightness in percent
|
|
317
|
+
*/
|
|
318
|
+
get brightness(): number {
|
|
319
|
+
return this._brightness;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Return faceplate brightness light status
|
|
324
|
+
*/
|
|
325
|
+
get indicatorLightStatus(): string {
|
|
326
|
+
return this._indicatorLight;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Return RGB faceplate light status
|
|
331
|
+
*/
|
|
332
|
+
get rgbLightStatus(): string {
|
|
333
|
+
return this._rgbStatus;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Return RGB light values
|
|
338
|
+
*/
|
|
339
|
+
get rgbLightValue(): Record<string, number> {
|
|
340
|
+
return this._rgbValue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Update device details
|
|
345
|
+
*/
|
|
346
|
+
async update(): Promise<void> {
|
|
347
|
+
await this.getDetails();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Display device info
|
|
352
|
+
*/
|
|
353
|
+
display(): void {
|
|
354
|
+
super.display();
|
|
355
|
+
const info = [
|
|
356
|
+
['Brightness:', this.brightness, '%'],
|
|
357
|
+
['RGB Status:', this.rgbLightStatus],
|
|
358
|
+
['RGB Values:', JSON.stringify(this.rgbLightValue)],
|
|
359
|
+
['Indicator Light:', this.indicatorLightStatus]
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
for (const [key, value, unit = ''] of info) {
|
|
363
|
+
console.log(`${key.toString().padEnd(30, '.')} ${value}${unit}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Return JSON details for dimmer switch
|
|
369
|
+
*/
|
|
370
|
+
displayJSON(): string {
|
|
371
|
+
const baseInfo = JSON.parse(super.displayJSON());
|
|
372
|
+
return JSON.stringify({
|
|
373
|
+
...baseInfo,
|
|
374
|
+
'Brightness': this.brightness,
|
|
375
|
+
'RGB Status': this.rgbLightStatus,
|
|
376
|
+
'RGB Values': this.rgbLightValue,
|
|
377
|
+
'Indicator Light': this.indicatorLightStatus
|
|
378
|
+
}, null, 4);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Set brightness level
|
|
383
|
+
* @param brightness - Brightness level (1-100)
|
|
384
|
+
*/
|
|
385
|
+
async setBrightness(brightness: number): Promise<boolean> {
|
|
386
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
387
|
+
body.uuid = this.uuid;
|
|
388
|
+
body.brightness = brightness;
|
|
389
|
+
|
|
390
|
+
const [response] = await Helpers.callApi(
|
|
391
|
+
'/dimmer/v1/device/updatebrightness',
|
|
392
|
+
'put',
|
|
393
|
+
body,
|
|
394
|
+
Helpers.reqHeaders(this.manager)
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
if (response?.code === 0) {
|
|
398
|
+
this._brightness = brightness;
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
console.debug(`Error setting ${this.deviceName} brightness`);
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Toggle indicator light status
|
|
407
|
+
* @param status - Light status ('on' or 'off')
|
|
408
|
+
*/
|
|
409
|
+
async indicatorLightToggle(status: string): Promise<boolean> {
|
|
410
|
+
if (status !== 'on' && status !== 'off') {
|
|
411
|
+
console.debug('Invalid status passed to indicator light toggle');
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
416
|
+
body.uuid = this.uuid;
|
|
417
|
+
body.status = status;
|
|
418
|
+
|
|
419
|
+
const [response] = await Helpers.callApi(
|
|
420
|
+
'/dimmer/v1/device/indicatorlightstatus',
|
|
421
|
+
'put',
|
|
422
|
+
body,
|
|
423
|
+
Helpers.reqHeaders(this.manager)
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
if (response?.code === 0) {
|
|
427
|
+
this._indicatorLight = status;
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
console.debug(`Error toggling ${this.deviceName} indicator light`);
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Set RGB color values
|
|
436
|
+
* @param red - Red value (0-255)
|
|
437
|
+
* @param green - Green value (0-255)
|
|
438
|
+
* @param blue - Blue value (0-255)
|
|
439
|
+
*/
|
|
440
|
+
async rgbColorSet(red: number, green: number, blue: number): Promise<boolean> {
|
|
441
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
442
|
+
body.uuid = this.uuid;
|
|
443
|
+
body.rgbValue = { red, green, blue };
|
|
444
|
+
body.status = 'on';
|
|
445
|
+
|
|
446
|
+
const [response] = await Helpers.callApi(
|
|
447
|
+
'/dimmer/v1/device/devicergbstatus',
|
|
448
|
+
'put',
|
|
449
|
+
body,
|
|
450
|
+
Helpers.reqHeaders(this.manager)
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
if (response?.code === 0) {
|
|
454
|
+
this._rgbValue = { red, green, blue };
|
|
455
|
+
this._rgbStatus = 'on';
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
console.debug(`Error setting ${this.deviceName} RGB color`);
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Toggle switch status
|
|
464
|
+
* @param status - Switch status ('on' or 'off')
|
|
465
|
+
*/
|
|
466
|
+
async switchToggle(status: string): Promise<boolean> {
|
|
467
|
+
if (status !== 'on' && status !== 'off') {
|
|
468
|
+
console.debug('Invalid status passed to switch toggle');
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return status === 'on' ? this.turnOn() : this.turnOff();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Set faceplate RGB color status and optionally set RGB values
|
|
477
|
+
* @param status - RGB status ('on' or 'off')
|
|
478
|
+
* @param red - Optional red value (0-255)
|
|
479
|
+
* @param green - Optional green value (0-255)
|
|
480
|
+
* @param blue - Optional blue value (0-255)
|
|
481
|
+
*/
|
|
482
|
+
async rgbColorStatus(status: string, red?: number, green?: number, blue?: number): Promise<boolean> {
|
|
483
|
+
if (status !== 'on' && status !== 'off') {
|
|
484
|
+
console.debug('Invalid status passed to RGB color status');
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const body = Helpers.reqBody(this.manager, 'devicestatus');
|
|
489
|
+
body.uuid = this.uuid;
|
|
490
|
+
body.status = status;
|
|
491
|
+
|
|
492
|
+
if (red !== undefined && green !== undefined && blue !== undefined) {
|
|
493
|
+
body.rgbValue = { red, green, blue };
|
|
494
|
+
this._rgbValue = { red, green, blue };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const [response] = await Helpers.callApi(
|
|
498
|
+
'/dimmer/v1/device/devicergbstatus',
|
|
499
|
+
'put',
|
|
500
|
+
body,
|
|
501
|
+
Helpers.reqHeaders(this.manager)
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
if (response?.code === 0) {
|
|
505
|
+
this._rgbStatus = status;
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
console.debug(`Error setting ${this.deviceName} RGB status`);
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Turn RGB Color Off
|
|
514
|
+
*/
|
|
515
|
+
async rgbColorOff(): Promise<boolean> {
|
|
516
|
+
return this.rgbColorStatus('off');
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Turn RGB Color On
|
|
521
|
+
*/
|
|
522
|
+
async rgbColorOn(): Promise<boolean> {
|
|
523
|
+
return this.rgbColorStatus('on');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Turn indicator light on
|
|
528
|
+
*/
|
|
529
|
+
async indicatorLightOn(): Promise<boolean> {
|
|
530
|
+
return this.indicatorLightToggle('on');
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Turn indicator light off
|
|
535
|
+
*/
|
|
536
|
+
async indicatorLightOff(): Promise<boolean> {
|
|
537
|
+
return this.indicatorLightToggle('off');
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Export switch modules for device factory
|
|
542
|
+
export const switchModules: Record<string, DeviceConstructor> = {
|
|
543
|
+
'ESWL01': VeSyncWallSwitch,
|
|
544
|
+
'ESWL03': VeSyncWallSwitch,
|
|
545
|
+
'ESWD16': VeSyncDimmerSwitch
|
|
546
|
+
};
|