tsvesync 1.0.14 → 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 +1 -1
- package/dist/lib/vesyncOutlet.js +57 -6
- package/package.json +1 -1
- package/src/lib/vesyncOutlet.ts +60 -7
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.
|
|
169
|
+
await fan.changeFanSpeed(2); // Speed range depends on model
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// Control an outlet
|
package/dist/lib/vesyncOutlet.js
CHANGED
|
@@ -46,15 +46,66 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
46
46
|
*/
|
|
47
47
|
async getDetails() {
|
|
48
48
|
logger_1.logger.debug(`[${this.deviceName}] Getting outlet details`);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const body = {
|
|
50
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
51
|
+
uuid: this.uuid
|
|
52
|
+
};
|
|
53
|
+
let url;
|
|
54
|
+
if (this.deviceType === 'wifi-switch-1.3') {
|
|
55
|
+
url = `/v1/device/wifi-switch-1.3-${this.cid}/detail`;
|
|
56
|
+
}
|
|
57
|
+
else if (this.deviceType.startsWith('ESO15')) {
|
|
58
|
+
url = '/outdoorsocket15a/v1/device/devicedetail';
|
|
59
|
+
}
|
|
60
|
+
else if (this.deviceType.startsWith('ESW15')) {
|
|
61
|
+
url = '/15a/v1/device/devicedetail';
|
|
62
|
+
}
|
|
63
|
+
else if (this.deviceType.startsWith('ESW03') || this.deviceType.startsWith('ESW01')) {
|
|
64
|
+
url = '/10a/v1/device/devicedetail';
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
url = '/v1/device/devicedetail';
|
|
68
|
+
}
|
|
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) {
|
|
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
|
+
}
|
|
54
105
|
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
55
106
|
}
|
|
56
107
|
else {
|
|
57
|
-
logger_1.logger.
|
|
108
|
+
logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
58
109
|
}
|
|
59
110
|
}
|
|
60
111
|
/**
|
package/package.json
CHANGED
package/src/lib/vesyncOutlet.ts
CHANGED
|
@@ -58,20 +58,73 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
58
58
|
*/
|
|
59
59
|
async getDetails(): Promise<void> {
|
|
60
60
|
logger.debug(`[${this.deviceName}] Getting outlet details`);
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
const body = {
|
|
63
|
+
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
64
|
+
uuid: this.uuid
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
let url: string;
|
|
68
|
+
if (this.deviceType === 'wifi-switch-1.3') {
|
|
69
|
+
url = `/v1/device/wifi-switch-1.3-${this.cid}/detail`;
|
|
70
|
+
} else if (this.deviceType.startsWith('ESO15')) {
|
|
71
|
+
url = '/outdoorsocket15a/v1/device/devicedetail';
|
|
72
|
+
} else if (this.deviceType.startsWith('ESW15')) {
|
|
73
|
+
url = '/15a/v1/device/devicedetail';
|
|
74
|
+
} else if (this.deviceType.startsWith('ESW03') || this.deviceType.startsWith('ESW01')) {
|
|
75
|
+
url = '/10a/v1/device/devicedetail';
|
|
76
|
+
} else {
|
|
77
|
+
url = '/v1/device/devicedetail';
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
const [response] = await Helpers.callApi(
|
|
63
81
|
url,
|
|
64
|
-
'get',
|
|
65
|
-
null,
|
|
82
|
+
this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post',
|
|
83
|
+
this.deviceType === 'wifi-switch-1.3' ? null : body,
|
|
66
84
|
Helpers.reqHeaders(this.manager)
|
|
67
85
|
);
|
|
68
86
|
|
|
69
|
-
if (response
|
|
70
|
-
this.
|
|
71
|
-
|
|
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
|
+
}
|
|
72
125
|
logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
73
126
|
} else {
|
|
74
|
-
logger.
|
|
127
|
+
logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
75
128
|
}
|
|
76
129
|
}
|
|
77
130
|
|