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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -0
  3. package/api/vesync/VeSync.yaml +33 -0
  4. package/api/vesyncbulb/ESL100.yaml +74 -0
  5. package/api/vesyncbulb/ESL100CW.yaml +123 -0
  6. package/api/vesyncbulb/ESL100MC.yaml +169 -0
  7. package/api/vesyncbulb/XYD0001.yaml +193 -0
  8. package/api/vesyncfan/Classic200S.yaml +280 -0
  9. package/api/vesyncfan/Classic300S.yaml +278 -0
  10. package/api/vesyncfan/Core200S.yaml +256 -0
  11. package/api/vesyncfan/Core300S.yaml +281 -0
  12. package/api/vesyncfan/Core400S.yaml +281 -0
  13. package/api/vesyncfan/Core600S.yaml +281 -0
  14. package/api/vesyncfan/Dual200S.yaml +278 -0
  15. package/api/vesyncfan/LAP-C201S-AUSR.yaml +256 -0
  16. package/api/vesyncfan/LAP-C202S-WUSR.yaml +256 -0
  17. package/api/vesyncfan/LAP-C301S-WAAA.yaml +281 -0
  18. package/api/vesyncfan/LAP-C301S-WJP.yaml +281 -0
  19. package/api/vesyncfan/LAP-C302S-WUSB.yaml +281 -0
  20. package/api/vesyncfan/LAP-C401S-WAAA.yaml +281 -0
  21. package/api/vesyncfan/LAP-C401S-WJP.yaml +281 -0
  22. package/api/vesyncfan/LAP-C401S-WUSR.yaml +281 -0
  23. package/api/vesyncfan/LAP-C601S-WEU.yaml +281 -0
  24. package/api/vesyncfan/LAP-C601S-WUS.yaml +281 -0
  25. package/api/vesyncfan/LAP-C601S-WUSR.yaml +281 -0
  26. package/api/vesyncfan/LAP-EL551S-AEUR.yaml +167 -0
  27. package/api/vesyncfan/LAP-EL551S-AUS.yaml +167 -0
  28. package/api/vesyncfan/LAP-EL551S-WEU.yaml +167 -0
  29. package/api/vesyncfan/LAP-EL551S-WUS.yaml +167 -0
  30. package/api/vesyncfan/LAP-V102S-AASR.yaml +167 -0
  31. package/api/vesyncfan/LAP-V102S-AUSR.yaml +167 -0
  32. package/api/vesyncfan/LAP-V102S-WEU.yaml +167 -0
  33. package/api/vesyncfan/LAP-V102S-WJP.yaml +167 -0
  34. package/api/vesyncfan/LAP-V102S-WUS.yaml +167 -0
  35. package/api/vesyncfan/LAP-V201-AUSR.yaml +167 -0
  36. package/api/vesyncfan/LAP-V201S-AASR.yaml +167 -0
  37. package/api/vesyncfan/LAP-V201S-AEUR.yaml +167 -0
  38. package/api/vesyncfan/LAP-V201S-AUSR.yaml +167 -0
  39. package/api/vesyncfan/LAP-V201S-WEU.yaml +167 -0
  40. package/api/vesyncfan/LAP-V201S-WJP.yaml +167 -0
  41. package/api/vesyncfan/LAP-V201S-WUS.yaml +167 -0
  42. package/api/vesyncfan/LEH-S601S-WUS.yaml +303 -0
  43. package/api/vesyncfan/LEH-S601S-WUSR.yaml +82 -0
  44. package/api/vesyncfan/LTF-F422S-KEU.yaml +165 -0
  45. package/api/vesyncfan/LTF-F422S-WUS.yaml +165 -0
  46. package/api/vesyncfan/LTF-F422S-WUSR.yaml +167 -0
  47. package/api/vesyncfan/LTF-F422_WJP.yaml +165 -0
  48. package/api/vesyncfan/LUH-A601S-AUSW.yaml +82 -0
  49. package/api/vesyncfan/LUH-A601S-WUSB.yaml +305 -0
  50. package/api/vesyncfan/LUH-A602S-WEU.yaml +305 -0
  51. package/api/vesyncfan/LUH-A602S-WEUR.yaml +305 -0
  52. package/api/vesyncfan/LUH-A602S-WJP.yaml +305 -0
  53. package/api/vesyncfan/LUH-A602S-WUS.yaml +305 -0
  54. package/api/vesyncfan/LUH-A602S-WUSC.yaml +305 -0
  55. package/api/vesyncfan/LUH-A602S-WUSR.yaml +305 -0
  56. package/api/vesyncfan/LUH-D301S-WEU.yaml +305 -0
  57. package/api/vesyncfan/LUH-D301S-WJP.yaml +305 -0
  58. package/api/vesyncfan/LUH-D301S-WUSR.yaml +305 -0
  59. package/api/vesyncfan/LUH-M101S-WUS.yaml +278 -0
  60. package/api/vesyncfan/LUH-O451S-WEU.yaml +278 -0
  61. package/api/vesyncfan/LUH-O451S-WUS.yaml +278 -0
  62. package/api/vesyncfan/LUH-O451S-WUSR.yaml +305 -0
  63. package/api/vesyncfan/LUH-O601S-KUS.yaml +305 -0
  64. package/api/vesyncfan/LUH-O601S-WUS.yaml +305 -0
  65. package/api/vesyncfan/LV-PUR131S.yaml +108 -0
  66. package/api/vesyncfan/LV-RH131S.yaml +108 -0
  67. package/api/vesyncoutlet/ESO15-TB.yaml +124 -0
  68. package/api/vesyncoutlet/ESW01-EU.yaml +122 -0
  69. package/api/vesyncoutlet/ESW03-USA.yaml +122 -0
  70. package/api/vesyncoutlet/ESW15-USA.yaml +156 -0
  71. package/api/vesyncoutlet/wifi-switch-1.3.yaml +60 -0
  72. package/api/vesyncswitch/ESWD16.yaml +128 -0
  73. package/api/vesyncswitch/ESWL01.yaml +56 -0
  74. package/api/vesyncswitch/ESWL03.yaml +56 -0
  75. package/dist/lib/helpers.d.ts +87 -0
  76. package/dist/lib/helpers.js +222 -0
  77. package/dist/lib/helpers.js.map +1 -0
  78. package/dist/lib/vesync.d.ts +47 -0
  79. package/dist/lib/vesync.js +309 -0
  80. package/dist/lib/vesync.js.map +1 -0
  81. package/dist/lib/vesyncBaseDevice.d.ts +68 -0
  82. package/dist/lib/vesyncBaseDevice.js +116 -0
  83. package/dist/lib/vesyncBaseDevice.js.map +1 -0
  84. package/dist/lib/vesyncBulb.d.ts +0 -0
  85. package/dist/lib/vesyncBulb.js +2 -0
  86. package/dist/lib/vesyncBulb.js.map +1 -0
  87. package/dist/lib/vesyncFan.d.ts +92 -0
  88. package/dist/lib/vesyncFan.js +265 -0
  89. package/dist/lib/vesyncFan.js.map +1 -0
  90. package/dist/lib/vesyncKitchen.d.ts +0 -0
  91. package/dist/lib/vesyncKitchen.js +2 -0
  92. package/dist/lib/vesyncKitchen.js.map +1 -0
  93. package/dist/lib/vesyncOutlet.d.ts +0 -0
  94. package/dist/lib/vesyncOutlet.js +2 -0
  95. package/dist/lib/vesyncOutlet.js.map +1 -0
  96. package/dist/lib/vesyncSwitch.d.ts +0 -0
  97. package/dist/lib/vesyncSwitch.js +2 -0
  98. package/dist/lib/vesyncSwitch.js.map +1 -0
  99. package/dist/src/lib/helpers.d.ts +88 -0
  100. package/dist/src/lib/helpers.js +244 -0
  101. package/dist/src/lib/vesync.d.ts +89 -0
  102. package/dist/src/lib/vesync.js +430 -0
  103. package/dist/src/lib/vesyncBaseDevice.d.ts +43 -0
  104. package/dist/src/lib/vesyncBaseDevice.js +87 -0
  105. package/dist/src/lib/vesyncBulb.d.ts +79 -0
  106. package/dist/src/lib/vesyncBulb.js +198 -0
  107. package/dist/src/lib/vesyncBulbImpl.d.ts +38 -0
  108. package/dist/src/lib/vesyncBulbImpl.js +161 -0
  109. package/dist/src/lib/vesyncFan.d.ts +80 -0
  110. package/dist/src/lib/vesyncFan.js +406 -0
  111. package/dist/src/lib/vesyncFanImpl.d.ts +137 -0
  112. package/dist/src/lib/vesyncFanImpl.js +643 -0
  113. package/dist/src/lib/vesyncOutlet.d.ts +53 -0
  114. package/dist/src/lib/vesyncOutlet.js +98 -0
  115. package/dist/src/lib/vesyncOutletImpl.d.ts +70 -0
  116. package/dist/src/lib/vesyncOutletImpl.js +206 -0
  117. package/dist/src/lib/vesyncSwitch.d.ts +169 -0
  118. package/dist/src/lib/vesyncSwitch.js +414 -0
  119. package/dist/src/lib/vesyncSwitchImpl.d.ts +82 -0
  120. package/dist/src/lib/vesyncSwitchImpl.js +290 -0
  121. package/dist/test/testFeatures.d.ts +4 -0
  122. package/dist/test/testFeatures.js +394 -0
  123. package/dist/test/testService.d.ts +62 -0
  124. package/dist/test/testService.js +540 -0
  125. package/dist/test/testSpecial.d.ts +5 -0
  126. package/dist/test/testSpecial.js +227 -0
  127. package/package.json +53 -0
  128. package/src/lib/helpers.ts +290 -0
  129. package/src/lib/vesync.ts +530 -0
  130. package/src/lib/vesyncBaseDevice.ts +114 -0
  131. package/src/lib/vesyncBulb.ts +252 -0
  132. package/src/lib/vesyncBulbImpl.ts +215 -0
  133. package/src/lib/vesyncFan.ts +447 -0
  134. package/src/lib/vesyncFanImpl.ts +848 -0
  135. package/src/lib/vesyncOutlet.ts +148 -0
  136. package/src/lib/vesyncOutletImpl.ts +284 -0
  137. package/src/lib/vesyncSwitch.ts +546 -0
  138. package/src/lib/vesyncSwitchImpl.ts +408 -0
@@ -0,0 +1,408 @@
1
+ /**
2
+ * VeSync Switch Implementations
3
+ */
4
+
5
+ import { VeSyncSwitch } from './vesyncSwitch';
6
+ import { VeSync } from './vesync';
7
+ import { Helpers } from './helpers';
8
+
9
+ /**
10
+ * Basic Wall Switch Implementation (ESWL01, ESWL03)
11
+ */
12
+ export class VeSyncWallSwitch extends VeSyncSwitch {
13
+ constructor(details: Record<string, any>, manager: VeSync) {
14
+ super(details, manager);
15
+ }
16
+
17
+ /**
18
+ * Get wall switch details
19
+ */
20
+ async getDetails(): Promise<void> {
21
+ const body = {
22
+ ...Helpers.reqBody(this.manager, 'devicedetail'),
23
+ uuid: this.cid,
24
+ method: 'devicedetail'
25
+ };
26
+
27
+ const [response] = await Helpers.callApi(
28
+ '/inwallswitch/v1/device/devicedetail',
29
+ 'post',
30
+ body,
31
+ Helpers.reqHeaders(this.manager)
32
+ );
33
+
34
+ if (response?.code === 0 && response?.result) {
35
+ const result = response.result;
36
+ this.deviceStatus = result.deviceStatus || this.deviceStatus;
37
+ this.details.active_time = result.activeTime || 0;
38
+ this.connectionStatus = result.connectionStatus || this.connectionStatus;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Get switch device configuration info
44
+ */
45
+ async getConfig(): Promise<void> {
46
+ const body = {
47
+ ...Helpers.reqBody(this.manager, 'devicedetail'),
48
+ method: 'configurations',
49
+ uuid: this.cid
50
+ };
51
+
52
+ const [response] = await Helpers.callApi(
53
+ '/inwallswitch/v1/device/configurations',
54
+ 'post',
55
+ body,
56
+ Helpers.reqHeaders(this.manager)
57
+ );
58
+
59
+ if (response?.code === 0) {
60
+ this.config = Helpers.buildConfigDict(response);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Turn off wall switch
66
+ */
67
+ async turnOff(): Promise<boolean> {
68
+ const body = {
69
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
70
+ status: 'off',
71
+ uuid: this.cid
72
+ };
73
+
74
+ const [response] = await Helpers.callApi(
75
+ '/inwallswitch/v1/device/devicestatus',
76
+ 'put',
77
+ body,
78
+ Helpers.reqHeaders(this.manager)
79
+ );
80
+
81
+ if (response?.code === 0) {
82
+ this.deviceStatus = 'off';
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+
88
+ /**
89
+ * Turn on wall switch
90
+ */
91
+ async turnOn(): Promise<boolean> {
92
+ const body = {
93
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
94
+ status: 'on',
95
+ uuid: this.cid
96
+ };
97
+
98
+ const [response] = await Helpers.callApi(
99
+ '/inwallswitch/v1/device/devicestatus',
100
+ 'put',
101
+ body,
102
+ Helpers.reqHeaders(this.manager)
103
+ );
104
+
105
+ if (response?.code === 0) {
106
+ this.deviceStatus = 'on';
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Dimmer Switch Implementation (ESWD16)
115
+ */
116
+ export class VeSyncDimmerSwitch extends VeSyncSwitch {
117
+ private _brightness: number = 0;
118
+ private _rgbValue: Record<string, number> = { red: 0, blue: 0, green: 0 };
119
+ private _rgbStatus: string = 'unknown';
120
+ private _indicatorLight: string = 'unknown';
121
+
122
+ constructor(details: Record<string, any>, manager: VeSync) {
123
+ super(details, manager);
124
+ }
125
+
126
+ /**
127
+ * Get dimmer switch details
128
+ */
129
+ async getDetails(): Promise<void> {
130
+ const body = {
131
+ ...Helpers.reqBody(this.manager, 'devicedetail'),
132
+ uuid: this.cid,
133
+ method: 'devicedetail'
134
+ };
135
+
136
+ const [response] = await Helpers.callApi(
137
+ '/dimmer/v1/device/devicedetail',
138
+ 'post',
139
+ body,
140
+ Helpers.reqHeaders(this.manager)
141
+ );
142
+
143
+ if (response?.code === 0 && response?.result) {
144
+ const result = response.result;
145
+ this.deviceStatus = result.deviceStatus || this.deviceStatus;
146
+ this.details.active_time = result.activeTime || 0;
147
+ this.connectionStatus = result.connectionStatus || this.connectionStatus;
148
+ this._brightness = result.brightness || this._brightness;
149
+ this._rgbStatus = result.rgbStatus || this._rgbStatus;
150
+ this._indicatorLight = result.indicatorlightStatus || this._indicatorLight;
151
+ if (result.rgbValue) {
152
+ this._rgbValue = {
153
+ red: result.rgbValue.red || 0,
154
+ green: result.rgbValue.green || 0,
155
+ blue: result.rgbValue.blue || 0
156
+ };
157
+ }
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Get dimmer switch configuration info
163
+ */
164
+ async getConfig(): Promise<void> {
165
+ const body = {
166
+ ...Helpers.reqBody(this.manager, 'devicedetail'),
167
+ method: 'configurations',
168
+ uuid: this.cid
169
+ };
170
+
171
+ const [response] = await Helpers.callApi(
172
+ '/dimmer/v1/device/configurations',
173
+ 'post',
174
+ body,
175
+ Helpers.reqHeaders(this.manager)
176
+ );
177
+
178
+ if (response?.code === 0) {
179
+ this.config = Helpers.buildConfigDict(response);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Turn off dimmer switch
185
+ */
186
+ async turnOff(): Promise<boolean> {
187
+ const body = {
188
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
189
+ status: 'off',
190
+ uuid: this.cid
191
+ };
192
+
193
+ const [response] = await Helpers.callApi(
194
+ '/dimmer/v1/device/devicestatus',
195
+ 'put',
196
+ body,
197
+ Helpers.reqHeaders(this.manager)
198
+ );
199
+
200
+ if (response?.code === 0) {
201
+ this.deviceStatus = 'off';
202
+ return true;
203
+ }
204
+ return false;
205
+ }
206
+
207
+ /**
208
+ * Turn on dimmer switch
209
+ */
210
+ async turnOn(): Promise<boolean> {
211
+ const body = {
212
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
213
+ status: 'on',
214
+ uuid: this.cid
215
+ };
216
+
217
+ const [response] = await Helpers.callApi(
218
+ '/dimmer/v1/device/devicestatus',
219
+ 'put',
220
+ body,
221
+ Helpers.reqHeaders(this.manager)
222
+ );
223
+
224
+ if (response?.code === 0) {
225
+ this.deviceStatus = 'on';
226
+ return true;
227
+ }
228
+ return false;
229
+ }
230
+
231
+ /**
232
+ * Set brightness level
233
+ */
234
+ async setBrightness(brightness: number): Promise<boolean> {
235
+ if (!this.isDimmable()) {
236
+ return false;
237
+ }
238
+
239
+ const body = {
240
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
241
+ brightness: brightness.toString(),
242
+ uuid: this.cid
243
+ };
244
+
245
+ const [response] = await Helpers.callApi(
246
+ '/dimmer/v1/device/updatebrightness',
247
+ 'put',
248
+ body,
249
+ Helpers.reqHeaders(this.manager)
250
+ );
251
+
252
+ if (response?.code === 0) {
253
+ this._brightness = brightness;
254
+ return true;
255
+ }
256
+ return false;
257
+ }
258
+
259
+ /**
260
+ * Set RGB indicator color
261
+ */
262
+ async rgbColorSet(red: number, green: number, blue: number): Promise<boolean> {
263
+ const body = {
264
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
265
+ rgbValue: {
266
+ red: Math.round(red),
267
+ green: Math.round(green),
268
+ blue: Math.round(blue)
269
+ },
270
+ status: 'on',
271
+ uuid: this.cid
272
+ };
273
+
274
+ const [response] = await Helpers.callApi(
275
+ '/dimmer/v1/device/devicergbstatus',
276
+ 'put',
277
+ body,
278
+ Helpers.reqHeaders(this.manager)
279
+ );
280
+
281
+ if (response?.code === 0) {
282
+ this._rgbValue = { red, green, blue };
283
+ this._rgbStatus = 'on';
284
+ return true;
285
+ }
286
+ return false;
287
+ }
288
+
289
+ /**
290
+ * Turn on RGB indicator
291
+ */
292
+ async rgbColorOn(): Promise<boolean> {
293
+ const body = {
294
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
295
+ status: 'on',
296
+ uuid: this.cid
297
+ };
298
+
299
+ const [response] = await Helpers.callApi(
300
+ '/dimmer/v1/device/devicergbstatus',
301
+ 'put',
302
+ body,
303
+ Helpers.reqHeaders(this.manager)
304
+ );
305
+
306
+ if (response?.code === 0) {
307
+ this._rgbStatus = 'on';
308
+ return true;
309
+ }
310
+ return false;
311
+ }
312
+
313
+ /**
314
+ * Turn off RGB indicator
315
+ */
316
+ async rgbColorOff(): Promise<boolean> {
317
+ const body = {
318
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
319
+ status: 'off',
320
+ uuid: this.cid
321
+ };
322
+
323
+ const [response] = await Helpers.callApi(
324
+ '/dimmer/v1/device/devicergbstatus',
325
+ 'put',
326
+ body,
327
+ Helpers.reqHeaders(this.manager)
328
+ );
329
+
330
+ if (response?.code === 0) {
331
+ this._rgbStatus = 'off';
332
+ return true;
333
+ }
334
+ return false;
335
+ }
336
+
337
+ /**
338
+ * Turn on indicator light
339
+ */
340
+ async indicatorLightOn(): Promise<boolean> {
341
+ const body = {
342
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
343
+ status: 'on',
344
+ uuid: this.cid
345
+ };
346
+
347
+ const [response] = await Helpers.callApi(
348
+ '/dimmer/v1/device/indicatorlightstatus',
349
+ 'put',
350
+ body,
351
+ Helpers.reqHeaders(this.manager)
352
+ );
353
+
354
+ if (response?.code === 0) {
355
+ this._indicatorLight = 'on';
356
+ return true;
357
+ }
358
+ return false;
359
+ }
360
+
361
+ /**
362
+ * Turn off indicator light
363
+ */
364
+ async indicatorLightOff(): Promise<boolean> {
365
+ const body = {
366
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
367
+ status: 'off',
368
+ uuid: this.cid
369
+ };
370
+
371
+ const [response] = await Helpers.callApi(
372
+ '/dimmer/v1/device/indicatorlightstatus',
373
+ 'put',
374
+ body,
375
+ Helpers.reqHeaders(this.manager)
376
+ );
377
+
378
+ if (response?.code === 0) {
379
+ this._indicatorLight = 'off';
380
+ return true;
381
+ }
382
+ return false;
383
+ }
384
+
385
+ // Getters
386
+ get brightness(): number {
387
+ return this._brightness;
388
+ }
389
+
390
+ get indicatorLightStatus(): string {
391
+ return this._indicatorLight;
392
+ }
393
+
394
+ get rgbLightStatus(): string {
395
+ return this._rgbStatus;
396
+ }
397
+
398
+ get rgbLightValue(): Record<string, number> {
399
+ return { ...this._rgbValue };
400
+ }
401
+ }
402
+
403
+ // Export the switch modules dictionary
404
+ export const switchModules: Record<string, any> = {
405
+ 'ESWL01': VeSyncWallSwitch,
406
+ 'ESWL03': VeSyncWallSwitch,
407
+ 'ESWD16': VeSyncDimmerSwitch
408
+ };