tsvesync 1.0.22 → 1.0.23

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.
@@ -85,23 +85,18 @@ function objectFactory(details, manager) {
85
85
  // Add category to device details
86
86
  details.deviceCategory = category;
87
87
  // Handle outdoor plug sub-devices
88
- if (deviceType === 'ESO15-TB' && details.subDevices) {
88
+ if (deviceType === 'ESO15-TB' && details.subDeviceNo) {
89
89
  const devices = [];
90
90
  // Create a device instance for each sub-device
91
- details.subDevices.forEach((subDevice) => {
92
- const subDeviceDetails = {
93
- ...details,
94
- deviceName: subDevice.subDeviceName,
95
- deviceStatus: subDevice.subDeviceStatus,
96
- subDeviceNo: subDevice.subDeviceNo,
97
- isSubDevice: true,
98
- parentCid: details.cid,
99
- // Generate a unique CID for the sub-device
100
- cid: `${details.cid}_${subDevice.subDeviceNo}`
101
- };
102
- const device = new DeviceClass(subDeviceDetails, manager);
103
- devices.push([category, device]);
104
- });
91
+ const subDeviceDetails = {
92
+ ...details,
93
+ deviceName: details.deviceName,
94
+ deviceStatus: details.deviceStatus,
95
+ subDeviceNo: details.subDeviceNo,
96
+ isSubDevice: true
97
+ };
98
+ const device = new DeviceClass(subDeviceDetails, manager);
99
+ devices.push([category, device]);
105
100
  // Return array of sub-devices
106
101
  return devices[0]; // Return first device, manager will handle adding all devices
107
102
  }
@@ -304,22 +299,18 @@ class VeSync {
304
299
  deviceList.forEach(dev => {
305
300
  const [category, device] = objectFactory(dev, this);
306
301
  // Handle outdoor plug sub-devices
307
- if (dev.deviceType === 'ESO15-TB' && dev.subDevices) {
308
- dev.subDevices.forEach((subDev) => {
309
- const subDeviceDetails = {
310
- ...dev,
311
- deviceName: subDev.subDeviceName,
312
- deviceStatus: subDev.subDeviceStatus,
313
- subDeviceNo: subDev.subDeviceNo,
314
- isSubDevice: true,
315
- parentCid: dev.cid,
316
- cid: `${dev.cid}_${subDev.subDeviceNo}`
317
- };
318
- const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
319
- if (subDevice && subCategory in this._devList) {
320
- this._devList[subCategory].push(subDevice);
321
- }
322
- });
302
+ if (dev.deviceType === 'ESO15-TB' && dev.subDeviceNo) {
303
+ const subDeviceDetails = {
304
+ ...dev,
305
+ deviceName: dev.deviceName,
306
+ deviceStatus: dev.deviceStatus,
307
+ subDeviceNo: dev.subDeviceNo,
308
+ isSubDevice: true,
309
+ };
310
+ const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
311
+ if (subDevice && subCategory in this._devList) {
312
+ this._devList[subCategory].push(subDevice);
313
+ }
323
314
  }
324
315
  else if (device && category in this._devList) {
325
316
  this._devList[category].push(device);
@@ -57,9 +57,8 @@ export declare class VeSyncOutlet15A extends VeSyncOutlet {
57
57
  * VeSync Outdoor Plug
58
58
  */
59
59
  export declare class VeSyncOutdoorPlug extends VeSyncOutlet {
60
- protected subDeviceNo?: number;
61
- protected isSubDevice: boolean;
62
- protected parentCid?: string;
60
+ subDeviceNo?: number;
61
+ isSubDevice: boolean;
63
62
  constructor(details: Record<string, any>, manager: VeSync);
64
63
  /**
65
64
  * Turn outlet on
@@ -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'),
@@ -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'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
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",
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
  }
@@ -254,25 +254,19 @@ export class VeSyncOutlet15A extends VeSyncOutlet {
254
254
  * VeSync Outdoor Plug
255
255
  */
256
256
  export class VeSyncOutdoorPlug extends VeSyncOutlet {
257
- protected subDeviceNo?: number;
258
- protected isSubDevice: boolean;
259
- protected parentCid?: string;
257
+ public subDeviceNo?: number;
258
+ public isSubDevice: boolean;
260
259
 
261
260
  constructor(details: Record<string, any>, manager: VeSync) {
262
261
  super(details, manager);
263
262
  this.isSubDevice = details.isSubDevice || false;
264
263
  this.subDeviceNo = details.subDeviceNo;
265
- this.parentCid = details.parentCid;
266
264
  }
267
265
 
268
266
  /**
269
267
  * Turn outlet on
270
268
  */
271
269
  async turnOn(): Promise<boolean> {
272
- if (!this.isSubDevice) {
273
- logger.error(`[${this.deviceName}] Cannot control parent device directly`);
274
- return false;
275
- }
276
270
 
277
271
  logger.debug(`[${this.deviceName}] Turning outlet on`);
278
272
  const body = {
@@ -302,10 +296,6 @@ export class VeSyncOutdoorPlug extends VeSyncOutlet {
302
296
  * Turn outlet off
303
297
  */
304
298
  async turnOff(): Promise<boolean> {
305
- if (!this.isSubDevice) {
306
- logger.error(`[${this.deviceName}] Cannot control parent device directly`);
307
- return false;
308
- }
309
299
 
310
300
  logger.debug(`[${this.deviceName}] Turning outlet off`);
311
301
  const body = {