tsvesync 1.0.81 → 1.0.82

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.
@@ -55,12 +55,24 @@ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
55
55
  };
56
56
  return true;
57
57
  }
58
+ // Log additional details on failure
59
+ if (!success && (response === null || response === void 0 ? void 0 : response.code)) {
60
+ logger_1.logger.error(`${this.deviceName}: getDetails failed with code ${response.code} - ${response.msg || 'Unknown error'}`);
61
+ if (response.traceId) {
62
+ logger_1.logger.error(`${this.deviceName}: TraceId for debugging: ${response.traceId}`);
63
+ }
64
+ }
58
65
  return false;
59
66
  }
60
67
  /**
61
68
  * Turn device on
62
69
  */
63
70
  async turnOn() {
71
+ // Check if device is already on
72
+ if (this.deviceStatus === 'on') {
73
+ logger_1.logger.debug(`Device ${this.deviceName} is already on`);
74
+ return false; // Return false to match pyvesync behavior
75
+ }
64
76
  logger_1.logger.info(`Turning on device: ${this.deviceName}`);
65
77
  const [response, status] = await this.callApi('/131airPurifier/v1/device/deviceStatus', 'put', {
66
78
  acceptLanguage: 'en',
@@ -78,7 +90,11 @@ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
78
90
  'tz': this.manager.timeZone
79
91
  });
80
92
  const success = this.checkResponse([response, status], 'turnOn');
81
- if (!success) {
93
+ if (success) {
94
+ // Update device status immediately
95
+ this.deviceStatus = 'on';
96
+ }
97
+ else {
82
98
  logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
83
99
  }
84
100
  return success;
@@ -87,6 +103,11 @@ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
87
103
  * Turn device off
88
104
  */
89
105
  async turnOff() {
106
+ // Check if device is already off
107
+ if (this.deviceStatus !== 'on') {
108
+ logger_1.logger.debug(`Device ${this.deviceName} is already off`);
109
+ return true;
110
+ }
90
111
  logger_1.logger.info(`Turning off device: ${this.deviceName}`);
91
112
  const [response, status] = await this.callApi('/131airPurifier/v1/device/deviceStatus', 'put', {
92
113
  acceptLanguage: 'en',
@@ -104,7 +125,11 @@ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
104
125
  'tz': this.manager.timeZone
105
126
  });
106
127
  const success = this.checkResponse([response, status], 'turnOff');
107
- if (!success) {
128
+ if (success) {
129
+ // Update device status immediately
130
+ this.deviceStatus = 'off';
131
+ }
132
+ else {
108
133
  logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
109
134
  }
110
135
  return success;
@@ -114,19 +139,10 @@ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
114
139
  */
115
140
  async changeFanSpeed(speed) {
116
141
  logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
117
- // Get fresh device details first to ensure we have the current mode
118
- await this.getDetails();
119
142
  // Check if device is in manual mode
120
143
  if (this.details.mode !== 'manual') {
121
- logger_1.logger.debug(`${this.deviceName} not in manual mode (current mode: ${this.details.mode}), switching to manual mode first`);
122
- // Switch to manual mode first
123
- const modeSuccess = await this.manualMode();
124
- if (!modeSuccess) {
125
- logger_1.logger.error(`Failed to switch to manual mode for device: ${this.deviceName}`);
126
- return false;
127
- }
128
- // Wait a bit for the mode change to take effect
129
- await new Promise(resolve => setTimeout(resolve, 1000));
144
+ logger_1.logger.error(`${this.deviceName}: Cannot change fan speed - device is in ${this.details.mode} mode, manual mode required`);
145
+ return false;
130
146
  }
131
147
  // Validate speed for LV series (1-3)
132
148
  if (speed < 1 || speed > 3) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
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",
@@ -63,6 +63,14 @@ export class VeSyncAir131 extends VeSyncFan {
63
63
  };
64
64
  return true;
65
65
  }
66
+
67
+ // Log additional details on failure
68
+ if (!success && response?.code) {
69
+ logger.error(`${this.deviceName}: getDetails failed with code ${response.code} - ${response.msg || 'Unknown error'}`);
70
+ if (response.traceId) {
71
+ logger.error(`${this.deviceName}: TraceId for debugging: ${response.traceId}`);
72
+ }
73
+ }
66
74
  return false;
67
75
  }
68
76
 
@@ -70,6 +78,12 @@ export class VeSyncAir131 extends VeSyncFan {
70
78
  * Turn device on
71
79
  */
72
80
  async turnOn(): Promise<boolean> {
81
+ // Check if device is already on
82
+ if (this.deviceStatus === 'on') {
83
+ logger.debug(`Device ${this.deviceName} is already on`);
84
+ return false; // Return false to match pyvesync behavior
85
+ }
86
+
73
87
  logger.info(`Turning on device: ${this.deviceName}`);
74
88
 
75
89
  const [response, status] = await this.callApi(
@@ -94,7 +108,10 @@ export class VeSyncAir131 extends VeSyncFan {
94
108
  );
95
109
 
96
110
  const success = this.checkResponse([response, status], 'turnOn');
97
- if (!success) {
111
+ if (success) {
112
+ // Update device status immediately
113
+ this.deviceStatus = 'on';
114
+ } else {
98
115
  logger.error(`Failed to turn on device: ${this.deviceName}`);
99
116
  }
100
117
  return success;
@@ -104,6 +121,12 @@ export class VeSyncAir131 extends VeSyncFan {
104
121
  * Turn device off
105
122
  */
106
123
  async turnOff(): Promise<boolean> {
124
+ // Check if device is already off
125
+ if (this.deviceStatus !== 'on') {
126
+ logger.debug(`Device ${this.deviceName} is already off`);
127
+ return true;
128
+ }
129
+
107
130
  logger.info(`Turning off device: ${this.deviceName}`);
108
131
 
109
132
  const [response, status] = await this.callApi(
@@ -128,7 +151,10 @@ export class VeSyncAir131 extends VeSyncFan {
128
151
  );
129
152
 
130
153
  const success = this.checkResponse([response, status], 'turnOff');
131
- if (!success) {
154
+ if (success) {
155
+ // Update device status immediately
156
+ this.deviceStatus = 'off';
157
+ } else {
132
158
  logger.error(`Failed to turn off device: ${this.deviceName}`);
133
159
  }
134
160
  return success;
@@ -140,22 +166,10 @@ export class VeSyncAir131 extends VeSyncFan {
140
166
  async changeFanSpeed(speed: number): Promise<boolean> {
141
167
  logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
142
168
 
143
- // Get fresh device details first to ensure we have the current mode
144
- await this.getDetails();
145
-
146
169
  // Check if device is in manual mode
147
170
  if (this.details.mode !== 'manual') {
148
- logger.debug(`${this.deviceName} not in manual mode (current mode: ${this.details.mode}), switching to manual mode first`);
149
-
150
- // Switch to manual mode first
151
- const modeSuccess = await this.manualMode();
152
- if (!modeSuccess) {
153
- logger.error(`Failed to switch to manual mode for device: ${this.deviceName}`);
154
- return false;
155
- }
156
-
157
- // Wait a bit for the mode change to take effect
158
- await new Promise(resolve => setTimeout(resolve, 1000));
171
+ logger.error(`${this.deviceName}: Cannot change fan speed - device is in ${this.details.mode} mode, manual mode required`);
172
+ return false;
159
173
  }
160
174
 
161
175
  // Validate speed for LV series (1-3)