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.
Files changed (40) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.js +25 -0
  3. package/dist/lib/helpers.d.ts +52 -51
  4. package/dist/lib/helpers.js +135 -112
  5. package/dist/lib/logger.d.ts +23 -0
  6. package/dist/lib/logger.js +54 -0
  7. package/dist/lib/vesync.d.ts +57 -15
  8. package/dist/lib/vesync.js +341 -217
  9. package/dist/lib/vesyncBaseDevice.d.ts +25 -50
  10. package/dist/lib/vesyncBaseDevice.js +63 -90
  11. package/dist/lib/vesyncBulb.d.ts +88 -0
  12. package/dist/lib/vesyncBulb.js +295 -1
  13. package/dist/lib/vesyncBulbImpl.d.ts +38 -0
  14. package/dist/lib/vesyncBulbImpl.js +230 -0
  15. package/dist/lib/vesyncFan.d.ts +55 -67
  16. package/dist/lib/vesyncFan.js +366 -213
  17. package/dist/lib/vesyncFanImpl.d.ts +173 -0
  18. package/dist/lib/vesyncFanImpl.js +909 -0
  19. package/dist/lib/vesyncOutlet.d.ts +70 -0
  20. package/dist/lib/vesyncOutlet.js +213 -1
  21. package/dist/lib/vesyncOutletImpl.d.ts +70 -0
  22. package/dist/lib/vesyncOutletImpl.js +245 -0
  23. package/dist/lib/vesyncSwitch.d.ts +45 -0
  24. package/dist/lib/vesyncSwitch.js +77 -1
  25. package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
  26. package/dist/lib/vesyncSwitchImpl.js +344 -0
  27. package/package.json +1 -1
  28. package/src/index.ts +14 -0
  29. package/src/lib/helpers.ts +3 -2
  30. package/src/lib/logger.ts +60 -0
  31. package/src/lib/vesync.ts +42 -43
  32. package/src/lib/vesyncBaseDevice.ts +8 -7
  33. package/src/lib/vesyncBulb.ts +138 -30
  34. package/src/lib/vesyncBulbImpl.ts +113 -44
  35. package/src/lib/vesyncFan.ts +2 -4
  36. package/src/lib/vesyncFanImpl.ts +314 -42
  37. package/src/lib/vesyncOutlet.ts +140 -13
  38. package/src/lib/vesyncOutletImpl.ts +41 -0
  39. package/src/lib/vesyncSwitch.ts +3 -454
  40. package/src/lib/vesyncSwitchImpl.ts +66 -16
@@ -2,9 +2,10 @@
2
2
  * VeSync Bulb Implementations
3
3
  */
4
4
 
5
- import { VeSyncBulb } from './vesyncBulb';
5
+ import { VeSyncBulb, bulbConfig } from './vesyncBulb';
6
6
  import { VeSync } from './vesync';
7
7
  import { Helpers } from './helpers';
8
+ import { logger } from './logger';
8
9
 
9
10
  /**
10
11
  * ESL100 Bulb Implementation
@@ -15,6 +16,7 @@ export class VeSyncBulbESL100 extends VeSyncBulb {
15
16
  }
16
17
 
17
18
  async setColorTemp(colorTemp: number): Promise<boolean> {
19
+ logger.error(`[${this.deviceName}] Color temperature control not supported`);
18
20
  return false;
19
21
  }
20
22
  }
@@ -29,27 +31,35 @@ export class VeSyncBulbESL100CW extends VeSyncBulb {
29
31
 
30
32
  async setColorTemp(colorTemp: number): Promise<boolean> {
31
33
  if (!this.features.includes('color_temp')) {
34
+ logger.error(`[${this.deviceName}] Color temperature control not supported`);
32
35
  return false;
33
36
  }
34
37
 
38
+ logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
35
39
  const body = {
36
- ...Helpers.reqBody(this.manager, 'devicestatus'),
37
- uuid: this.cid,
38
- status: 'on',
39
- colorTemp: colorTemp.toString()
40
+ ...Helpers.reqBody(this.manager, 'bypass'),
41
+ cid: this.cid,
42
+ configModule: this.configModule,
43
+ jsonCmd: {
44
+ light: {
45
+ colorTempe: colorTemp
46
+ }
47
+ }
40
48
  };
41
49
 
42
50
  const [response] = await Helpers.callApi(
43
- '/SmartBulb/v1/device/updateColorTemperature',
44
- 'put',
51
+ '/cloud/v1/deviceManaged/bypass',
52
+ 'post',
45
53
  body,
46
54
  Helpers.reqHeaders(this.manager)
47
55
  );
48
56
 
49
57
  if (response?.code === 0) {
50
58
  this.colorTemp = colorTemp;
59
+ logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
51
60
  return true;
52
61
  }
62
+ logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
53
63
  return false;
54
64
  }
55
65
  }
@@ -64,48 +74,75 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
64
74
 
65
75
  async setColorTemp(colorTemp: number): Promise<boolean> {
66
76
  if (!this.features.includes('color_temp')) {
77
+ logger.error(`[${this.deviceName}] Color temperature control not supported`);
67
78
  return false;
68
79
  }
69
80
 
81
+ logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
70
82
  const body = {
71
- ...Helpers.reqBody(this.manager, 'devicestatus'),
72
- uuid: this.cid,
73
- status: 'on',
74
- colorTemp: colorTemp.toString()
83
+ ...Helpers.reqBody(this.manager, 'bypassV2'),
84
+ cid: this.cid,
85
+ configModule: this.configModule,
86
+ payload: {
87
+ data: {
88
+ brightness: '',
89
+ colorMode: 'white',
90
+ colorTemp: colorTemp,
91
+ force: 1,
92
+ hue: '',
93
+ saturation: '',
94
+ value: ''
95
+ },
96
+ method: 'setLightStatusV2',
97
+ source: 'APP'
98
+ }
75
99
  };
76
100
 
77
101
  const [response] = await Helpers.callApi(
78
- '/SmartBulb/v1/device/updateColorTemperature',
79
- 'put',
102
+ '/cloud/v2/deviceManaged/bypassV2',
103
+ 'post',
80
104
  body,
81
105
  Helpers.reqHeaders(this.manager)
82
106
  );
83
107
 
84
108
  if (response?.code === 0) {
85
109
  this.colorTemp = colorTemp;
110
+ logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
86
111
  return true;
87
112
  }
113
+ logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
88
114
  return false;
89
115
  }
90
116
 
91
117
  async setHsv(hue: number, saturation: number, value: number): Promise<boolean> {
92
118
  if (!this.features.includes('rgb_shift')) {
119
+ logger.error(`[${this.deviceName}] Color control not supported`);
93
120
  return false;
94
121
  }
95
122
 
123
+ logger.debug(`[${this.deviceName}] Setting HSV color to H:${hue} S:${saturation} V:${value}`);
96
124
  const body = {
97
- ...Helpers.reqBody(this.manager, 'devicestatus'),
98
- uuid: this.cid,
99
- status: 'on',
100
- mode: 'color',
101
- hue: Math.round(hue).toString(),
102
- saturation: Math.round(saturation).toString(),
103
- brightness: Math.round(value).toString()
125
+ ...Helpers.reqBody(this.manager, 'bypassV2'),
126
+ cid: this.cid,
127
+ configModule: this.configModule,
128
+ payload: {
129
+ data: {
130
+ brightness: value,
131
+ colorMode: 'hsv',
132
+ colorTemp: '',
133
+ force: 1,
134
+ hue: hue,
135
+ saturation: saturation,
136
+ value: value
137
+ },
138
+ method: 'setLightStatusV2',
139
+ source: 'APP'
140
+ }
104
141
  };
105
142
 
106
143
  const [response] = await Helpers.callApi(
107
- '/SmartBulb/v1/device/updateColor',
108
- 'put',
144
+ '/cloud/v2/deviceManaged/bypassV2',
145
+ 'post',
109
146
  body,
110
147
  Helpers.reqHeaders(this.manager)
111
148
  );
@@ -114,30 +151,47 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
114
151
  this.colorHue = hue;
115
152
  this.colorSaturation = saturation;
116
153
  this.colorValue = value;
154
+ logger.debug(`[${this.deviceName}] Successfully set HSV color`);
117
155
  return true;
118
156
  }
157
+ logger.error(`[${this.deviceName}] Failed to set HSV color: ${JSON.stringify(response)}`);
119
158
  return false;
120
159
  }
121
160
 
122
161
  async enableWhiteMode(): Promise<boolean> {
162
+ logger.debug(`[${this.deviceName}] Enabling white mode`);
123
163
  const body = {
124
- ...Helpers.reqBody(this.manager, 'devicestatus'),
125
- uuid: this.cid,
126
- status: 'on',
127
- colorMode: 'white'
164
+ ...Helpers.reqBody(this.manager, 'bypassV2'),
165
+ cid: this.cid,
166
+ configModule: this.configModule,
167
+ payload: {
168
+ data: {
169
+ brightness: '',
170
+ colorMode: 'white',
171
+ colorTemp: '',
172
+ force: 1,
173
+ red: '',
174
+ green: '',
175
+ blue: ''
176
+ },
177
+ method: 'setLightStatusV2',
178
+ source: 'APP'
179
+ }
128
180
  };
129
181
 
130
182
  const [response] = await Helpers.callApi(
131
- '/SmartBulb/v1/device/updateColorMode',
132
- 'put',
183
+ '/cloud/v2/deviceManaged/bypassV2',
184
+ 'post',
133
185
  body,
134
186
  Helpers.reqHeaders(this.manager)
135
187
  );
136
188
 
137
189
  if (response?.code === 0) {
138
190
  this.colorMode = 'white';
191
+ logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
139
192
  return true;
140
193
  }
194
+ logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
141
195
  return false;
142
196
  }
143
197
  }
@@ -151,63 +205,78 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
151
205
  }
152
206
 
153
207
  async setColorTemp(colorTemp: number): Promise<boolean> {
208
+ logger.error(`[${this.deviceName}] Color temperature control not supported`);
154
209
  return false;
155
210
  }
156
211
 
157
212
  async setRgb(red: number, green: number, blue: number): Promise<boolean> {
158
213
  if (!this.features.includes('rgb_shift')) {
214
+ logger.error(`[${this.deviceName}] Color control not supported`);
159
215
  return false;
160
216
  }
161
217
 
218
+ logger.debug(`[${this.deviceName}] Setting RGB color to R:${red} G:${green} B:${blue}`);
162
219
  const body = {
163
- ...Helpers.reqBody(this.manager, 'devicestatus'),
164
- uuid: this.cid,
165
- status: 'on',
166
- mode: 'color',
167
- red: Math.round(red).toString(),
168
- green: Math.round(green).toString(),
169
- blue: Math.round(blue).toString()
220
+ ...Helpers.reqBody(this.manager, 'bypass'),
221
+ cid: this.cid,
222
+ configModule: this.configModule,
223
+ jsonCmd: {
224
+ light: {
225
+ red: Math.round(red),
226
+ green: Math.round(green),
227
+ blue: Math.round(blue)
228
+ }
229
+ }
170
230
  };
171
231
 
172
232
  const [response] = await Helpers.callApi(
173
- '/SmartBulb/v1/device/updateColor',
174
- 'put',
233
+ '/cloud/v1/deviceManaged/bypass',
234
+ 'post',
175
235
  body,
176
236
  Helpers.reqHeaders(this.manager)
177
237
  );
178
238
 
179
239
  if (response?.code === 0) {
180
240
  this.rgbValues = { red, green, blue };
241
+ logger.debug(`[${this.deviceName}] Successfully set RGB color`);
181
242
  return true;
182
243
  }
244
+ logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
183
245
  return false;
184
246
  }
185
247
 
186
248
  async enableWhiteMode(): Promise<boolean> {
249
+ logger.debug(`[${this.deviceName}] Enabling white mode`);
187
250
  const body = {
188
- ...Helpers.reqBody(this.manager, 'devicestatus'),
189
- uuid: this.cid,
190
- status: 'on',
191
- colorMode: 'white'
251
+ ...Helpers.reqBody(this.manager, 'bypass'),
252
+ cid: this.cid,
253
+ configModule: this.configModule,
254
+ jsonCmd: {
255
+ light: {
256
+ mode: 'white'
257
+ }
258
+ }
192
259
  };
193
260
 
194
261
  const [response] = await Helpers.callApi(
195
- '/SmartBulb/v1/device/updateColorMode',
196
- 'put',
262
+ '/cloud/v1/deviceManaged/bypass',
263
+ 'post',
197
264
  body,
198
265
  Helpers.reqHeaders(this.manager)
199
266
  );
200
267
 
201
268
  if (response?.code === 0) {
202
269
  this.colorMode = 'white';
270
+ logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
203
271
  return true;
204
272
  }
273
+ logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
205
274
  return false;
206
275
  }
207
276
  }
208
277
 
209
278
  // Export the bulb modules dictionary
210
- export const bulbModules: Record<string, any> = {
279
+ export const bulbModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncBulb> = {
211
280
  'ESL100': VeSyncBulbESL100,
212
281
  'ESL100CW': VeSyncBulbESL100CW,
213
282
  'XYD0001': VeSyncBulbXYD0001,
@@ -4,9 +4,7 @@
4
4
 
5
5
  import { VeSyncBaseDevice } from './vesyncBaseDevice';
6
6
  import { VeSync } from './vesync';
7
- import { Helpers } from './helpers';
8
-
9
- type DeviceConstructor = new (config: Record<string, any>, manager: VeSync) => VeSyncBaseDevice;
7
+ import { logger } from './logger';
10
8
 
11
9
  interface FanConfig {
12
10
  [key: string]: {
@@ -396,7 +394,7 @@ export abstract class VeSyncFan extends VeSyncBaseDevice {
396
394
  }
397
395
 
398
396
  for (const [key, value, unit = ''] of info) {
399
- console.log(`${key.toString().padEnd(30, '.')} ${value}${unit}`);
397
+ logger.info(`${key.toString().padEnd(30, '.')} ${value}${unit}`);
400
398
  }
401
399
  }
402
400