tsvesync 1.3.9 → 1.3.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.
@@ -14,6 +14,86 @@ class VeSyncBulbESL100 extends vesyncBulb_1.VeSyncBulb {
14
14
  constructor(details, manager) {
15
15
  super(details, manager);
16
16
  }
17
+ async getDetails() {
18
+ logger_1.logger.debug(`[${this.deviceName}] Fetching ESL100 details`);
19
+ const body = {
20
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
21
+ uuid: this.uuid
22
+ };
23
+ const [response, statusCode] = await this.callApi('/SmartBulb/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
24
+ const success = this.checkResponse([response, statusCode], 'getDetails');
25
+ if (success && (response === null || response === void 0 ? void 0 : response.result)) {
26
+ const result = response.result;
27
+ if (result.deviceStatus) {
28
+ this.deviceStatus = result.deviceStatus;
29
+ }
30
+ if (result.connectionStatus) {
31
+ this.connectionStatus = result.connectionStatus;
32
+ }
33
+ if (result.brightNess !== undefined) {
34
+ this.brightness = Number(result.brightNess);
35
+ }
36
+ else if (result.brightness !== undefined) {
37
+ this.brightness = Number(result.brightness);
38
+ }
39
+ logger_1.logger.debug(`[${this.deviceName}] Updated details: status=${this.deviceStatus}, brightness=${this.brightness}`);
40
+ }
41
+ return success;
42
+ }
43
+ async turnOn() {
44
+ const body = {
45
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
46
+ uuid: this.uuid,
47
+ status: 'on'
48
+ };
49
+ const [response] = await this.callApi('/SmartBulb/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
50
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
51
+ this.deviceStatus = 'on';
52
+ this.connectionStatus = 'online';
53
+ logger_1.logger.info(`[${this.deviceName}] Turned on successfully`);
54
+ return true;
55
+ }
56
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn on: ${JSON.stringify(response)}`);
57
+ return false;
58
+ }
59
+ async turnOff() {
60
+ const body = {
61
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
62
+ uuid: this.uuid,
63
+ status: 'off'
64
+ };
65
+ const [response] = await this.callApi('/SmartBulb/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
66
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
67
+ this.deviceStatus = 'off';
68
+ logger_1.logger.info(`[${this.deviceName}] Turned off successfully`);
69
+ return true;
70
+ }
71
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn off: ${JSON.stringify(response)}`);
72
+ return false;
73
+ }
74
+ async setBrightness(brightness) {
75
+ if (!this.features.includes('dimmable')) {
76
+ logger_1.logger.error(`[${this.deviceName}] Dimming not supported`);
77
+ return false;
78
+ }
79
+ const brightnessUpdate = vesyncBulb_1.VeSyncBulb.clamp(Math.round(brightness), 0, 100);
80
+ const body = {
81
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
82
+ uuid: this.uuid,
83
+ status: 'on',
84
+ brightNess: String(brightnessUpdate)
85
+ };
86
+ const [response] = await this.callApi('/SmartBulb/v1/device/updateBrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
87
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
88
+ this.brightness = brightnessUpdate;
89
+ this.deviceStatus = 'on';
90
+ this.connectionStatus = 'online';
91
+ logger_1.logger.info(`[${this.deviceName}] Brightness set to ${brightnessUpdate}`);
92
+ return true;
93
+ }
94
+ logger_1.logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
95
+ return false;
96
+ }
17
97
  async setColorTemp(colorTemp) {
18
98
  logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
19
99
  return false;
@@ -27,26 +107,106 @@ class VeSyncBulbESL100CW extends vesyncBulb_1.VeSyncBulb {
27
107
  constructor(details, manager) {
28
108
  super(details, manager);
29
109
  }
30
- async setColorTemp(colorTemp) {
31
- if (!this.features.includes('color_temp')) {
32
- logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
33
- return false;
34
- }
35
- logger_1.logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
110
+ buildBypassBody(lightPayload) {
111
+ return {
112
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
113
+ cid: this.cid,
114
+ configModule: this.configModule,
115
+ jsonCmd: {
116
+ light: lightPayload
117
+ }
118
+ };
119
+ }
120
+ async getDetails() {
121
+ var _a;
122
+ logger_1.logger.debug(`[${this.deviceName}] Fetching ESL100CW status`);
36
123
  const body = {
37
124
  ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
38
125
  cid: this.cid,
39
126
  configModule: this.configModule,
40
127
  jsonCmd: {
41
- light: {
42
- colorTempe: colorTemp
128
+ getLightStatus: 'get'
129
+ }
130
+ };
131
+ const [response, statusCode] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
132
+ const success = this.checkResponse([response, statusCode], 'getDetails');
133
+ if (success) {
134
+ const inner = ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result) || (response === null || response === void 0 ? void 0 : response.result);
135
+ const light = inner === null || inner === void 0 ? void 0 : inner.light;
136
+ if (light) {
137
+ this.deviceStatus = light.action === 'on' ? 'on' : 'off';
138
+ if (light.brightness !== undefined) {
139
+ this.brightness = Number(light.brightness);
140
+ }
141
+ if (light.colorTempe !== undefined) {
142
+ this.colorTemp = Number(light.colorTempe);
43
143
  }
44
144
  }
145
+ }
146
+ return success;
147
+ }
148
+ async turnOn() {
149
+ const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', this.buildBypassBody({ action: 'on' }), helpers_1.Helpers.reqHeaders(this.manager));
150
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
151
+ this.deviceStatus = 'on';
152
+ this.connectionStatus = 'online';
153
+ logger_1.logger.info(`[${this.deviceName}] Turned on successfully`);
154
+ return true;
155
+ }
156
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn on: ${JSON.stringify(response)}`);
157
+ return false;
158
+ }
159
+ async turnOff() {
160
+ const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', this.buildBypassBody({ action: 'off' }), helpers_1.Helpers.reqHeaders(this.manager));
161
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
162
+ this.deviceStatus = 'off';
163
+ logger_1.logger.info(`[${this.deviceName}] Turned off successfully`);
164
+ return true;
165
+ }
166
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn off: ${JSON.stringify(response)}`);
167
+ return false;
168
+ }
169
+ async setBrightness(brightness) {
170
+ if (!this.features.includes('dimmable')) {
171
+ logger_1.logger.error(`[${this.deviceName}] Dimming not supported`);
172
+ return false;
173
+ }
174
+ const brightnessUpdate = vesyncBulb_1.VeSyncBulb.clamp(Math.round(brightness), 0, 100);
175
+ const light = {
176
+ action: 'on',
177
+ brightness: brightnessUpdate
45
178
  };
46
- const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
179
+ if (this.features.includes('color_temp')) {
180
+ light.colorTempe = this.colorTemp;
181
+ }
182
+ const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', this.buildBypassBody(light), helpers_1.Helpers.reqHeaders(this.manager));
47
183
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
48
- this.colorTemp = colorTemp;
49
- logger_1.logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
184
+ this.brightness = brightnessUpdate;
185
+ this.deviceStatus = 'on';
186
+ this.connectionStatus = 'online';
187
+ logger_1.logger.info(`[${this.deviceName}] Brightness set to ${brightnessUpdate}`);
188
+ return true;
189
+ }
190
+ logger_1.logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
191
+ return false;
192
+ }
193
+ async setColorTemp(colorTemp) {
194
+ if (!this.features.includes('color_temp')) {
195
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
196
+ return false;
197
+ }
198
+ const colorTempUpdate = vesyncBulb_1.VeSyncBulb.clamp(Math.round(colorTemp), 0, 100);
199
+ const light = {
200
+ action: 'on',
201
+ brightness: this.brightness,
202
+ colorTempe: colorTempUpdate
203
+ };
204
+ const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', this.buildBypassBody(light), helpers_1.Helpers.reqHeaders(this.manager));
205
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
206
+ this.colorTemp = colorTempUpdate;
207
+ this.deviceStatus = 'on';
208
+ this.connectionStatus = 'online';
209
+ logger_1.logger.info(`[${this.deviceName}] Color temperature set to ${colorTempUpdate}`);
50
210
  return true;
51
211
  }
52
212
  logger_1.logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
@@ -167,8 +327,104 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
167
327
  constructor(details, manager) {
168
328
  super(details, manager);
169
329
  }
170
- async setColorTemp(colorTemp) {
171
- logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
330
+ buildBypassV2Payload(method, data) {
331
+ return {
332
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
333
+ cid: this.cid,
334
+ configModule: this.configModule,
335
+ payload: {
336
+ method,
337
+ source: 'APP',
338
+ data
339
+ }
340
+ };
341
+ }
342
+ handleBypassV2Response(response, context) {
343
+ if (!response) {
344
+ logger_1.logger.error(`[${this.deviceName}] ${context} returned empty response`);
345
+ return false;
346
+ }
347
+ if (response.code !== 0) {
348
+ logger_1.logger.error(`[${this.deviceName}] ${context} failed: ${JSON.stringify(response)}`);
349
+ return false;
350
+ }
351
+ const inner = response.result;
352
+ if ((inner === null || inner === void 0 ? void 0 : inner.code) !== undefined && inner.code !== 0) {
353
+ logger_1.logger.error(`[${this.deviceName}] ${context} inner error: ${JSON.stringify(response)}`);
354
+ return false;
355
+ }
356
+ return true;
357
+ }
358
+ async getDetails() {
359
+ var _a, _b, _c, _d;
360
+ logger_1.logger.debug(`[${this.deviceName}] Fetching ESL100MC status`);
361
+ const body = this.buildBypassV2Payload('getLightStatus', {});
362
+ const [response, statusCode] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
363
+ const success = this.checkResponse([response, statusCode], 'getDetails');
364
+ if (!success) {
365
+ return false;
366
+ }
367
+ const inner = ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result) || (response === null || response === void 0 ? void 0 : response.result);
368
+ if (inner) {
369
+ if (inner.action) {
370
+ this.deviceStatus = inner.action === 'on' ? 'on' : 'off';
371
+ }
372
+ if (inner.brightness !== undefined) {
373
+ this.brightness = Number(inner.brightness);
374
+ }
375
+ this.rgbValues = {
376
+ red: Number((_b = inner.red) !== null && _b !== void 0 ? _b : this.rgbValues.red),
377
+ green: Number((_c = inner.green) !== null && _c !== void 0 ? _c : this.rgbValues.green),
378
+ blue: Number((_d = inner.blue) !== null && _d !== void 0 ? _d : this.rgbValues.blue)
379
+ };
380
+ this.colorMode = inner.colorMode || this.colorMode;
381
+ }
382
+ return true;
383
+ }
384
+ async turnOn() {
385
+ const body = this.buildBypassV2Payload('setSwitch', {
386
+ id: 0,
387
+ enabled: true
388
+ });
389
+ const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
390
+ if (this.handleBypassV2Response(response, 'turn on')) {
391
+ this.deviceStatus = 'on';
392
+ this.connectionStatus = 'online';
393
+ return true;
394
+ }
395
+ return false;
396
+ }
397
+ async turnOff() {
398
+ const body = this.buildBypassV2Payload('setSwitch', {
399
+ id: 0,
400
+ enabled: false
401
+ });
402
+ const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
403
+ if (this.handleBypassV2Response(response, 'turn off')) {
404
+ this.deviceStatus = 'off';
405
+ return true;
406
+ }
407
+ return false;
408
+ }
409
+ async setBrightness(brightness) {
410
+ const brightnessUpdate = vesyncBulb_1.VeSyncBulb.clamp(Math.round(brightness), 0, 100);
411
+ const body = this.buildBypassV2Payload('setLightStatus', {
412
+ action: 'on',
413
+ speed: 0,
414
+ brightness: brightnessUpdate,
415
+ red: 0,
416
+ green: 0,
417
+ blue: 0,
418
+ colorMode: 'white'
419
+ });
420
+ const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
421
+ if (this.handleBypassV2Response(response, 'set brightness')) {
422
+ this.brightness = brightnessUpdate;
423
+ this.deviceStatus = 'on';
424
+ this.colorMode = 'white';
425
+ this.connectionStatus = 'online';
426
+ return true;
427
+ }
172
428
  return false;
173
429
  }
174
430
  async setRgb(red, green, blue) {
@@ -176,47 +432,40 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
176
432
  logger_1.logger.error(`[${this.deviceName}] Color control not supported`);
177
433
  return false;
178
434
  }
179
- logger_1.logger.debug(`[${this.deviceName}] Setting RGB color to R:${red} G:${green} B:${blue}`);
180
- const body = {
181
- ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
182
- cid: this.cid,
183
- configModule: this.configModule,
184
- jsonCmd: {
185
- light: {
186
- red: Math.round(red),
187
- green: Math.round(green),
188
- blue: Math.round(blue)
189
- }
190
- }
191
- };
192
- const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
193
- if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
194
- this.rgbValues = { red, green, blue };
195
- logger_1.logger.info(`[${this.deviceName}] Successfully set RGB color`);
435
+ const body = this.buildBypassV2Payload('setLightStatus', {
436
+ action: 'on',
437
+ speed: 0,
438
+ brightness: 100,
439
+ red: vesyncBulb_1.VeSyncBulb.clamp(Math.round(red), 0, 255),
440
+ green: vesyncBulb_1.VeSyncBulb.clamp(Math.round(green), 0, 255),
441
+ blue: vesyncBulb_1.VeSyncBulb.clamp(Math.round(blue), 0, 255),
442
+ colorMode: 'color'
443
+ });
444
+ const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
445
+ if (this.handleBypassV2Response(response, 'set RGB color')) {
446
+ this.rgbValues = {
447
+ red: vesyncBulb_1.VeSyncBulb.clamp(Math.round(red), 0, 255),
448
+ green: vesyncBulb_1.VeSyncBulb.clamp(Math.round(green), 0, 255),
449
+ blue: vesyncBulb_1.VeSyncBulb.clamp(Math.round(blue), 0, 255)
450
+ };
451
+ this.brightness = 100;
452
+ this.deviceStatus = 'on';
453
+ this.colorMode = 'color';
454
+ this.connectionStatus = 'online';
196
455
  return true;
197
456
  }
198
- logger_1.logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
199
457
  return false;
200
458
  }
201
459
  async enableWhiteMode() {
202
- logger_1.logger.debug(`[${this.deviceName}] Enabling white mode`);
203
- const body = {
204
- ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
205
- cid: this.cid,
206
- configModule: this.configModule,
207
- jsonCmd: {
208
- light: {
209
- mode: 'white'
210
- }
211
- }
212
- };
213
- const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
214
- if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
460
+ const targetBrightness = this.brightness > 0 ? this.brightness : 100;
461
+ const success = await this.setBrightness(targetBrightness);
462
+ if (success) {
215
463
  this.colorMode = 'white';
216
- logger_1.logger.info(`[${this.deviceName}] Successfully enabled white mode`);
217
- return true;
218
464
  }
219
- logger_1.logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
465
+ return success;
466
+ }
467
+ async setColorTemp(colorTemp) {
468
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
220
469
  return false;
221
470
  }
222
471
  }
@@ -29,10 +29,7 @@ export declare class VeSyncWallSwitch extends VeSyncSwitch {
29
29
  * Dimmer Switch Implementation (ESWD16)
30
30
  */
31
31
  export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
32
- private _brightness;
33
- private _rgbValue;
34
- private _rgbStatus;
35
- private _indicatorLight;
32
+ private stateSnapshot;
36
33
  constructor(details: Record<string, any>, manager: VeSync);
37
34
  /**
38
35
  * Get dimmer switch details
@@ -78,5 +75,9 @@ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
78
75
  get indicatorLightStatus(): string;
79
76
  get rgbLightStatus(): string;
80
77
  get rgbLightValue(): Record<string, number>;
78
+ private toggleSwitch;
79
+ private toggleIndicatorLight;
80
+ private buildDimmerRequest;
81
+ private callDimmerCommand;
81
82
  }
82
83
  export declare const switchModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncSwitch>;