tsvesync 1.0.20 → 1.0.22

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.
@@ -291,37 +291,49 @@ class VeSync {
291
291
  * Process devices from API response
292
292
  */
293
293
  processDevices(deviceList) {
294
- // Clear existing devices
295
- for (const category of Object.keys(this._devList)) {
296
- this._devList[category].length = 0;
297
- }
298
- // Process each device
299
- deviceList.forEach(dev => {
300
- const [category, device] = objectFactory(dev, this);
301
- // Handle outdoor plug sub-devices
302
- if (dev.deviceType === 'ESO15-TB' && dev.subDevices) {
303
- dev.subDevices.forEach((subDev) => {
304
- const subDeviceDetails = {
305
- ...dev,
306
- deviceName: subDev.subDeviceName,
307
- deviceStatus: subDev.subDeviceStatus,
308
- subDeviceNo: subDev.subDeviceNo,
309
- isSubDevice: true,
310
- parentCid: dev.cid,
311
- cid: `${dev.cid}_${subDev.subDeviceNo}`
312
- };
313
- const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
314
- if (subDevice && subCategory in this._devList) {
315
- this._devList[subCategory].push(subDevice);
316
- }
317
- });
294
+ try {
295
+ // Clear existing devices
296
+ for (const category of Object.keys(this._devList)) {
297
+ this._devList[category].length = 0;
318
298
  }
319
- else if (device && category in this._devList) {
320
- this._devList[category].push(device);
299
+ if (!deviceList || deviceList.length === 0) {
300
+ logger_1.logger.warn('No devices found in API response');
301
+ return false;
321
302
  }
322
- });
323
- // Update device list reference
324
- this.devices = Object.values(this._devList).flat();
303
+ // Process each device
304
+ deviceList.forEach(dev => {
305
+ const [category, device] = objectFactory(dev, this);
306
+ // 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
+ });
323
+ }
324
+ else if (device && category in this._devList) {
325
+ this._devList[category].push(device);
326
+ }
327
+ });
328
+ // Update device list reference
329
+ this.devices = Object.values(this._devList).flat();
330
+ // Return true if we processed at least one device successfully
331
+ return this.devices.length > 0;
332
+ }
333
+ catch (error) {
334
+ logger_1.logger.error('Error processing devices:', error);
335
+ return false;
336
+ }
325
337
  }
326
338
  /**
327
339
  * Get list of VeSync devices
@@ -333,12 +345,12 @@ class VeSync {
333
345
  return false;
334
346
  }
335
347
  this._inProcess = true;
336
- let procReturn = false;
348
+ let success = false;
337
349
  try {
338
350
  const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/devices', 'post', helpers_1.Helpers.reqBody(this, 'devicelist'), helpers_1.Helpers.reqHeaders(this));
339
351
  if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.list) {
340
352
  const deviceList = response.result.list;
341
- this.processDevices(deviceList);
353
+ success = this.processDevices(deviceList);
342
354
  // Log device discovery results
343
355
  logger_1.logger.debug('\n=== Device Discovery Summary ===');
344
356
  logger_1.logger.debug(`Total devices processed: ${deviceList.length}`);
@@ -376,7 +388,7 @@ class VeSync {
376
388
  logger_1.logger.error('Unable to get device list:', error);
377
389
  }
378
390
  this._inProcess = false;
379
- return procReturn;
391
+ return success;
380
392
  }
381
393
  /**
382
394
  * Login to VeSync server
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
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
@@ -358,40 +358,53 @@ export class VeSync {
358
358
  /**
359
359
  * Process devices from API response
360
360
  */
361
- private processDevices(deviceList: any[]): void {
362
- // Clear existing devices
363
- for (const category of Object.keys(this._devList)) {
364
- this._devList[category].length = 0;
365
- }
361
+ private processDevices(deviceList: any[]): boolean {
362
+ try {
363
+ // Clear existing devices
364
+ for (const category of Object.keys(this._devList)) {
365
+ this._devList[category].length = 0;
366
+ }
366
367
 
367
- // Process each device
368
- deviceList.forEach(dev => {
369
- const [category, device] = objectFactory(dev, this);
370
-
371
- // Handle outdoor plug sub-devices
372
- if (dev.deviceType === 'ESO15-TB' && dev.subDevices) {
373
- dev.subDevices.forEach((subDev: any) => {
374
- const subDeviceDetails = {
375
- ...dev,
376
- deviceName: subDev.subDeviceName,
377
- deviceStatus: subDev.subDeviceStatus,
378
- subDeviceNo: subDev.subDeviceNo,
379
- isSubDevice: true,
380
- parentCid: dev.cid,
381
- cid: `${dev.cid}_${subDev.subDeviceNo}`
382
- };
383
- const [subCategory, subDevice] = objectFactory(subDeviceDetails, this);
384
- if (subDevice && subCategory in this._devList) {
385
- this._devList[subCategory].push(subDevice);
386
- }
387
- });
388
- } else if (device && category in this._devList) {
389
- this._devList[category].push(device);
368
+ if (!deviceList || deviceList.length === 0) {
369
+ logger.warn('No devices found in API response');
370
+ return false;
390
371
  }
391
- });
392
372
 
393
- // Update device list reference
394
- this.devices = Object.values(this._devList).flat();
373
+ // Process each device
374
+ deviceList.forEach(dev => {
375
+ const [category, device] = objectFactory(dev, this);
376
+
377
+ // 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
+ });
394
+ } else if (device && category in this._devList) {
395
+ this._devList[category].push(device);
396
+ }
397
+ });
398
+
399
+ // Update device list reference
400
+ this.devices = Object.values(this._devList).flat();
401
+
402
+ // Return true if we processed at least one device successfully
403
+ return this.devices.length > 0;
404
+ } catch (error) {
405
+ logger.error('Error processing devices:', error);
406
+ return false;
407
+ }
395
408
  }
396
409
 
397
410
  /**
@@ -404,7 +417,7 @@ export class VeSync {
404
417
  }
405
418
 
406
419
  this._inProcess = true;
407
- let procReturn = false;
420
+ let success = false;
408
421
 
409
422
  try {
410
423
  const [response] = await Helpers.callApi(
@@ -416,7 +429,7 @@ export class VeSync {
416
429
 
417
430
  if (response?.result?.list) {
418
431
  const deviceList = response.result.list;
419
- this.processDevices(deviceList);
432
+ success = this.processDevices(deviceList);
420
433
 
421
434
  // Log device discovery results
422
435
  logger.debug('\n=== Device Discovery Summary ===');
@@ -458,7 +471,7 @@ export class VeSync {
458
471
  }
459
472
 
460
473
  this._inProcess = false;
461
- return procReturn;
474
+ return success;
462
475
  }
463
476
 
464
477
  /**