tsvesync 1.0.23 → 1.0.25
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 +12 -0
- package/dist/lib/helpers.d.ts +1 -1
- package/dist/lib/helpers.js +13 -2
- package/dist/lib/vesync.d.ts +4 -0
- package/dist/lib/vesync.js +9 -3
- package/dist/lib/vesyncBaseDevice.d.ts +4 -0
- package/dist/lib/vesyncBaseDevice.js +7 -0
- package/dist/lib/vesyncBulb.js +5 -5
- package/dist/lib/vesyncBulbImpl.js +6 -6
- package/dist/lib/vesyncFanImpl.js +25 -25
- package/dist/lib/vesyncOutlet.js +10 -10
- package/dist/lib/vesyncOutletImpl.js +10 -10
- package/dist/lib/vesyncSwitchImpl.js +14 -14
- package/package.json +1 -1
- package/src/lib/helpers.ts +16 -2
- package/src/lib/vesync.ts +18 -3
- package/src/lib/vesyncBaseDevice.ts +13 -0
- package/src/lib/vesyncBulb.ts +5 -5
- package/src/lib/vesyncBulbImpl.ts +6 -6
- package/src/lib/vesyncFanImpl.ts +25 -25
- package/src/lib/vesyncOutlet.ts +10 -10
- package/src/lib/vesyncOutletImpl.ts +10 -12
- package/src/lib/vesyncSwitchImpl.ts +14 -14
package/README.md
CHANGED
|
@@ -130,6 +130,18 @@ A TypeScript library for interacting with VeSync smart home devices. This librar
|
|
|
130
130
|
- Modes: Normal, Auto, Advanced Sleep, Turbo
|
|
131
131
|
- Fan speeds: 1-12
|
|
132
132
|
|
|
133
|
+
### Wall Switches
|
|
134
|
+
- ESWL01
|
|
135
|
+
- Basic on/off control
|
|
136
|
+
- Status monitoring
|
|
137
|
+
- ESWL03
|
|
138
|
+
- Basic on/off control
|
|
139
|
+
- Status monitoring
|
|
140
|
+
- ESWD16
|
|
141
|
+
- Dimming control
|
|
142
|
+
- RGB indicator light control
|
|
143
|
+
- Status monitoring
|
|
144
|
+
|
|
133
145
|
## Installation
|
|
134
146
|
|
|
135
147
|
```bash
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export declare class Helpers {
|
|
|
68
68
|
/**
|
|
69
69
|
* Call VeSync API
|
|
70
70
|
*/
|
|
71
|
-
static callApi(endpoint: string, method: string, data
|
|
71
|
+
static callApi(endpoint: string, method: string, data: any | undefined, headers: Record<string, string> | undefined, manager: VeSync): Promise<[any, number]>;
|
|
72
72
|
/**
|
|
73
73
|
* Calculate hex value from energy response
|
|
74
74
|
*/
|
package/dist/lib/helpers.js
CHANGED
|
@@ -162,7 +162,7 @@ class Helpers {
|
|
|
162
162
|
/**
|
|
163
163
|
* Call VeSync API
|
|
164
164
|
*/
|
|
165
|
-
static async callApi(endpoint, method, data = null, headers = {}) {
|
|
165
|
+
static async callApi(endpoint, method, data = null, headers = {}, manager) {
|
|
166
166
|
try {
|
|
167
167
|
const url = _apiBaseUrl + endpoint;
|
|
168
168
|
const response = await (0, axios_1.default)({
|
|
@@ -176,7 +176,18 @@ class Helpers {
|
|
|
176
176
|
}
|
|
177
177
|
catch (error) {
|
|
178
178
|
if (error.response) {
|
|
179
|
-
|
|
179
|
+
const responseData = error.response.data;
|
|
180
|
+
// Check for token expiration
|
|
181
|
+
if ((responseData === null || responseData === void 0 ? void 0 : responseData.code) === 4001004 || (responseData === null || responseData === void 0 ? void 0 : responseData.msg) === "token expired") {
|
|
182
|
+
logger_1.logger.debug('Token expired, attempting to re-login...');
|
|
183
|
+
// Re-login
|
|
184
|
+
if (await manager.login()) {
|
|
185
|
+
// Retry the original request
|
|
186
|
+
logger_1.logger.debug('Re-login successful, retrying original request...');
|
|
187
|
+
return await this.callApi(endpoint, method, data, headers, manager);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return [responseData, error.response.status];
|
|
180
191
|
}
|
|
181
192
|
logger_1.logger.error('API call failed:', error.message);
|
|
182
193
|
return [null, 0];
|
package/dist/lib/vesync.d.ts
CHANGED
|
@@ -94,4 +94,8 @@ export declare class VeSync {
|
|
|
94
94
|
* Create device instance from details
|
|
95
95
|
*/
|
|
96
96
|
createDevice(details: Record<string, any>): VeSyncBaseDevice | null;
|
|
97
|
+
/**
|
|
98
|
+
* Call API with authentication
|
|
99
|
+
*/
|
|
100
|
+
protected callApi(endpoint: string, method: string, data?: any, headers?: Record<string, string>): Promise<[any, number]>;
|
|
97
101
|
}
|
package/dist/lib/vesync.js
CHANGED
|
@@ -111,7 +111,7 @@ function objectFactory(details, manager) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
|
-
logger_1.logger.
|
|
114
|
+
logger_1.logger.debug(`No device class found for type: ${deviceType}`);
|
|
115
115
|
return [category, null];
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -338,7 +338,7 @@ class VeSync {
|
|
|
338
338
|
this._inProcess = true;
|
|
339
339
|
let success = false;
|
|
340
340
|
try {
|
|
341
|
-
const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/devices', 'post', helpers_1.Helpers.reqBody(this, 'devicelist'), helpers_1.Helpers.reqHeaders(this));
|
|
341
|
+
const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/devices', 'post', helpers_1.Helpers.reqBody(this, 'devicelist'), helpers_1.Helpers.reqHeaders(this), this);
|
|
342
342
|
if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.list) {
|
|
343
343
|
const deviceList = response.result.list;
|
|
344
344
|
success = this.processDevices(deviceList);
|
|
@@ -392,7 +392,7 @@ class VeSync {
|
|
|
392
392
|
body
|
|
393
393
|
});
|
|
394
394
|
try {
|
|
395
|
-
const [response, status] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body);
|
|
395
|
+
const [response, status] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body, {}, this);
|
|
396
396
|
logger_1.logger.debug('Login response:', { status, response });
|
|
397
397
|
if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.token) {
|
|
398
398
|
this.token = response.result.token;
|
|
@@ -451,5 +451,11 @@ class VeSync {
|
|
|
451
451
|
}
|
|
452
452
|
return null;
|
|
453
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* Call API with authentication
|
|
456
|
+
*/
|
|
457
|
+
async callApi(endpoint, method, data = null, headers = {}) {
|
|
458
|
+
return await helpers_1.Helpers.callApi(endpoint, method, data, headers, this);
|
|
459
|
+
}
|
|
454
460
|
}
|
|
455
461
|
exports.VeSync = VeSync;
|
|
@@ -40,4 +40,8 @@ export declare abstract class VeSyncBaseDevice {
|
|
|
40
40
|
* Update device details
|
|
41
41
|
*/
|
|
42
42
|
update(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Call API with proper headers
|
|
45
|
+
*/
|
|
46
|
+
protected callApi(endpoint: string, method: string, data?: any, headers?: Record<string, string>): Promise<[any, number]>;
|
|
43
47
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VeSyncBaseDevice = void 0;
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
8
9
|
class VeSyncBaseDevice {
|
|
9
10
|
constructor(details, manager) {
|
|
10
11
|
this.config = {};
|
|
@@ -85,5 +86,11 @@ class VeSyncBaseDevice {
|
|
|
85
86
|
async update() {
|
|
86
87
|
await this.getDetails();
|
|
87
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Call API with proper headers
|
|
91
|
+
*/
|
|
92
|
+
async callApi(endpoint, method, data = null, headers = {}) {
|
|
93
|
+
return await helpers_1.Helpers.callApi(endpoint, method, data, headers, this.manager);
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
exports.VeSyncBaseDevice = VeSyncBaseDevice;
|
package/dist/lib/vesyncBulb.js
CHANGED
|
@@ -74,7 +74,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
74
74
|
getLightStatus: 'get'
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
const [response] = await
|
|
77
|
+
const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
78
78
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
79
79
|
this.deviceStatus = response.result.enabled ? 'on' : 'off';
|
|
80
80
|
this.brightness = response.result.brightness || this.brightness;
|
|
@@ -95,7 +95,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
95
95
|
this.colorValue = response.result.value || this.colorValue;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
logger_1.logger.
|
|
98
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
@@ -138,7 +138,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
const [response] = await
|
|
141
|
+
const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
142
142
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
143
143
|
this.deviceStatus = 'on';
|
|
144
144
|
logger_1.logger.info(`[${this.deviceName}] Successfully turned bulb on`);
|
|
@@ -176,7 +176,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
|
-
const [response] = await
|
|
179
|
+
const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
180
180
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
181
181
|
this.deviceStatus = 'off';
|
|
182
182
|
logger_1.logger.info(`[${this.deviceName}] Successfully turned bulb off`);
|
|
@@ -223,7 +223,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
const [response] = await
|
|
226
|
+
const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
227
227
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
228
228
|
this.brightness = brightness;
|
|
229
229
|
logger_1.logger.info(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
|
|
@@ -43,7 +43,7 @@ class VeSyncBulbESL100CW extends vesyncBulb_1.VeSyncBulb {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
const [response] = await
|
|
46
|
+
const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
47
47
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
48
48
|
this.colorTemp = colorTemp;
|
|
49
49
|
logger_1.logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
@@ -85,7 +85,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
85
85
|
source: 'APP'
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
const [response] = await
|
|
88
|
+
const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
89
89
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
90
90
|
this.colorTemp = colorTemp;
|
|
91
91
|
logger_1.logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
@@ -118,7 +118,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
118
118
|
source: 'APP'
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
const [response] = await
|
|
121
|
+
const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
122
122
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
123
123
|
this.colorHue = hue;
|
|
124
124
|
this.colorSaturation = saturation;
|
|
@@ -149,7 +149,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
149
149
|
source: 'APP'
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
-
const [response] = await
|
|
152
|
+
const [response] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
153
153
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
154
154
|
this.colorMode = 'white';
|
|
155
155
|
logger_1.logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
@@ -189,7 +189,7 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
-
const [response] = await
|
|
192
|
+
const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
193
193
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
194
194
|
this.rgbValues = { red, green, blue };
|
|
195
195
|
logger_1.logger.info(`[${this.deviceName}] Successfully set RGB color`);
|
|
@@ -210,7 +210,7 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
|
-
const [response] = await
|
|
213
|
+
const [response] = await this.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
214
214
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
215
215
|
this.colorMode = 'white';
|
|
216
216
|
logger_1.logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
@@ -25,7 +25,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
25
25
|
async getDetails() {
|
|
26
26
|
var _a;
|
|
27
27
|
logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
28
|
-
const [response, status] = await
|
|
28
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
29
29
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
30
30
|
cid: this.cid,
|
|
31
31
|
configModule: this.configModule,
|
|
@@ -65,7 +65,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
65
65
|
*/
|
|
66
66
|
async turnOn() {
|
|
67
67
|
logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
|
|
68
|
-
const [response, status] = await
|
|
68
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
69
69
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
70
70
|
cid: this.cid,
|
|
71
71
|
configModule: this.configModule,
|
|
@@ -89,7 +89,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
89
89
|
*/
|
|
90
90
|
async turnOff() {
|
|
91
91
|
logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
|
|
92
|
-
const [response, status] = await
|
|
92
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
93
93
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
94
94
|
cid: this.cid,
|
|
95
95
|
configModule: this.configModule,
|
|
@@ -118,7 +118,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
118
118
|
throw new Error(error);
|
|
119
119
|
}
|
|
120
120
|
logger_1.logger.debug(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
121
|
-
const [response, status] = await
|
|
121
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
122
122
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
123
123
|
cid: this.cid,
|
|
124
124
|
configModule: this.configModule,
|
|
@@ -149,7 +149,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
149
149
|
throw new Error(error);
|
|
150
150
|
}
|
|
151
151
|
logger_1.logger.debug(`Setting mode to ${mode} for device: ${this.deviceName}`);
|
|
152
|
-
const [response, status] = await
|
|
152
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
153
153
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
154
154
|
cid: this.cid,
|
|
155
155
|
configModule: this.configModule,
|
|
@@ -177,7 +177,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
177
177
|
throw new Error(error);
|
|
178
178
|
}
|
|
179
179
|
logger_1.logger.debug(`Setting display to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
|
|
180
|
-
const [response, status] = await
|
|
180
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
181
181
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
182
182
|
cid: this.cid,
|
|
183
183
|
configModule: this.configModule,
|
|
@@ -205,7 +205,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
205
205
|
throw new Error(error);
|
|
206
206
|
}
|
|
207
207
|
logger_1.logger.debug(`Setting child lock to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
|
|
208
|
-
const [response, status] = await
|
|
208
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
209
209
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
210
210
|
cid: this.cid,
|
|
211
211
|
configModule: this.configModule,
|
|
@@ -233,7 +233,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
233
233
|
throw new Error(error);
|
|
234
234
|
}
|
|
235
235
|
logger_1.logger.debug(`Setting timer to ${hours} hours for device: ${this.deviceName}`);
|
|
236
|
-
const [response, status] = await
|
|
236
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
237
237
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
238
238
|
cid: this.cid,
|
|
239
239
|
configModule: this.configModule,
|
|
@@ -262,7 +262,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
262
262
|
throw new Error(error);
|
|
263
263
|
}
|
|
264
264
|
logger_1.logger.debug(`Clearing timer for device: ${this.deviceName}`);
|
|
265
|
-
const [response, status] = await
|
|
265
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
266
266
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
267
267
|
cid: this.cid,
|
|
268
268
|
configModule: this.configModule,
|
|
@@ -283,7 +283,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
283
283
|
*/
|
|
284
284
|
async automaticStopOn() {
|
|
285
285
|
logger_1.logger.debug(`Setting automatic stop on for device: ${this.deviceName}`);
|
|
286
|
-
const [response, status] = await
|
|
286
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
287
287
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
288
288
|
cid: this.cid,
|
|
289
289
|
configModule: this.configModule,
|
|
@@ -306,7 +306,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
306
306
|
*/
|
|
307
307
|
async automaticStopOff() {
|
|
308
308
|
logger_1.logger.debug(`Setting automatic stop off for device: ${this.deviceName}`);
|
|
309
|
-
const [response, status] = await
|
|
309
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
310
310
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
311
311
|
cid: this.cid,
|
|
312
312
|
configModule: this.configModule,
|
|
@@ -399,7 +399,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
399
399
|
*/
|
|
400
400
|
async getDetails() {
|
|
401
401
|
logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
402
|
-
const [response, status] = await
|
|
402
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
403
403
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
404
404
|
cid: this.cid,
|
|
405
405
|
configModule: this.configModule,
|
|
@@ -423,7 +423,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
423
423
|
*/
|
|
424
424
|
async turnOn() {
|
|
425
425
|
logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
|
|
426
|
-
const [response, status] = await
|
|
426
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
427
427
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
428
428
|
cid: this.cid,
|
|
429
429
|
configModule: this.configModule,
|
|
@@ -447,7 +447,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
447
447
|
*/
|
|
448
448
|
async turnOff() {
|
|
449
449
|
logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
|
|
450
|
-
const [response, status] = await
|
|
450
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
451
451
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
452
452
|
cid: this.cid,
|
|
453
453
|
configModule: this.configModule,
|
|
@@ -476,7 +476,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
476
476
|
throw new Error(error);
|
|
477
477
|
}
|
|
478
478
|
logger_1.logger.debug(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
479
|
-
const [response, status] = await
|
|
479
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
480
480
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
481
481
|
cid: this.cid,
|
|
482
482
|
configModule: this.configModule,
|
|
@@ -506,7 +506,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
506
506
|
throw new Error(error);
|
|
507
507
|
}
|
|
508
508
|
logger_1.logger.debug(`Setting mode to ${mode} for device: ${this.deviceName}`);
|
|
509
|
-
const [response, status] = await
|
|
509
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
510
510
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
511
511
|
cid: this.cid,
|
|
512
512
|
configModule: this.configModule,
|
|
@@ -539,7 +539,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
539
539
|
throw new Error(error);
|
|
540
540
|
}
|
|
541
541
|
logger_1.logger.debug(`Setting mist level to ${level} for device: ${this.deviceName}`);
|
|
542
|
-
const [response, status] = await
|
|
542
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
543
543
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
544
544
|
cid: this.cid,
|
|
545
545
|
configModule: this.configModule,
|
|
@@ -572,7 +572,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
572
572
|
throw new Error(error);
|
|
573
573
|
}
|
|
574
574
|
logger_1.logger.debug(`Setting target humidity to ${humidity}% for device: ${this.deviceName}`);
|
|
575
|
-
const [response, status] = await
|
|
575
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
576
576
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
577
577
|
cid: this.cid,
|
|
578
578
|
configModule: this.configModule,
|
|
@@ -600,7 +600,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
600
600
|
throw new Error(error);
|
|
601
601
|
}
|
|
602
602
|
logger_1.logger.debug(`Setting display to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
|
|
603
|
-
const [response, status] = await
|
|
603
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
604
604
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
605
605
|
cid: this.cid,
|
|
606
606
|
configModule: this.configModule,
|
|
@@ -628,7 +628,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
628
628
|
throw new Error(error);
|
|
629
629
|
}
|
|
630
630
|
logger_1.logger.debug(`Setting timer to ${hours} hours for device: ${this.deviceName}`);
|
|
631
|
-
const [response, status] = await
|
|
631
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
632
632
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
633
633
|
cid: this.cid,
|
|
634
634
|
configModule: this.configModule,
|
|
@@ -657,7 +657,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
657
657
|
throw new Error(error);
|
|
658
658
|
}
|
|
659
659
|
logger_1.logger.debug(`Clearing timer for device: ${this.deviceName}`);
|
|
660
|
-
const [response, status] = await
|
|
660
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
661
661
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
662
662
|
cid: this.cid,
|
|
663
663
|
configModule: this.configModule,
|
|
@@ -678,7 +678,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
678
678
|
*/
|
|
679
679
|
async automaticStopOn() {
|
|
680
680
|
logger_1.logger.debug(`Setting automatic stop on for device: ${this.deviceName}`);
|
|
681
|
-
const [response, status] = await
|
|
681
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
682
682
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
683
683
|
cid: this.cid,
|
|
684
684
|
configModule: this.configModule,
|
|
@@ -701,7 +701,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
701
701
|
*/
|
|
702
702
|
async automaticStopOff() {
|
|
703
703
|
logger_1.logger.debug(`Setting automatic stop off for device: ${this.deviceName}`);
|
|
704
|
-
const [response, status] = await
|
|
704
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
705
705
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
706
706
|
cid: this.cid,
|
|
707
707
|
configModule: this.configModule,
|
|
@@ -789,7 +789,7 @@ class VeSyncWarmHumidifier extends VeSyncHumidifier {
|
|
|
789
789
|
throw new Error(error);
|
|
790
790
|
}
|
|
791
791
|
logger_1.logger.debug(`Setting warm level to ${level} for device: ${this.deviceName}`);
|
|
792
|
-
const [response, status] = await
|
|
792
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
793
793
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
794
794
|
cid: this.cid,
|
|
795
795
|
configModule: this.configModule,
|
|
@@ -817,7 +817,7 @@ class VeSyncWarmHumidifier extends VeSyncHumidifier {
|
|
|
817
817
|
throw new Error(error);
|
|
818
818
|
}
|
|
819
819
|
logger_1.logger.debug(`Setting drying mode to ${enabled} for device: ${this.deviceName}`);
|
|
820
|
-
const [response, status] = await
|
|
820
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
821
821
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
822
822
|
cid: this.cid,
|
|
823
823
|
configModule: this.configModule,
|
package/dist/lib/vesyncOutlet.js
CHANGED
|
@@ -66,7 +66,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
66
66
|
else {
|
|
67
67
|
url = '/v1/device/devicedetail';
|
|
68
68
|
}
|
|
69
|
-
const [response] = await
|
|
69
|
+
const [response] = await this.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
70
|
if (!response) {
|
|
71
71
|
logger_1.logger.debug(`[${this.deviceName}] No response received from API`);
|
|
72
72
|
return;
|
|
@@ -101,7 +101,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
101
101
|
});
|
|
102
102
|
if (subDevice) {
|
|
103
103
|
this.deviceStatus = subDevice.subDeviceStatus;
|
|
104
|
-
logger_1.logger.
|
|
104
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved sub-device status: ${this.deviceStatus}`);
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -119,7 +119,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
119
119
|
logger_1.logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
logger_1.logger.
|
|
122
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
125
|
logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
@@ -155,7 +155,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
155
155
|
...helpers_1.Helpers.reqBody(this.manager, 'energy'),
|
|
156
156
|
uuid: this.uuid
|
|
157
157
|
};
|
|
158
|
-
const [response] = await
|
|
158
|
+
const [response] = await this.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
159
159
|
// Handle different response formats
|
|
160
160
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && response.result) {
|
|
161
161
|
this.energy = response.result;
|
|
@@ -250,10 +250,10 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
250
250
|
...helpers_1.Helpers.reqBody(this.manager, 'energyweek'),
|
|
251
251
|
uuid: this.uuid
|
|
252
252
|
};
|
|
253
|
-
const [response] = await
|
|
253
|
+
const [response] = await this.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/week` : `/${this.getApiPrefix()}/energyweek`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
254
254
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
255
255
|
this.energy.week = response.result || response.energyWeek || '0';
|
|
256
|
-
logger_1.logger.
|
|
256
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved weekly energy data`);
|
|
257
257
|
}
|
|
258
258
|
else {
|
|
259
259
|
this.energy.week = '0';
|
|
@@ -274,10 +274,10 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
274
274
|
...helpers_1.Helpers.reqBody(this.manager, 'energymonth'),
|
|
275
275
|
uuid: this.uuid
|
|
276
276
|
};
|
|
277
|
-
const [response] = await
|
|
277
|
+
const [response] = await this.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/month` : `/${this.getApiPrefix()}/energymonth`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
278
278
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
279
279
|
this.energy.month = response.result || response.energyMonth || '0';
|
|
280
|
-
logger_1.logger.
|
|
280
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved monthly energy data`);
|
|
281
281
|
}
|
|
282
282
|
else {
|
|
283
283
|
this.energy.month = '0';
|
|
@@ -298,10 +298,10 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
298
298
|
...helpers_1.Helpers.reqBody(this.manager, 'energyyear'),
|
|
299
299
|
uuid: this.uuid
|
|
300
300
|
};
|
|
301
|
-
const [response] = await
|
|
301
|
+
const [response] = await this.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/year` : `/${this.getApiPrefix()}/energyyear`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
302
302
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
303
303
|
this.energy.year = response.result || response.energyYear || '0';
|
|
304
|
-
logger_1.logger.
|
|
304
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved yearly energy data`);
|
|
305
305
|
}
|
|
306
306
|
else {
|
|
307
307
|
this.energy.year = '0';
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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`);
|
|
@@ -206,7 +206,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
206
206
|
status: 'on',
|
|
207
207
|
switchNo: this.subDeviceNo
|
|
208
208
|
};
|
|
209
|
-
const [response] = await
|
|
209
|
+
const [response] = await this.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
210
210
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
211
211
|
this.deviceStatus = 'on';
|
|
212
212
|
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
@@ -226,7 +226,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
226
226
|
status: 'off',
|
|
227
227
|
switchNo: this.subDeviceNo
|
|
228
228
|
};
|
|
229
|
-
const [response] = await
|
|
229
|
+
const [response] = await this.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
230
230
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
231
231
|
this.deviceStatus = 'off';
|
|
232
232
|
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|