tsvesync 1.0.15 → 1.0.16

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.
package/README.md CHANGED
@@ -166,7 +166,7 @@ for (const device of manager.devices) {
166
166
  const fan = manager.devices.find(d => d.deviceType === 'Core300S');
167
167
  if (fan) {
168
168
  await fan.setMode('auto'); // Available modes: auto, sleep, manual
169
- await fan.setSpeed(2); // Speed range depends on model
169
+ await fan.changeFanSpeed(2); // Speed range depends on model
170
170
  }
171
171
 
172
172
  // Control an outlet
@@ -52,7 +52,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
52
52
  };
53
53
  let url;
54
54
  if (this.deviceType === 'wifi-switch-1.3') {
55
- url = `/v1/device/${this.deviceType}-${this.cid}/detail`;
55
+ url = `/v1/device/wifi-switch-1.3-${this.cid}/detail`;
56
56
  }
57
57
  else if (this.deviceType.startsWith('ESO15')) {
58
58
  url = '/outdoorsocket15a/v1/device/devicedetail';
@@ -67,13 +67,45 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
67
67
  url = '/v1/device/devicedetail';
68
68
  }
69
69
  const [response] = await helpers_1.Helpers.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', this.deviceType === 'wifi-switch-1.3' ? null : body, helpers_1.Helpers.reqHeaders(this.manager));
70
- if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
71
- this.details = response.result;
72
- this.deviceStatus = response.result.deviceStatus;
70
+ if (!response) {
71
+ logger_1.logger.debug(`[${this.deviceName}] No response received from API`);
72
+ return;
73
+ }
74
+ // Handle error responses
75
+ if (response.error) {
76
+ logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
77
+ return;
78
+ }
79
+ // Handle successful responses
80
+ if (response.code === 0) {
81
+ this.details = response;
82
+ // Handle outdoor plugs with subdevices
83
+ if (response.subDevices) {
84
+ const subDevice = response.subDevices.find((dev) => dev.subDeviceName === this.deviceName);
85
+ if (subDevice) {
86
+ this.deviceStatus = subDevice.subDeviceStatus;
87
+ logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved subdevice status: ${this.deviceStatus}`);
88
+ return;
89
+ }
90
+ }
91
+ // Handle regular devices
92
+ if (response.deviceStatus !== undefined) {
93
+ this.deviceStatus = response.deviceStatus;
94
+ }
95
+ else if (response.status !== undefined) {
96
+ this.deviceStatus = response.status;
97
+ }
98
+ else if (response.power !== undefined) {
99
+ this.deviceStatus = response.power === 'on' ? 'on' : 'off';
100
+ }
101
+ else {
102
+ logger_1.logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
103
+ return;
104
+ }
73
105
  logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
74
106
  }
75
107
  else {
76
- logger_1.logger.error(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
108
+ logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
77
109
  }
78
110
  }
79
111
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
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",
@@ -66,7 +66,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
66
66
 
67
67
  let url: string;
68
68
  if (this.deviceType === 'wifi-switch-1.3') {
69
- url = `/v1/device/${this.deviceType}-${this.cid}/detail`;
69
+ url = `/v1/device/wifi-switch-1.3-${this.cid}/detail`;
70
70
  } else if (this.deviceType.startsWith('ESO15')) {
71
71
  url = '/outdoorsocket15a/v1/device/devicedetail';
72
72
  } else if (this.deviceType.startsWith('ESW15')) {
@@ -84,12 +84,47 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
84
84
  Helpers.reqHeaders(this.manager)
85
85
  );
86
86
 
87
- if (response?.code === 0) {
88
- this.details = response.result;
89
- this.deviceStatus = response.result.deviceStatus;
87
+ if (!response) {
88
+ logger.debug(`[${this.deviceName}] No response received from API`);
89
+ return;
90
+ }
91
+
92
+ // Handle error responses
93
+ if (response.error) {
94
+ logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
95
+ return;
96
+ }
97
+
98
+ // Handle successful responses
99
+ if (response.code === 0) {
100
+ this.details = response;
101
+
102
+ // Handle outdoor plugs with subdevices
103
+ if (response.subDevices) {
104
+ const subDevice = response.subDevices.find(
105
+ (dev: any) => dev.subDeviceName === this.deviceName
106
+ );
107
+ if (subDevice) {
108
+ this.deviceStatus = subDevice.subDeviceStatus;
109
+ logger.debug(`[${this.deviceName}] Successfully retrieved subdevice status: ${this.deviceStatus}`);
110
+ return;
111
+ }
112
+ }
113
+
114
+ // Handle regular devices
115
+ if (response.deviceStatus !== undefined) {
116
+ this.deviceStatus = response.deviceStatus;
117
+ } else if (response.status !== undefined) {
118
+ this.deviceStatus = response.status;
119
+ } else if (response.power !== undefined) {
120
+ this.deviceStatus = response.power === 'on' ? 'on' : 'off';
121
+ } else {
122
+ logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
123
+ return;
124
+ }
90
125
  logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
91
126
  } else {
92
- logger.error(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
127
+ logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
93
128
  }
94
129
  }
95
130