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,148 @@
1
+ /**
2
+ * VeSync Outlets
3
+ */
4
+
5
+ import { VeSyncBaseDevice } from './vesyncBaseDevice';
6
+ import { VeSync } from './vesync';
7
+ import { Helpers } from './helpers';
8
+
9
+ /**
10
+ * VeSync Outlet Base Class
11
+ */
12
+ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
13
+ protected energy: Record<string, any>;
14
+ protected details: Record<string, any>;
15
+
16
+ constructor(details: Record<string, any>, manager: VeSync) {
17
+ super(details, manager);
18
+ this.energy = {};
19
+ this.details = details;
20
+ }
21
+
22
+ /**
23
+ * Get outlet details
24
+ */
25
+ async getDetails(): Promise<void> {
26
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/detail`;
27
+ const [response] = await Helpers.callApi(
28
+ url,
29
+ 'get',
30
+ null,
31
+ Helpers.reqHeaders(this.manager)
32
+ );
33
+
34
+ if (response?.code === 0) {
35
+ this.details = response.result;
36
+ this.deviceStatus = response.result.deviceStatus;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Update outlet energy data
42
+ */
43
+ async updateEnergy(): Promise<void> {
44
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/detail`;
45
+ const [response] = await Helpers.callApi(
46
+ url,
47
+ 'get',
48
+ null,
49
+ Helpers.reqHeaders(this.manager)
50
+ );
51
+
52
+ if (response?.code === 0) {
53
+ this.energy = response.result;
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Get outlet energy usage
59
+ */
60
+ async getEnergyUsage(): Promise<Record<string, any>> {
61
+ await this.updateEnergy();
62
+ return {
63
+ power: this.energy.power || 'Not available',
64
+ voltage: this.energy.voltage || 'Not available',
65
+ energy_today: this.energy.energyToday || 'Not available',
66
+ energy_week: this.energy.energyWeek || 'Not available',
67
+ energy_month: this.energy.energyMonth || 'Not available',
68
+ energy_year: this.energy.energyYear || 'Not available'
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Get outlet status
74
+ */
75
+ async getStatus(): Promise<string> {
76
+ await this.getDetails();
77
+ return this.deviceStatus;
78
+ }
79
+
80
+ /**
81
+ * Get weekly energy data
82
+ */
83
+ async getWeeklyEnergy(): Promise<void> {
84
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/week`;
85
+ const [response] = await Helpers.callApi(
86
+ url,
87
+ 'get',
88
+ null,
89
+ Helpers.reqHeaders(this.manager)
90
+ );
91
+
92
+ if (response?.code === 0) {
93
+ this.energy.week = response.result;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Get monthly energy data
99
+ */
100
+ async getMonthlyEnergy(): Promise<void> {
101
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/month`;
102
+ const [response] = await Helpers.callApi(
103
+ url,
104
+ 'get',
105
+ null,
106
+ Helpers.reqHeaders(this.manager)
107
+ );
108
+
109
+ if (response?.code === 0) {
110
+ this.energy.month = response.result;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Get yearly energy data
116
+ */
117
+ async getYearlyEnergy(): Promise<void> {
118
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/year`;
119
+ const [response] = await Helpers.callApi(
120
+ url,
121
+ 'get',
122
+ null,
123
+ Helpers.reqHeaders(this.manager)
124
+ );
125
+
126
+ if (response?.code === 0) {
127
+ this.energy.year = response.result;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Update outlet details and energy info
133
+ */
134
+ async update(): Promise<void> {
135
+ await this.getDetails();
136
+ await this.updateEnergy();
137
+ }
138
+
139
+ /**
140
+ * Turn outlet on
141
+ */
142
+ abstract turnOn(): Promise<boolean>;
143
+
144
+ /**
145
+ * Turn outlet off
146
+ */
147
+ abstract turnOff(): Promise<boolean>;
148
+ }
@@ -0,0 +1,284 @@
1
+ /**
2
+ * VeSync Outlet Implementations
3
+ */
4
+
5
+ import { VeSyncOutlet } from './vesyncOutlet';
6
+ import { VeSync } from './vesync';
7
+ import { Helpers } from './helpers';
8
+
9
+ /**
10
+ * VeSync 7A Outlet
11
+ */
12
+ export class VeSyncOutlet7A extends VeSyncOutlet {
13
+ constructor(details: Record<string, any>, manager: VeSync) {
14
+ super(details, manager);
15
+ }
16
+
17
+ /**
18
+ * Turn outlet on
19
+ */
20
+ async turnOn(): Promise<boolean> {
21
+ const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/on`;
22
+ const [response] = await Helpers.callApi(
23
+ url,
24
+ 'put',
25
+ null,
26
+ Helpers.reqHeaders(this.manager)
27
+ );
28
+
29
+ if (response?.code === 0) {
30
+ this.deviceStatus = 'on';
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+
36
+ /**
37
+ * Turn outlet off
38
+ */
39
+ async turnOff(): Promise<boolean> {
40
+ const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/off`;
41
+ const [response] = await Helpers.callApi(
42
+ url,
43
+ 'put',
44
+ null,
45
+ Helpers.reqHeaders(this.manager)
46
+ );
47
+
48
+ if (response?.code === 0) {
49
+ this.deviceStatus = 'off';
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * VeSync 10A Outlet
58
+ */
59
+ export class VeSyncOutlet10A extends VeSyncOutlet {
60
+ constructor(details: Record<string, any>, manager: VeSync) {
61
+ super(details, manager);
62
+ }
63
+
64
+ /**
65
+ * Turn outlet on
66
+ */
67
+ async turnOn(): Promise<boolean> {
68
+ const body = {
69
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
70
+ uuid: this.uuid,
71
+ status: 'on'
72
+ };
73
+
74
+ const [response] = await Helpers.callApi(
75
+ '/10a/v1/device/devicestatus',
76
+ 'put',
77
+ body,
78
+ Helpers.reqHeaders(this.manager)
79
+ );
80
+
81
+ if (response?.code === 0) {
82
+ this.deviceStatus = 'on';
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+
88
+ /**
89
+ * Turn outlet off
90
+ */
91
+ async turnOff(): Promise<boolean> {
92
+ const body = {
93
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
94
+ uuid: this.uuid,
95
+ status: 'off'
96
+ };
97
+
98
+ const [response] = await Helpers.callApi(
99
+ '/10a/v1/device/devicestatus',
100
+ 'put',
101
+ body,
102
+ Helpers.reqHeaders(this.manager)
103
+ );
104
+
105
+ if (response?.code === 0) {
106
+ this.deviceStatus = 'off';
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * VeSync 15A Outlet
115
+ */
116
+ export class VeSyncOutlet15A extends VeSyncOutlet {
117
+ constructor(details: Record<string, any>, manager: VeSync) {
118
+ super(details, manager);
119
+ }
120
+
121
+ /**
122
+ * Turn outlet on
123
+ */
124
+ async turnOn(): Promise<boolean> {
125
+ const body = {
126
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
127
+ uuid: this.uuid,
128
+ status: 'on'
129
+ };
130
+
131
+ const [response] = await Helpers.callApi(
132
+ '/15a/v1/device/devicestatus',
133
+ 'put',
134
+ body,
135
+ Helpers.reqHeaders(this.manager)
136
+ );
137
+
138
+ if (response?.code === 0) {
139
+ this.deviceStatus = 'on';
140
+ return true;
141
+ }
142
+ return false;
143
+ }
144
+
145
+ /**
146
+ * Turn outlet off
147
+ */
148
+ async turnOff(): Promise<boolean> {
149
+ const body = {
150
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
151
+ uuid: this.uuid,
152
+ status: 'off'
153
+ };
154
+
155
+ const [response] = await Helpers.callApi(
156
+ '/15a/v1/device/devicestatus',
157
+ 'put',
158
+ body,
159
+ Helpers.reqHeaders(this.manager)
160
+ );
161
+
162
+ if (response?.code === 0) {
163
+ this.deviceStatus = 'off';
164
+ return true;
165
+ }
166
+ return false;
167
+ }
168
+
169
+ /**
170
+ * Turn on nightlight
171
+ */
172
+ async turnOnNightlight(): Promise<boolean> {
173
+ const body = {
174
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
175
+ uuid: this.uuid,
176
+ mode: 'auto'
177
+ };
178
+
179
+ const [response] = await Helpers.callApi(
180
+ '/15a/v1/device/nightlightstatus',
181
+ 'put',
182
+ body,
183
+ Helpers.reqHeaders(this.manager)
184
+ );
185
+
186
+ if (response?.code === 0) {
187
+ this.details.nightLightStatus = 'on';
188
+ return true;
189
+ }
190
+ return false;
191
+ }
192
+
193
+ /**
194
+ * Turn off nightlight
195
+ */
196
+ async turnOffNightlight(): Promise<boolean> {
197
+ const body = {
198
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
199
+ uuid: this.uuid,
200
+ mode: 'manual'
201
+ };
202
+
203
+ const [response] = await Helpers.callApi(
204
+ '/15a/v1/device/nightlightstatus',
205
+ 'put',
206
+ body,
207
+ Helpers.reqHeaders(this.manager)
208
+ );
209
+
210
+ if (response?.code === 0) {
211
+ this.details.nightLightStatus = 'off';
212
+ return true;
213
+ }
214
+ return false;
215
+ }
216
+ }
217
+
218
+ /**
219
+ * VeSync Outdoor Plug
220
+ */
221
+ export class VeSyncOutdoorPlug extends VeSyncOutlet {
222
+ constructor(details: Record<string, any>, manager: VeSync) {
223
+ super(details, manager);
224
+ }
225
+
226
+ /**
227
+ * Turn outlet on
228
+ */
229
+ async turnOn(): Promise<boolean> {
230
+ const body = {
231
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
232
+ uuid: this.uuid,
233
+ status: 'on',
234
+ switchNo: 1
235
+ };
236
+
237
+ const [response] = await Helpers.callApi(
238
+ '/outdoorsocket15a/v1/device/devicestatus',
239
+ 'put',
240
+ body,
241
+ Helpers.reqHeaders(this.manager)
242
+ );
243
+
244
+ if (response?.code === 0) {
245
+ this.deviceStatus = 'on';
246
+ return true;
247
+ }
248
+ return false;
249
+ }
250
+
251
+ /**
252
+ * Turn outlet off
253
+ */
254
+ async turnOff(): Promise<boolean> {
255
+ const body = {
256
+ ...Helpers.reqBody(this.manager, 'devicestatus'),
257
+ uuid: this.uuid,
258
+ status: 'off',
259
+ switchNo: 1
260
+ };
261
+
262
+ const [response] = await Helpers.callApi(
263
+ '/outdoorsocket15a/v1/device/devicestatus',
264
+ 'put',
265
+ body,
266
+ Helpers.reqHeaders(this.manager)
267
+ );
268
+
269
+ if (response?.code === 0) {
270
+ this.deviceStatus = 'off';
271
+ return true;
272
+ }
273
+ return false;
274
+ }
275
+ }
276
+
277
+ // Export outlet modules dictionary
278
+ export const outletModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncOutlet> = {
279
+ 'wifi-switch-1.3': VeSyncOutlet7A,
280
+ 'ESW03-USA': VeSyncOutlet10A,
281
+ 'ESW01-EU': VeSyncOutlet10A,
282
+ 'ESW15-USA': VeSyncOutlet15A,
283
+ 'ESO15-TB': VeSyncOutdoorPlug
284
+ };