tsvesync 1.0.11 → 1.0.13
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/index.d.ts +7 -0
- package/dist/index.js +25 -0
- package/dist/lib/helpers.d.ts +52 -51
- package/dist/lib/helpers.js +135 -112
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.js +54 -0
- package/dist/lib/vesync.d.ts +57 -15
- package/dist/lib/vesync.js +341 -217
- package/dist/lib/vesyncBaseDevice.d.ts +25 -50
- package/dist/lib/vesyncBaseDevice.js +63 -90
- package/dist/lib/vesyncBulb.d.ts +88 -0
- package/dist/lib/vesyncBulb.js +295 -1
- package/dist/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/lib/vesyncBulbImpl.js +230 -0
- package/dist/lib/vesyncFan.d.ts +55 -67
- package/dist/lib/vesyncFan.js +366 -213
- package/dist/lib/vesyncFanImpl.d.ts +173 -0
- package/dist/lib/vesyncFanImpl.js +909 -0
- package/dist/lib/vesyncOutlet.d.ts +70 -0
- package/dist/lib/vesyncOutlet.js +213 -1
- package/dist/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/lib/vesyncOutletImpl.js +245 -0
- package/dist/lib/vesyncSwitch.d.ts +45 -0
- package/dist/lib/vesyncSwitch.js +77 -1
- package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/lib/vesyncSwitchImpl.js +344 -0
- package/package.json +1 -1
- package/src/index.ts +14 -0
- package/src/lib/helpers.ts +3 -2
- package/src/lib/logger.ts +60 -0
- package/src/lib/vesync.ts +42 -43
- package/src/lib/vesyncBaseDevice.ts +8 -7
- package/src/lib/vesyncBulb.ts +138 -30
- package/src/lib/vesyncBulbImpl.ts +113 -44
- package/src/lib/vesyncFan.ts +2 -4
- package/src/lib/vesyncFanImpl.ts +314 -42
- package/src/lib/vesyncOutlet.ts +140 -13
- package/src/lib/vesyncOutletImpl.ts +41 -0
- package/src/lib/vesyncSwitch.ts +3 -454
- package/src/lib/vesyncSwitchImpl.ts +66 -16
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { VeSyncSwitch } from './vesyncSwitch';
|
|
6
6
|
import { VeSync } from './vesync';
|
|
7
7
|
import { Helpers } from './helpers';
|
|
8
|
+
import { logger } from './logger';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Basic Wall Switch Implementation (ESWL01, ESWL03)
|
|
@@ -12,12 +13,14 @@ import { Helpers } from './helpers';
|
|
|
12
13
|
export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
13
14
|
constructor(details: Record<string, any>, manager: VeSync) {
|
|
14
15
|
super(details, manager);
|
|
16
|
+
logger.debug(`Initialized VeSyncWallSwitch device: ${this.deviceName}`);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Get wall switch details
|
|
19
21
|
*/
|
|
20
22
|
async getDetails(): Promise<void> {
|
|
23
|
+
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
21
24
|
const body = {
|
|
22
25
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
23
26
|
uuid: this.cid,
|
|
@@ -36,6 +39,9 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
36
39
|
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
37
40
|
this.details.active_time = result.activeTime || 0;
|
|
38
41
|
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
42
|
+
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
43
|
+
} else {
|
|
44
|
+
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -43,6 +49,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
43
49
|
* Get switch device configuration info
|
|
44
50
|
*/
|
|
45
51
|
async getConfig(): Promise<void> {
|
|
52
|
+
logger.debug(`Getting configuration for device: ${this.deviceName}`);
|
|
46
53
|
const body = {
|
|
47
54
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
48
55
|
method: 'configurations',
|
|
@@ -58,6 +65,9 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
58
65
|
|
|
59
66
|
if (response?.code === 0) {
|
|
60
67
|
this.config = Helpers.buildConfigDict(response);
|
|
68
|
+
logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
|
|
69
|
+
} else {
|
|
70
|
+
logger.error(`Failed to get configuration for device: ${this.deviceName}`);
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
|
|
@@ -65,6 +75,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
65
75
|
* Turn off wall switch
|
|
66
76
|
*/
|
|
67
77
|
async turnOff(): Promise<boolean> {
|
|
78
|
+
logger.debug(`Turning off device: ${this.deviceName}`);
|
|
68
79
|
const body = {
|
|
69
80
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
70
81
|
status: 'off',
|
|
@@ -80,8 +91,10 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
80
91
|
|
|
81
92
|
if (response?.code === 0) {
|
|
82
93
|
this.deviceStatus = 'off';
|
|
94
|
+
logger.debug(`Successfully turned off device: ${this.deviceName}`);
|
|
83
95
|
return true;
|
|
84
96
|
}
|
|
97
|
+
logger.error(`Failed to turn off device: ${this.deviceName}`);
|
|
85
98
|
return false;
|
|
86
99
|
}
|
|
87
100
|
|
|
@@ -89,6 +102,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
89
102
|
* Turn on wall switch
|
|
90
103
|
*/
|
|
91
104
|
async turnOn(): Promise<boolean> {
|
|
105
|
+
logger.debug(`Turning on device: ${this.deviceName}`);
|
|
92
106
|
const body = {
|
|
93
107
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
94
108
|
status: 'on',
|
|
@@ -104,8 +118,10 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
104
118
|
|
|
105
119
|
if (response?.code === 0) {
|
|
106
120
|
this.deviceStatus = 'on';
|
|
121
|
+
logger.debug(`Successfully turned on device: ${this.deviceName}`);
|
|
107
122
|
return true;
|
|
108
123
|
}
|
|
124
|
+
logger.error(`Failed to turn on device: ${this.deviceName}`);
|
|
109
125
|
return false;
|
|
110
126
|
}
|
|
111
127
|
}
|
|
@@ -121,12 +137,14 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
121
137
|
|
|
122
138
|
constructor(details: Record<string, any>, manager: VeSync) {
|
|
123
139
|
super(details, manager);
|
|
140
|
+
logger.debug(`Initialized VeSyncDimmerSwitch device: ${this.deviceName}`);
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
/**
|
|
127
144
|
* Get dimmer switch details
|
|
128
145
|
*/
|
|
129
146
|
async getDetails(): Promise<void> {
|
|
147
|
+
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
130
148
|
const body = {
|
|
131
149
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
132
150
|
uuid: this.cid,
|
|
@@ -155,6 +173,9 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
155
173
|
blue: result.rgbValue.blue || 0
|
|
156
174
|
};
|
|
157
175
|
}
|
|
176
|
+
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
177
|
+
} else {
|
|
178
|
+
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
158
179
|
}
|
|
159
180
|
}
|
|
160
181
|
|
|
@@ -162,6 +183,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
162
183
|
* Get dimmer switch configuration info
|
|
163
184
|
*/
|
|
164
185
|
async getConfig(): Promise<void> {
|
|
186
|
+
logger.debug(`Getting configuration for device: ${this.deviceName}`);
|
|
165
187
|
const body = {
|
|
166
188
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
167
189
|
method: 'configurations',
|
|
@@ -177,6 +199,9 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
177
199
|
|
|
178
200
|
if (response?.code === 0) {
|
|
179
201
|
this.config = Helpers.buildConfigDict(response);
|
|
202
|
+
logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
|
|
203
|
+
} else {
|
|
204
|
+
logger.error(`Failed to get configuration for device: ${this.deviceName}`);
|
|
180
205
|
}
|
|
181
206
|
}
|
|
182
207
|
|
|
@@ -184,6 +209,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
184
209
|
* Turn off dimmer switch
|
|
185
210
|
*/
|
|
186
211
|
async turnOff(): Promise<boolean> {
|
|
212
|
+
logger.debug(`Turning off device: ${this.deviceName}`);
|
|
187
213
|
const body = {
|
|
188
214
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
189
215
|
status: 'off',
|
|
@@ -199,8 +225,10 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
199
225
|
|
|
200
226
|
if (response?.code === 0) {
|
|
201
227
|
this.deviceStatus = 'off';
|
|
228
|
+
logger.debug(`Successfully turned off device: ${this.deviceName}`);
|
|
202
229
|
return true;
|
|
203
230
|
}
|
|
231
|
+
logger.error(`Failed to turn off device: ${this.deviceName}`);
|
|
204
232
|
return false;
|
|
205
233
|
}
|
|
206
234
|
|
|
@@ -208,6 +236,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
208
236
|
* Turn on dimmer switch
|
|
209
237
|
*/
|
|
210
238
|
async turnOn(): Promise<boolean> {
|
|
239
|
+
logger.debug(`Turning on device: ${this.deviceName}`);
|
|
211
240
|
const body = {
|
|
212
241
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
213
242
|
status: 'on',
|
|
@@ -223,8 +252,10 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
223
252
|
|
|
224
253
|
if (response?.code === 0) {
|
|
225
254
|
this.deviceStatus = 'on';
|
|
255
|
+
logger.debug(`Successfully turned on device: ${this.deviceName}`);
|
|
226
256
|
return true;
|
|
227
257
|
}
|
|
258
|
+
logger.error(`Failed to turn on device: ${this.deviceName}`);
|
|
228
259
|
return false;
|
|
229
260
|
}
|
|
230
261
|
|
|
@@ -233,9 +264,11 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
233
264
|
*/
|
|
234
265
|
async setBrightness(brightness: number): Promise<boolean> {
|
|
235
266
|
if (!this.isDimmable()) {
|
|
267
|
+
logger.error(`Device ${this.deviceName} does not support dimming`);
|
|
236
268
|
return false;
|
|
237
269
|
}
|
|
238
270
|
|
|
271
|
+
logger.debug(`Setting brightness to ${brightness} for device: ${this.deviceName}`);
|
|
239
272
|
const body = {
|
|
240
273
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
241
274
|
brightness: brightness.toString(),
|
|
@@ -251,8 +284,10 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
251
284
|
|
|
252
285
|
if (response?.code === 0) {
|
|
253
286
|
this._brightness = brightness;
|
|
287
|
+
logger.debug(`Successfully set brightness to ${brightness} for device: ${this.deviceName}`);
|
|
254
288
|
return true;
|
|
255
289
|
}
|
|
290
|
+
logger.error(`Failed to set brightness to ${brightness} for device: ${this.deviceName}`);
|
|
256
291
|
return false;
|
|
257
292
|
}
|
|
258
293
|
|
|
@@ -260,6 +295,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
260
295
|
* Set RGB indicator color
|
|
261
296
|
*/
|
|
262
297
|
async rgbColorSet(red: number, green: number, blue: number): Promise<boolean> {
|
|
298
|
+
logger.debug(`Setting RGB color to (${red}, ${green}, ${blue}) for device: ${this.deviceName}`);
|
|
263
299
|
const body = {
|
|
264
300
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
265
301
|
rgbValue: {
|
|
@@ -281,18 +317,21 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
281
317
|
if (response?.code === 0) {
|
|
282
318
|
this._rgbValue = { red, green, blue };
|
|
283
319
|
this._rgbStatus = 'on';
|
|
320
|
+
logger.debug(`Successfully set RGB color for device: ${this.deviceName}`);
|
|
284
321
|
return true;
|
|
285
322
|
}
|
|
323
|
+
logger.error(`Failed to set RGB color for device: ${this.deviceName}`);
|
|
286
324
|
return false;
|
|
287
325
|
}
|
|
288
326
|
|
|
289
327
|
/**
|
|
290
328
|
* Turn on RGB indicator
|
|
291
329
|
*/
|
|
292
|
-
async
|
|
330
|
+
async rgbColorOff(): Promise<boolean> {
|
|
331
|
+
logger.debug(`Turning off RGB color for device: ${this.deviceName}`);
|
|
293
332
|
const body = {
|
|
294
333
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
295
|
-
status: '
|
|
334
|
+
status: 'off',
|
|
296
335
|
uuid: this.cid
|
|
297
336
|
};
|
|
298
337
|
|
|
@@ -304,20 +343,23 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
304
343
|
);
|
|
305
344
|
|
|
306
345
|
if (response?.code === 0) {
|
|
307
|
-
this._rgbStatus = '
|
|
346
|
+
this._rgbStatus = 'off';
|
|
347
|
+
logger.debug(`Successfully turned off RGB color for device: ${this.deviceName}`);
|
|
308
348
|
return true;
|
|
309
349
|
}
|
|
350
|
+
logger.error(`Failed to turn off RGB color for device: ${this.deviceName}`);
|
|
310
351
|
return false;
|
|
311
352
|
}
|
|
312
353
|
|
|
313
354
|
/**
|
|
314
|
-
* Turn
|
|
355
|
+
* Turn RGB Color On
|
|
315
356
|
*/
|
|
316
|
-
async
|
|
357
|
+
async rgbColorOn(): Promise<boolean> {
|
|
358
|
+
logger.debug(`Turning on RGB color for device: ${this.deviceName}`);
|
|
317
359
|
const body = {
|
|
318
360
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
319
|
-
|
|
320
|
-
|
|
361
|
+
uuid: this.cid,
|
|
362
|
+
status: 'on'
|
|
321
363
|
};
|
|
322
364
|
|
|
323
365
|
const [response] = await Helpers.callApi(
|
|
@@ -328,20 +370,23 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
328
370
|
);
|
|
329
371
|
|
|
330
372
|
if (response?.code === 0) {
|
|
331
|
-
this._rgbStatus = '
|
|
373
|
+
this._rgbStatus = 'on';
|
|
374
|
+
logger.debug(`Successfully turned on RGB color for device: ${this.deviceName}`);
|
|
332
375
|
return true;
|
|
333
376
|
}
|
|
377
|
+
logger.error(`Failed to turn on RGB color for device: ${this.deviceName}`);
|
|
334
378
|
return false;
|
|
335
379
|
}
|
|
336
380
|
|
|
337
381
|
/**
|
|
338
|
-
* Turn
|
|
382
|
+
* Turn indicator light on
|
|
339
383
|
*/
|
|
340
384
|
async indicatorLightOn(): Promise<boolean> {
|
|
385
|
+
logger.debug(`Turning on indicator light for device: ${this.deviceName}`);
|
|
341
386
|
const body = {
|
|
342
387
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
343
|
-
|
|
344
|
-
|
|
388
|
+
uuid: this.cid,
|
|
389
|
+
status: 'on'
|
|
345
390
|
};
|
|
346
391
|
|
|
347
392
|
const [response] = await Helpers.callApi(
|
|
@@ -353,19 +398,22 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
353
398
|
|
|
354
399
|
if (response?.code === 0) {
|
|
355
400
|
this._indicatorLight = 'on';
|
|
401
|
+
logger.debug(`Successfully turned on indicator light for device: ${this.deviceName}`);
|
|
356
402
|
return true;
|
|
357
403
|
}
|
|
404
|
+
logger.error(`Failed to turn on indicator light for device: ${this.deviceName}`);
|
|
358
405
|
return false;
|
|
359
406
|
}
|
|
360
407
|
|
|
361
408
|
/**
|
|
362
|
-
* Turn
|
|
409
|
+
* Turn indicator light off
|
|
363
410
|
*/
|
|
364
411
|
async indicatorLightOff(): Promise<boolean> {
|
|
412
|
+
logger.debug(`Turning off indicator light for device: ${this.deviceName}`);
|
|
365
413
|
const body = {
|
|
366
414
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
367
|
-
|
|
368
|
-
|
|
415
|
+
uuid: this.cid,
|
|
416
|
+
status: 'off'
|
|
369
417
|
};
|
|
370
418
|
|
|
371
419
|
const [response] = await Helpers.callApi(
|
|
@@ -377,8 +425,10 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
377
425
|
|
|
378
426
|
if (response?.code === 0) {
|
|
379
427
|
this._indicatorLight = 'off';
|
|
428
|
+
logger.debug(`Successfully turned off indicator light for device: ${this.deviceName}`);
|
|
380
429
|
return true;
|
|
381
430
|
}
|
|
431
|
+
logger.error(`Failed to turn off indicator light for device: ${this.deviceName}`);
|
|
382
432
|
return false;
|
|
383
433
|
}
|
|
384
434
|
|
|
@@ -400,8 +450,8 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
400
450
|
}
|
|
401
451
|
}
|
|
402
452
|
|
|
403
|
-
// Export
|
|
404
|
-
export const switchModules: Record<string, any> = {
|
|
453
|
+
// Export switch modules dictionary
|
|
454
|
+
export const switchModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncSwitch> = {
|
|
405
455
|
'ESWL01': VeSyncWallSwitch,
|
|
406
456
|
'ESWL03': VeSyncWallSwitch,
|
|
407
457
|
'ESWD16': VeSyncDimmerSwitch
|