tsvesync 1.0.11 → 1.0.12

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.
@@ -1,2 +1,418 @@
1
1
  "use strict";
2
- //# sourceMappingURL=vesyncSwitch.js.map
2
+ /**
3
+ * VeSync Switch Classes
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.switchModules = exports.VeSyncDimmerSwitch = exports.VeSyncWallSwitch = exports.VeSyncSwitch = exports.switchConfig = void 0;
7
+ const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
8
+ const helpers_1 = require("./helpers");
9
+ // Switch configuration
10
+ exports.switchConfig = {
11
+ 'ESWL01': {
12
+ module: 'VeSyncWallSwitch',
13
+ features: []
14
+ },
15
+ 'ESWD16': {
16
+ module: 'VeSyncDimmerSwitch',
17
+ features: ['dimmable']
18
+ },
19
+ 'ESWL03': {
20
+ module: 'VeSyncWallSwitch',
21
+ features: []
22
+ }
23
+ };
24
+ /**
25
+ * Base class for VeSync Switches
26
+ */
27
+ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
28
+ constructor(details, manager) {
29
+ var _a;
30
+ super(details, manager);
31
+ this.details = {};
32
+ this.features = [];
33
+ this.details = details;
34
+ this.features = ((_a = exports.switchConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
35
+ }
36
+ /**
37
+ * Get active time of switch
38
+ */
39
+ get activeTime() {
40
+ var _a;
41
+ return (_a = this.details.active_time) !== null && _a !== void 0 ? _a : 0;
42
+ }
43
+ /**
44
+ * Return true if switch is dimmable
45
+ */
46
+ isDimmable() {
47
+ return this.features.includes('dimmable');
48
+ }
49
+ /**
50
+ * Return formatted device info to stdout
51
+ */
52
+ display() {
53
+ super.display();
54
+ const info = [
55
+ ['Active Time:', this.activeTime]
56
+ ];
57
+ for (const [key, value] of info) {
58
+ console.log(`${key.toString().padEnd(30, '.')} ${value}`);
59
+ }
60
+ }
61
+ /**
62
+ * Return JSON details for switch
63
+ */
64
+ displayJSON() {
65
+ const baseInfo = JSON.parse(super.displayJSON());
66
+ return JSON.stringify({
67
+ ...baseInfo,
68
+ 'Active Time': this.activeTime
69
+ }, null, 4);
70
+ }
71
+ /**
72
+ * Update device details
73
+ */
74
+ async update() {
75
+ await this.getDetails();
76
+ }
77
+ }
78
+ exports.VeSyncSwitch = VeSyncSwitch;
79
+ /**
80
+ * VeSync Wall Switch
81
+ */
82
+ class VeSyncWallSwitch extends VeSyncSwitch {
83
+ constructor(details, manager) {
84
+ super(details, manager);
85
+ }
86
+ /**
87
+ * Get wall switch details
88
+ */
89
+ async getDetails() {
90
+ var _a, _b, _c;
91
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
92
+ body.uuid = this.uuid;
93
+ const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
94
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
95
+ const result = response.result;
96
+ this.deviceStatus = (_a = result.deviceStatus) !== null && _a !== void 0 ? _a : this.deviceStatus;
97
+ this.details.active_time = (_b = result.activeTime) !== null && _b !== void 0 ? _b : 0;
98
+ this.connectionStatus = (_c = result.connectionStatus) !== null && _c !== void 0 ? _c : this.connectionStatus;
99
+ }
100
+ else {
101
+ console.debug(`Error getting ${this.deviceName} details`);
102
+ }
103
+ }
104
+ /**
105
+ * Get switch device configuration info
106
+ */
107
+ async getConfig() {
108
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
109
+ body.method = 'configurations';
110
+ body.uuid = this.uuid;
111
+ const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
112
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
113
+ this.config = helpers_1.Helpers.buildConfigDict(response);
114
+ }
115
+ else {
116
+ console.debug(`Unable to get ${this.deviceName} config info`);
117
+ }
118
+ }
119
+ /**
120
+ * Turn off wall switch
121
+ */
122
+ async turnOff() {
123
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
124
+ body.status = 'off';
125
+ body.uuid = this.uuid;
126
+ const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
127
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
128
+ this.deviceStatus = 'off';
129
+ return true;
130
+ }
131
+ console.debug(`Error turning ${this.deviceName} off`);
132
+ return false;
133
+ }
134
+ /**
135
+ * Turn on wall switch
136
+ */
137
+ async turnOn() {
138
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
139
+ body.status = 'on';
140
+ body.uuid = this.uuid;
141
+ const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
142
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
143
+ this.deviceStatus = 'on';
144
+ return true;
145
+ }
146
+ console.debug(`Error turning ${this.deviceName} on`);
147
+ return false;
148
+ }
149
+ }
150
+ exports.VeSyncWallSwitch = VeSyncWallSwitch;
151
+ /**
152
+ * VeSync Dimmer Switch
153
+ */
154
+ class VeSyncDimmerSwitch extends VeSyncSwitch {
155
+ constructor(details, manager) {
156
+ super(details, manager);
157
+ this._brightness = 0;
158
+ this._rgbValue = { red: 0, blue: 0, green: 0 };
159
+ this._rgbStatus = 'unknown';
160
+ this._indicatorLight = 'unknown';
161
+ }
162
+ /**
163
+ * Get dimmer switch details
164
+ */
165
+ async getDetails() {
166
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
167
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
168
+ body.uuid = this.uuid;
169
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
170
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
171
+ const result = response.result;
172
+ this.deviceStatus = (_a = result.deviceStatus) !== null && _a !== void 0 ? _a : this.deviceStatus;
173
+ this.details.active_time = (_b = result.activeTime) !== null && _b !== void 0 ? _b : 0;
174
+ this.connectionStatus = (_c = result.connectionStatus) !== null && _c !== void 0 ? _c : this.connectionStatus;
175
+ this._brightness = (_d = result.brightness) !== null && _d !== void 0 ? _d : this._brightness;
176
+ this._rgbStatus = (_e = result.rgbStatus) !== null && _e !== void 0 ? _e : this._rgbStatus;
177
+ this._indicatorLight = (_f = result.indicatorlightStatus) !== null && _f !== void 0 ? _f : this._indicatorLight;
178
+ if (result.rgbValue) {
179
+ this._rgbValue = {
180
+ red: (_g = result.rgbValue.red) !== null && _g !== void 0 ? _g : 0,
181
+ green: (_h = result.rgbValue.green) !== null && _h !== void 0 ? _h : 0,
182
+ blue: (_j = result.rgbValue.blue) !== null && _j !== void 0 ? _j : 0
183
+ };
184
+ }
185
+ }
186
+ else {
187
+ console.debug(`Error getting ${this.deviceName} details`);
188
+ }
189
+ }
190
+ /**
191
+ * Get dimmer switch configuration info
192
+ */
193
+ async getConfig() {
194
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
195
+ body.method = 'configurations';
196
+ body.uuid = this.uuid;
197
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
198
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
199
+ this.config = helpers_1.Helpers.buildConfigDict(response);
200
+ }
201
+ else {
202
+ console.debug(`Unable to get ${this.deviceName} config info`);
203
+ }
204
+ }
205
+ /**
206
+ * Turn off dimmer switch
207
+ */
208
+ async turnOff() {
209
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
210
+ body.status = 'off';
211
+ body.uuid = this.uuid;
212
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
213
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
214
+ this.deviceStatus = 'off';
215
+ return true;
216
+ }
217
+ console.debug(`Error turning ${this.deviceName} off`);
218
+ return false;
219
+ }
220
+ /**
221
+ * Turn on dimmer switch
222
+ */
223
+ async turnOn() {
224
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
225
+ body.status = 'on';
226
+ body.uuid = this.uuid;
227
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
228
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
229
+ this.deviceStatus = 'on';
230
+ return true;
231
+ }
232
+ console.debug(`Error turning ${this.deviceName} on`);
233
+ return false;
234
+ }
235
+ /**
236
+ * Return brightness in percent
237
+ */
238
+ get brightness() {
239
+ return this._brightness;
240
+ }
241
+ /**
242
+ * Return faceplate brightness light status
243
+ */
244
+ get indicatorLightStatus() {
245
+ return this._indicatorLight;
246
+ }
247
+ /**
248
+ * Return RGB faceplate light status
249
+ */
250
+ get rgbLightStatus() {
251
+ return this._rgbStatus;
252
+ }
253
+ /**
254
+ * Return RGB light values
255
+ */
256
+ get rgbLightValue() {
257
+ return this._rgbValue;
258
+ }
259
+ /**
260
+ * Update device details
261
+ */
262
+ async update() {
263
+ await this.getDetails();
264
+ }
265
+ /**
266
+ * Display device info
267
+ */
268
+ display() {
269
+ super.display();
270
+ const info = [
271
+ ['Brightness:', this.brightness, '%'],
272
+ ['RGB Status:', this.rgbLightStatus],
273
+ ['RGB Values:', JSON.stringify(this.rgbLightValue)],
274
+ ['Indicator Light:', this.indicatorLightStatus]
275
+ ];
276
+ for (const [key, value, unit = ''] of info) {
277
+ console.log(`${key.toString().padEnd(30, '.')} ${value}${unit}`);
278
+ }
279
+ }
280
+ /**
281
+ * Return JSON details for dimmer switch
282
+ */
283
+ displayJSON() {
284
+ const baseInfo = JSON.parse(super.displayJSON());
285
+ return JSON.stringify({
286
+ ...baseInfo,
287
+ 'Brightness': this.brightness,
288
+ 'RGB Status': this.rgbLightStatus,
289
+ 'RGB Values': this.rgbLightValue,
290
+ 'Indicator Light': this.indicatorLightStatus
291
+ }, null, 4);
292
+ }
293
+ /**
294
+ * Set brightness level
295
+ * @param brightness - Brightness level (1-100)
296
+ */
297
+ async setBrightness(brightness) {
298
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
299
+ body.uuid = this.uuid;
300
+ body.brightness = brightness;
301
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
302
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
303
+ this._brightness = brightness;
304
+ return true;
305
+ }
306
+ console.debug(`Error setting ${this.deviceName} brightness`);
307
+ return false;
308
+ }
309
+ /**
310
+ * Toggle indicator light status
311
+ * @param status - Light status ('on' or 'off')
312
+ */
313
+ async indicatorLightToggle(status) {
314
+ if (status !== 'on' && status !== 'off') {
315
+ console.debug('Invalid status passed to indicator light toggle');
316
+ return false;
317
+ }
318
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
319
+ body.uuid = this.uuid;
320
+ body.status = status;
321
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
322
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
323
+ this._indicatorLight = status;
324
+ return true;
325
+ }
326
+ console.debug(`Error toggling ${this.deviceName} indicator light`);
327
+ return false;
328
+ }
329
+ /**
330
+ * Set RGB color values
331
+ * @param red - Red value (0-255)
332
+ * @param green - Green value (0-255)
333
+ * @param blue - Blue value (0-255)
334
+ */
335
+ async rgbColorSet(red, green, blue) {
336
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
337
+ body.uuid = this.uuid;
338
+ body.rgbValue = { red, green, blue };
339
+ body.status = 'on';
340
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
341
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
342
+ this._rgbValue = { red, green, blue };
343
+ this._rgbStatus = 'on';
344
+ return true;
345
+ }
346
+ console.debug(`Error setting ${this.deviceName} RGB color`);
347
+ return false;
348
+ }
349
+ /**
350
+ * Toggle switch status
351
+ * @param status - Switch status ('on' or 'off')
352
+ */
353
+ async switchToggle(status) {
354
+ if (status !== 'on' && status !== 'off') {
355
+ console.debug('Invalid status passed to switch toggle');
356
+ return false;
357
+ }
358
+ return status === 'on' ? this.turnOn() : this.turnOff();
359
+ }
360
+ /**
361
+ * Set faceplate RGB color status and optionally set RGB values
362
+ * @param status - RGB status ('on' or 'off')
363
+ * @param red - Optional red value (0-255)
364
+ * @param green - Optional green value (0-255)
365
+ * @param blue - Optional blue value (0-255)
366
+ */
367
+ async rgbColorStatus(status, red, green, blue) {
368
+ if (status !== 'on' && status !== 'off') {
369
+ console.debug('Invalid status passed to RGB color status');
370
+ return false;
371
+ }
372
+ const body = helpers_1.Helpers.reqBody(this.manager, 'devicestatus');
373
+ body.uuid = this.uuid;
374
+ body.status = status;
375
+ if (red !== undefined && green !== undefined && blue !== undefined) {
376
+ body.rgbValue = { red, green, blue };
377
+ this._rgbValue = { red, green, blue };
378
+ }
379
+ const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
380
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
381
+ this._rgbStatus = status;
382
+ return true;
383
+ }
384
+ console.debug(`Error setting ${this.deviceName} RGB status`);
385
+ return false;
386
+ }
387
+ /**
388
+ * Turn RGB Color Off
389
+ */
390
+ async rgbColorOff() {
391
+ return this.rgbColorStatus('off');
392
+ }
393
+ /**
394
+ * Turn RGB Color On
395
+ */
396
+ async rgbColorOn() {
397
+ return this.rgbColorStatus('on');
398
+ }
399
+ /**
400
+ * Turn indicator light on
401
+ */
402
+ async indicatorLightOn() {
403
+ return this.indicatorLightToggle('on');
404
+ }
405
+ /**
406
+ * Turn indicator light off
407
+ */
408
+ async indicatorLightOff() {
409
+ return this.indicatorLightToggle('off');
410
+ }
411
+ }
412
+ exports.VeSyncDimmerSwitch = VeSyncDimmerSwitch;
413
+ // Export switch modules for device factory
414
+ exports.switchModules = {
415
+ 'ESWL01': VeSyncWallSwitch,
416
+ 'ESWL03': VeSyncWallSwitch,
417
+ 'ESWD16': VeSyncDimmerSwitch
418
+ };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * VeSync Switch Implementations
3
+ */
4
+ import { VeSyncSwitch } from './vesyncSwitch';
5
+ import { VeSync } from './vesync';
6
+ /**
7
+ * Basic Wall Switch Implementation (ESWL01, ESWL03)
8
+ */
9
+ export declare class VeSyncWallSwitch extends VeSyncSwitch {
10
+ constructor(details: Record<string, any>, manager: VeSync);
11
+ /**
12
+ * Get wall switch details
13
+ */
14
+ getDetails(): Promise<void>;
15
+ /**
16
+ * Get switch device configuration info
17
+ */
18
+ getConfig(): Promise<void>;
19
+ /**
20
+ * Turn off wall switch
21
+ */
22
+ turnOff(): Promise<boolean>;
23
+ /**
24
+ * Turn on wall switch
25
+ */
26
+ turnOn(): Promise<boolean>;
27
+ }
28
+ /**
29
+ * Dimmer Switch Implementation (ESWD16)
30
+ */
31
+ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
32
+ private _brightness;
33
+ private _rgbValue;
34
+ private _rgbStatus;
35
+ private _indicatorLight;
36
+ constructor(details: Record<string, any>, manager: VeSync);
37
+ /**
38
+ * Get dimmer switch details
39
+ */
40
+ getDetails(): Promise<void>;
41
+ /**
42
+ * Get dimmer switch configuration info
43
+ */
44
+ getConfig(): Promise<void>;
45
+ /**
46
+ * Turn off dimmer switch
47
+ */
48
+ turnOff(): Promise<boolean>;
49
+ /**
50
+ * Turn on dimmer switch
51
+ */
52
+ turnOn(): Promise<boolean>;
53
+ /**
54
+ * Set brightness level
55
+ */
56
+ setBrightness(brightness: number): Promise<boolean>;
57
+ /**
58
+ * Set RGB indicator color
59
+ */
60
+ rgbColorSet(red: number, green: number, blue: number): Promise<boolean>;
61
+ /**
62
+ * Turn on RGB indicator
63
+ */
64
+ rgbColorOn(): Promise<boolean>;
65
+ /**
66
+ * Turn off RGB indicator
67
+ */
68
+ rgbColorOff(): Promise<boolean>;
69
+ /**
70
+ * Turn on indicator light
71
+ */
72
+ indicatorLightOn(): Promise<boolean>;
73
+ /**
74
+ * Turn off indicator light
75
+ */
76
+ indicatorLightOff(): Promise<boolean>;
77
+ get brightness(): number;
78
+ get indicatorLightStatus(): string;
79
+ get rgbLightStatus(): string;
80
+ get rgbLightValue(): Record<string, number>;
81
+ }
82
+ export declare const switchModules: Record<string, any>;