tsvesync 1.0.22 → 1.0.24

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.
@@ -20,7 +20,7 @@ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
20
20
  async turnOn() {
21
21
  logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
22
22
  const url = `/v1/wifi-switch-1.3/${this.cid}/status/on`;
23
- const [response, statusCode] = await helpers_1.Helpers.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
23
+ const [response, statusCode] = await this.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
24
24
  if (statusCode === 200) {
25
25
  this.deviceStatus = 'on';
26
26
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
@@ -35,7 +35,7 @@ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
35
35
  async turnOff() {
36
36
  logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
37
37
  const url = `/v1/wifi-switch-1.3/${this.cid}/status/off`;
38
- const [response, statusCode] = await helpers_1.Helpers.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
38
+ const [response, statusCode] = await this.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
39
39
  if (statusCode === 200) {
40
40
  this.deviceStatus = 'off';
41
41
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
@@ -63,7 +63,7 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
63
63
  uuid: this.uuid,
64
64
  status: 'on'
65
65
  };
66
- const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
66
+ const [response] = await this.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
67
67
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
68
68
  this.deviceStatus = 'on';
69
69
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
@@ -82,7 +82,7 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
82
82
  uuid: this.uuid,
83
83
  status: 'off'
84
84
  };
85
- const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
85
+ const [response] = await this.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
86
86
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
87
87
  this.deviceStatus = 'off';
88
88
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
@@ -110,7 +110,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
110
110
  uuid: this.uuid,
111
111
  status: 'on'
112
112
  };
113
- const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
113
+ const [response] = await this.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
114
114
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
115
115
  this.deviceStatus = 'on';
116
116
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
@@ -129,7 +129,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
129
129
  uuid: this.uuid,
130
130
  status: 'off'
131
131
  };
132
- const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
132
+ const [response] = await this.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
133
133
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
134
134
  this.deviceStatus = 'off';
135
135
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
@@ -152,7 +152,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
152
152
  uuid: this.uuid,
153
153
  mode: 'auto'
154
154
  };
155
- const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
155
+ const [response] = await this.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
156
156
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
157
157
  this.details.nightLightStatus = 'on';
158
158
  logger_1.logger.info(`[${this.deviceName}] Successfully turned nightlight on`);
@@ -175,7 +175,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
175
175
  uuid: this.uuid,
176
176
  mode: 'manual'
177
177
  };
178
- const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
178
+ const [response] = await this.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
179
179
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
180
180
  this.details.nightLightStatus = 'off';
181
181
  logger_1.logger.info(`[${this.deviceName}] Successfully turned nightlight off`);
@@ -194,16 +194,11 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
194
194
  super(details, manager);
195
195
  this.isSubDevice = details.isSubDevice || false;
196
196
  this.subDeviceNo = details.subDeviceNo;
197
- this.parentCid = details.parentCid;
198
197
  }
199
198
  /**
200
199
  * Turn outlet on
201
200
  */
202
201
  async turnOn() {
203
- if (!this.isSubDevice) {
204
- logger_1.logger.error(`[${this.deviceName}] Cannot control parent device directly`);
205
- return false;
206
- }
207
202
  logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
208
203
  const body = {
209
204
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
@@ -211,7 +206,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
211
206
  status: 'on',
212
207
  switchNo: this.subDeviceNo
213
208
  };
214
- const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
209
+ const [response] = await this.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
215
210
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
216
211
  this.deviceStatus = 'on';
217
212
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
@@ -224,10 +219,6 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
224
219
  * Turn outlet off
225
220
  */
226
221
  async turnOff() {
227
- if (!this.isSubDevice) {
228
- logger_1.logger.error(`[${this.deviceName}] Cannot control parent device directly`);
229
- return false;
230
- }
231
222
  logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
232
223
  const body = {
233
224
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
@@ -235,7 +226,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
235
226
  status: 'off',
236
227
  switchNo: this.subDeviceNo
237
228
  };
238
- const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
229
+ const [response] = await this.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
239
230
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
240
231
  this.deviceStatus = 'off';
241
232
  logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
@@ -25,7 +25,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
25
25
  uuid: this.cid,
26
26
  method: 'devicedetail'
27
27
  };
28
- const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
28
+ const [response] = await this.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
29
29
  if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
30
30
  const result = response.result;
31
31
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
@@ -47,7 +47,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
47
47
  method: 'configurations',
48
48
  uuid: this.cid
49
49
  };
50
- const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
50
+ const [response] = await this.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
51
51
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
52
52
  this.config = helpers_1.Helpers.buildConfigDict(response);
53
53
  logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
@@ -66,7 +66,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
66
66
  status: 'off',
67
67
  uuid: this.cid
68
68
  };
69
- const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
69
+ const [response] = await this.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
70
70
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
71
71
  this.deviceStatus = 'off';
72
72
  logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
@@ -85,7 +85,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
85
85
  status: 'on',
86
86
  uuid: this.cid
87
87
  };
88
- const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
88
+ const [response] = await this.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
89
89
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
90
90
  this.deviceStatus = 'on';
91
91
  logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
@@ -118,7 +118,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
118
118
  uuid: this.cid,
119
119
  method: 'devicedetail'
120
120
  };
121
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
121
+ const [response] = await this.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
122
122
  if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
123
123
  const result = response.result;
124
124
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
@@ -150,7 +150,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
150
150
  method: 'configurations',
151
151
  uuid: this.cid
152
152
  };
153
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
153
+ const [response] = await this.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
154
154
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
155
155
  this.config = helpers_1.Helpers.buildConfigDict(response);
156
156
  logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
@@ -169,7 +169,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
169
169
  status: 'off',
170
170
  uuid: this.cid
171
171
  };
172
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
172
+ const [response] = await this.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
173
173
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
174
174
  this.deviceStatus = 'off';
175
175
  logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
@@ -188,7 +188,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
188
188
  status: 'on',
189
189
  uuid: this.cid
190
190
  };
191
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
191
+ const [response] = await this.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
192
192
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
193
193
  this.deviceStatus = 'on';
194
194
  logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
@@ -211,7 +211,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
211
211
  brightness: brightness.toString(),
212
212
  uuid: this.cid
213
213
  };
214
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
214
+ const [response] = await this.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
215
215
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
216
216
  this._brightness = brightness;
217
217
  logger_1.logger.debug(`Successfully set brightness to ${brightness} for device: ${this.deviceName}`);
@@ -235,7 +235,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
235
235
  status: 'on',
236
236
  uuid: this.cid
237
237
  };
238
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
238
+ const [response] = await this.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
239
239
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
240
240
  this._rgbValue = { red, green, blue };
241
241
  this._rgbStatus = 'on';
@@ -255,7 +255,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
255
255
  status: 'off',
256
256
  uuid: this.cid
257
257
  };
258
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
258
+ const [response] = await this.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
259
259
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
260
260
  this._rgbStatus = 'off';
261
261
  logger_1.logger.debug(`Successfully turned off RGB color for device: ${this.deviceName}`);
@@ -274,7 +274,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
274
274
  uuid: this.cid,
275
275
  status: 'on'
276
276
  };
277
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
277
+ const [response] = await this.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
278
278
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
279
279
  this._rgbStatus = 'on';
280
280
  logger_1.logger.debug(`Successfully turned on RGB color for device: ${this.deviceName}`);
@@ -293,7 +293,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
293
293
  uuid: this.cid,
294
294
  status: 'on'
295
295
  };
296
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
296
+ const [response] = await this.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
297
297
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
298
298
  this._indicatorLight = 'on';
299
299
  logger_1.logger.debug(`Successfully turned on indicator light for device: ${this.deviceName}`);
@@ -312,7 +312,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
312
312
  uuid: this.cid,
313
313
  status: 'off'
314
314
  };
315
- const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
315
+ const [response] = await this.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
316
316
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
317
317
  this._indicatorLight = 'off';
318
318
  logger_1.logger.debug(`Successfully turned off indicator light for device: ${this.deviceName}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "A TypeScript library for interacting with VeSync smart home devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -202,7 +202,8 @@ export class Helpers {
202
202
  endpoint: string,
203
203
  method: string,
204
204
  data: any = null,
205
- headers: Record<string, string> = {}
205
+ headers: Record<string, string> = {},
206
+ manager: VeSync
206
207
  ): Promise<[any, number]> {
207
208
  try {
208
209
  const url = _apiBaseUrl + endpoint;
@@ -217,7 +218,20 @@ export class Helpers {
217
218
  return [response.data, response.status];
218
219
  } catch (error: any) {
219
220
  if (error.response) {
220
- return [error.response.data, error.response.status];
221
+ const responseData = error.response.data;
222
+
223
+ // Check for token expiration
224
+ if (responseData?.code === 4001004 || responseData?.msg === "token expired") {
225
+ logger.debug('Token expired, attempting to re-login...');
226
+
227
+ // Re-login
228
+ if (await manager.login()) {
229
+ // Retry the original request
230
+ logger.debug('Re-login successful, retrying original request...');
231
+ return await this.callApi(endpoint, method, data, headers, manager);
232
+ }
233
+ }
234
+ return [responseData, error.response.status];
221
235
  }
222
236
  logger.error('API call failed:', error.message);
223
237
  return [null, 0];
package/src/lib/vesync.ts CHANGED
@@ -8,7 +8,6 @@ import { fanModules } from './vesyncFanImpl';
8
8
  import { outletModules } from './vesyncOutletImpl';
9
9
  import { switchModules } from './vesyncSwitchImpl';
10
10
  import { bulbModules } from './vesyncBulbImpl';
11
- import { VeSyncBulb } from './vesyncBulb';
12
11
  import { logger, setLogger, Logger } from './logger';
13
12
 
14
13
  const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
@@ -105,24 +104,20 @@ function objectFactory(details: Record<string, any>, manager: VeSync): [string,
105
104
  details.deviceCategory = category;
106
105
 
107
106
  // Handle outdoor plug sub-devices
108
- if (deviceType === 'ESO15-TB' && details.subDevices) {
107
+ if (deviceType === 'ESO15-TB' && details.subDeviceNo) {
109
108
  const devices: [string, VeSyncBaseDevice | null][] = [];
110
109
 
111
110
  // Create a device instance for each sub-device
112
- details.subDevices.forEach((subDevice: any) => {
113
- const subDeviceDetails = {
114
- ...details,
115
- deviceName: subDevice.subDeviceName,
116
- deviceStatus: subDevice.subDeviceStatus,
117
- subDeviceNo: subDevice.subDeviceNo,
118
- isSubDevice: true,
119
- parentCid: details.cid,
120
- // Generate a unique CID for the sub-device
121
- cid: `${details.cid}_${subDevice.subDeviceNo}`
122
- };
123
- const device = new DeviceClass(subDeviceDetails, manager);
124
- devices.push([category, device]);
125
- });
111
+
112
+ const subDeviceDetails = {
113
+ ...details,
114
+ deviceName: details.deviceName,
115
+ deviceStatus: details.deviceStatus,
116
+ subDeviceNo: details.subDeviceNo,
117
+ isSubDevice: true
118
+ };
119
+ const device = new DeviceClass(subDeviceDetails, manager);
120
+ devices.push([category, device]);
126
121
 
127
122
  // Return array of sub-devices
128
123
  return devices[0]; // Return first device, manager will handle adding all devices
@@ -373,24 +368,19 @@ export class VeSync {
373
368
  // Process each device
374
369
  deviceList.forEach(dev => {
375
370
  const [category, device] = objectFactory(dev, this);
376
-
377
371
  // Handle outdoor plug sub-devices
378
- if (dev.deviceType === 'ESO15-TB' && dev.subDevices) {
379
- dev.subDevices.forEach((subDev: any) => {
380
- const subDeviceDetails = {
381
- ...dev,
382
- deviceName: subDev.subDeviceName,
383
- deviceStatus: subDev.subDeviceStatus,
384
- subDeviceNo: subDev.subDeviceNo,
385
- isSubDevice: true,
386
- parentCid: dev.cid,
387
- cid: `${dev.cid}_${subDev.subDeviceNo}`
388
- };
389
- const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
390
- if (subDevice && subCategory in this._devList) {
391
- this._devList[subCategory].push(subDevice);
392
- }
393
- });
372
+ if (dev.deviceType === 'ESO15-TB' && dev.subDeviceNo) {
373
+ const subDeviceDetails = {
374
+ ...dev,
375
+ deviceName: dev.deviceName,
376
+ deviceStatus: dev.deviceStatus,
377
+ subDeviceNo: dev.subDeviceNo,
378
+ isSubDevice: true,
379
+ };
380
+ const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
381
+ if (subDevice && subCategory in this._devList) {
382
+ this._devList[subCategory].push(subDevice);
383
+ }
394
384
  } else if (device && category in this._devList) {
395
385
  this._devList[category].push(device);
396
386
  }
@@ -424,7 +414,8 @@ export class VeSync {
424
414
  '/cloud/v2/deviceManaged/devices',
425
415
  'post',
426
416
  Helpers.reqBody(this, 'devicelist'),
427
- Helpers.reqHeaders(this)
417
+ Helpers.reqHeaders(this),
418
+ this
428
419
  );
429
420
 
430
421
  if (response?.result?.list) {
@@ -488,7 +479,9 @@ export class VeSync {
488
479
  const [response, status] = await Helpers.callApi(
489
480
  '/cloud/v1/user/login',
490
481
  'post',
491
- body
482
+ body,
483
+ {},
484
+ this
492
485
  );
493
486
 
494
487
  logger.debug('Login response:', { status, response });
@@ -559,4 +552,16 @@ export class VeSync {
559
552
 
560
553
  return null;
561
554
  }
555
+
556
+ /**
557
+ * Call API with authentication
558
+ */
559
+ protected async callApi(
560
+ endpoint: string,
561
+ method: string,
562
+ data: any = null,
563
+ headers: Record<string, string> = {}
564
+ ): Promise<[any, number]> {
565
+ return await Helpers.callApi(endpoint, method, data, headers, this);
566
+ }
562
567
  }
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { VeSync } from './vesync';
6
6
  import { logger } from './logger';
7
+ import { Helpers } from './helpers';
7
8
 
8
9
  export abstract class VeSyncBaseDevice {
9
10
  protected manager: VeSync;
@@ -112,4 +113,16 @@ export abstract class VeSyncBaseDevice {
112
113
  async update(): Promise<void> {
113
114
  await this.getDetails();
114
115
  }
116
+
117
+ /**
118
+ * Call API with proper headers
119
+ */
120
+ protected async callApi(
121
+ endpoint: string,
122
+ method: string,
123
+ data: any = null,
124
+ headers: Record<string, string> = {}
125
+ ): Promise<[any, number]> {
126
+ return await Helpers.callApi(endpoint, method, data, headers, this.manager);
127
+ }
115
128
  }
@@ -94,7 +94,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
94
94
  }
95
95
  };
96
96
 
97
- const [response] = await Helpers.callApi(
97
+ const [response] = await this.callApi(
98
98
  endpoint,
99
99
  'post',
100
100
  body,
@@ -166,7 +166,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
166
166
  }
167
167
  };
168
168
 
169
- const [response] = await Helpers.callApi(
169
+ const [response] = await this.callApi(
170
170
  endpoint,
171
171
  'post',
172
172
  body,
@@ -213,7 +213,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
213
213
  }
214
214
  };
215
215
 
216
- const [response] = await Helpers.callApi(
216
+ const [response] = await this.callApi(
217
217
  endpoint,
218
218
  'post',
219
219
  body,
@@ -270,7 +270,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
270
270
  }
271
271
  };
272
272
 
273
- const [response] = await Helpers.callApi(
273
+ const [response] = await this.callApi(
274
274
  endpoint,
275
275
  'post',
276
276
  body,
@@ -47,7 +47,7 @@ export class VeSyncBulbESL100CW extends VeSyncBulb {
47
47
  }
48
48
  };
49
49
 
50
- const [response] = await Helpers.callApi(
50
+ const [response] = await this.callApi(
51
51
  '/cloud/v1/deviceManaged/bypass',
52
52
  'post',
53
53
  body,
@@ -98,7 +98,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
98
98
  }
99
99
  };
100
100
 
101
- const [response] = await Helpers.callApi(
101
+ const [response] = await this.callApi(
102
102
  '/cloud/v2/deviceManaged/bypassV2',
103
103
  'post',
104
104
  body,
@@ -140,7 +140,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
140
140
  }
141
141
  };
142
142
 
143
- const [response] = await Helpers.callApi(
143
+ const [response] = await this.callApi(
144
144
  '/cloud/v2/deviceManaged/bypassV2',
145
145
  'post',
146
146
  body,
@@ -179,7 +179,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
179
179
  }
180
180
  };
181
181
 
182
- const [response] = await Helpers.callApi(
182
+ const [response] = await this.callApi(
183
183
  '/cloud/v2/deviceManaged/bypassV2',
184
184
  'post',
185
185
  body,
@@ -229,7 +229,7 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
229
229
  }
230
230
  };
231
231
 
232
- const [response] = await Helpers.callApi(
232
+ const [response] = await this.callApi(
233
233
  '/cloud/v1/deviceManaged/bypass',
234
234
  'post',
235
235
  body,
@@ -258,7 +258,7 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
258
258
  }
259
259
  };
260
260
 
261
- const [response] = await Helpers.callApi(
261
+ const [response] = await this.callApi(
262
262
  '/cloud/v1/deviceManaged/bypass',
263
263
  'post',
264
264
  body,