tsvesync 1.0.12 → 1.0.14

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.
Files changed (70) hide show
  1. package/dist/lib/helpers.js +3 -2
  2. package/dist/lib/logger.d.ts +23 -0
  3. package/dist/lib/logger.js +54 -0
  4. package/dist/lib/vesync.js +42 -41
  5. package/dist/lib/vesyncBaseDevice.js +8 -7
  6. package/dist/lib/vesyncBulb.d.ts +9 -0
  7. package/dist/lib/vesyncBulb.js +125 -28
  8. package/dist/lib/vesyncBulbImpl.d.ts +1 -1
  9. package/dist/lib/vesyncBulbImpl.js +105 -36
  10. package/dist/lib/vesyncFan.js +2 -1
  11. package/dist/lib/vesyncFanImpl.d.ts +36 -0
  12. package/dist/lib/vesyncFanImpl.js +307 -42
  13. package/dist/lib/vesyncOutlet.d.ts +17 -0
  14. package/dist/lib/vesyncOutlet.js +124 -8
  15. package/dist/lib/vesyncOutletImpl.js +39 -0
  16. package/dist/lib/vesyncSwitch.d.ts +0 -124
  17. package/dist/lib/vesyncSwitch.js +3 -343
  18. package/dist/lib/vesyncSwitchImpl.d.ts +6 -6
  19. package/dist/lib/vesyncSwitchImpl.js +69 -15
  20. package/package.json +1 -1
  21. package/src/lib/helpers.ts +3 -2
  22. package/src/lib/logger.ts +60 -0
  23. package/src/lib/vesync.ts +42 -43
  24. package/src/lib/vesyncBaseDevice.ts +8 -7
  25. package/src/lib/vesyncBulb.ts +138 -30
  26. package/src/lib/vesyncBulbImpl.ts +113 -44
  27. package/src/lib/vesyncFan.ts +2 -4
  28. package/src/lib/vesyncFanImpl.ts +314 -42
  29. package/src/lib/vesyncOutlet.ts +140 -13
  30. package/src/lib/vesyncOutletImpl.ts +41 -0
  31. package/src/lib/vesyncSwitch.ts +3 -454
  32. package/src/lib/vesyncSwitchImpl.ts +66 -16
  33. package/dist/lib/helpers.js.map +0 -1
  34. package/dist/lib/vesync.js.map +0 -1
  35. package/dist/lib/vesyncBaseDevice.js.map +0 -1
  36. package/dist/lib/vesyncBulb.js.map +0 -1
  37. package/dist/lib/vesyncFan.js.map +0 -1
  38. package/dist/lib/vesyncKitchen.d.ts +0 -0
  39. package/dist/lib/vesyncKitchen.js +0 -2
  40. package/dist/lib/vesyncKitchen.js.map +0 -1
  41. package/dist/lib/vesyncOutlet.js.map +0 -1
  42. package/dist/lib/vesyncSwitch.js.map +0 -1
  43. package/dist/src/lib/helpers.d.ts +0 -88
  44. package/dist/src/lib/helpers.js +0 -244
  45. package/dist/src/lib/vesync.d.ts +0 -89
  46. package/dist/src/lib/vesync.js +0 -430
  47. package/dist/src/lib/vesyncBaseDevice.d.ts +0 -43
  48. package/dist/src/lib/vesyncBaseDevice.js +0 -87
  49. package/dist/src/lib/vesyncBulb.d.ts +0 -79
  50. package/dist/src/lib/vesyncBulb.js +0 -198
  51. package/dist/src/lib/vesyncBulbImpl.d.ts +0 -38
  52. package/dist/src/lib/vesyncBulbImpl.js +0 -161
  53. package/dist/src/lib/vesyncFan.d.ts +0 -80
  54. package/dist/src/lib/vesyncFan.js +0 -406
  55. package/dist/src/lib/vesyncFanImpl.d.ts +0 -137
  56. package/dist/src/lib/vesyncFanImpl.js +0 -643
  57. package/dist/src/lib/vesyncOutlet.d.ts +0 -53
  58. package/dist/src/lib/vesyncOutlet.js +0 -98
  59. package/dist/src/lib/vesyncOutletImpl.d.ts +0 -70
  60. package/dist/src/lib/vesyncOutletImpl.js +0 -206
  61. package/dist/src/lib/vesyncSwitch.d.ts +0 -169
  62. package/dist/src/lib/vesyncSwitch.js +0 -414
  63. package/dist/src/lib/vesyncSwitchImpl.d.ts +0 -82
  64. package/dist/src/lib/vesyncSwitchImpl.js +0 -290
  65. package/dist/test/testFeatures.d.ts +0 -4
  66. package/dist/test/testFeatures.js +0 -394
  67. package/dist/test/testService.d.ts +0 -62
  68. package/dist/test/testService.js +0 -540
  69. package/dist/test/testSpecial.d.ts +0 -5
  70. package/dist/test/testSpecial.js +0 -227
@@ -3,9 +3,9 @@
3
3
  * VeSync Switch Classes
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.switchModules = exports.VeSyncDimmerSwitch = exports.VeSyncWallSwitch = exports.VeSyncSwitch = exports.switchConfig = void 0;
6
+ exports.VeSyncSwitch = exports.switchConfig = void 0;
7
7
  const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
8
- const helpers_1 = require("./helpers");
8
+ const logger_1 = require("./logger");
9
9
  // Switch configuration
10
10
  exports.switchConfig = {
11
11
  'ESWL01': {
@@ -55,7 +55,7 @@ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
55
55
  ['Active Time:', this.activeTime]
56
56
  ];
57
57
  for (const [key, value] of info) {
58
- console.log(`${key.toString().padEnd(30, '.')} ${value}`);
58
+ logger_1.logger.info(`${key.toString().padEnd(30, '.')} ${value}`);
59
59
  }
60
60
  }
61
61
  /**
@@ -76,343 +76,3 @@ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
76
76
  }
77
77
  }
78
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
- };
@@ -61,17 +61,17 @@ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
61
61
  /**
62
62
  * Turn on RGB indicator
63
63
  */
64
- rgbColorOn(): Promise<boolean>;
64
+ rgbColorOff(): Promise<boolean>;
65
65
  /**
66
- * Turn off RGB indicator
66
+ * Turn RGB Color On
67
67
  */
68
- rgbColorOff(): Promise<boolean>;
68
+ rgbColorOn(): Promise<boolean>;
69
69
  /**
70
- * Turn on indicator light
70
+ * Turn indicator light on
71
71
  */
72
72
  indicatorLightOn(): Promise<boolean>;
73
73
  /**
74
- * Turn off indicator light
74
+ * Turn indicator light off
75
75
  */
76
76
  indicatorLightOff(): Promise<boolean>;
77
77
  get brightness(): number;
@@ -79,4 +79,4 @@ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
79
79
  get rgbLightStatus(): string;
80
80
  get rgbLightValue(): Record<string, number>;
81
81
  }
82
- export declare const switchModules: Record<string, any>;
82
+ export declare const switchModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncSwitch>;