tsvesync 1.0.12 → 1.0.13
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/dist/lib/helpers.js +3 -2
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.js +54 -0
- package/dist/lib/vesync.js +42 -41
- package/dist/lib/vesyncBaseDevice.js +8 -7
- package/dist/lib/vesyncBulb.d.ts +9 -0
- package/dist/lib/vesyncBulb.js +125 -28
- package/dist/lib/vesyncBulbImpl.d.ts +1 -1
- package/dist/lib/vesyncBulbImpl.js +105 -36
- package/dist/lib/vesyncFan.js +2 -1
- package/dist/lib/vesyncFanImpl.d.ts +36 -0
- package/dist/lib/vesyncFanImpl.js +307 -42
- package/dist/lib/vesyncOutlet.d.ts +17 -0
- package/dist/lib/vesyncOutlet.js +124 -8
- package/dist/lib/vesyncOutletImpl.js +39 -0
- package/dist/lib/vesyncSwitch.d.ts +0 -124
- package/dist/lib/vesyncSwitch.js +3 -343
- package/dist/lib/vesyncSwitchImpl.d.ts +6 -6
- package/dist/lib/vesyncSwitchImpl.js +69 -15
- package/package.json +1 -1
- package/src/lib/helpers.ts +3 -2
- package/src/lib/logger.ts +60 -0
- package/src/lib/vesync.ts +42 -43
- package/src/lib/vesyncBaseDevice.ts +8 -7
- package/src/lib/vesyncBulb.ts +138 -30
- package/src/lib/vesyncBulbImpl.ts +113 -44
- package/src/lib/vesyncFan.ts +2 -4
- package/src/lib/vesyncFanImpl.ts +314 -42
- package/src/lib/vesyncOutlet.ts +140 -13
- package/src/lib/vesyncOutletImpl.ts +41 -0
- package/src/lib/vesyncSwitch.ts +3 -454
- package/src/lib/vesyncSwitchImpl.ts +66 -16
|
@@ -3,12 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
5
|
import { VeSync } from './vesync';
|
|
6
|
+
interface OutletConfig {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
module: string;
|
|
9
|
+
features: string[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare const outletConfig: OutletConfig;
|
|
6
13
|
/**
|
|
7
14
|
* VeSync Outlet Base Class
|
|
8
15
|
*/
|
|
9
16
|
export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
10
17
|
protected energy: Record<string, any>;
|
|
11
18
|
protected details: Record<string, any>;
|
|
19
|
+
protected features: string[];
|
|
12
20
|
constructor(details: Record<string, any>, manager: VeSync);
|
|
13
21
|
/**
|
|
14
22
|
* Get outlet details
|
|
@@ -26,6 +34,10 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
26
34
|
* Get outlet status
|
|
27
35
|
*/
|
|
28
36
|
getStatus(): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Get API prefix based on device type
|
|
39
|
+
*/
|
|
40
|
+
private getApiPrefix;
|
|
29
41
|
/**
|
|
30
42
|
* Get weekly energy data
|
|
31
43
|
*/
|
|
@@ -42,6 +54,10 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
42
54
|
* Update outlet details and energy info
|
|
43
55
|
*/
|
|
44
56
|
update(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Check if outlet has nightlight feature
|
|
59
|
+
*/
|
|
60
|
+
hasNightlight(): boolean;
|
|
45
61
|
/**
|
|
46
62
|
* Turn outlet on
|
|
47
63
|
*/
|
|
@@ -51,3 +67,4 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
51
67
|
*/
|
|
52
68
|
abstract turnOff(): Promise<boolean>;
|
|
53
69
|
}
|
|
70
|
+
export {};
|
package/dist/lib/vesyncOutlet.js
CHANGED
|
@@ -3,43 +3,94 @@
|
|
|
3
3
|
* VeSync Outlets
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.VeSyncOutlet = void 0;
|
|
6
|
+
exports.VeSyncOutlet = exports.outletConfig = void 0;
|
|
7
7
|
const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
// Outlet configuration
|
|
11
|
+
exports.outletConfig = {
|
|
12
|
+
'wifi-switch-1.3': {
|
|
13
|
+
module: 'VeSyncOutlet7A',
|
|
14
|
+
features: ['energy']
|
|
15
|
+
},
|
|
16
|
+
'ESW03-USA': {
|
|
17
|
+
module: 'VeSyncOutlet10A',
|
|
18
|
+
features: ['energy']
|
|
19
|
+
},
|
|
20
|
+
'ESW01-EU': {
|
|
21
|
+
module: 'VeSyncOutlet10A',
|
|
22
|
+
features: ['energy']
|
|
23
|
+
},
|
|
24
|
+
'ESW15-USA': {
|
|
25
|
+
module: 'VeSyncOutlet15A',
|
|
26
|
+
features: ['energy', 'nightlight']
|
|
27
|
+
},
|
|
28
|
+
'ESO15-TB': {
|
|
29
|
+
module: 'VeSyncOutdoorPlug',
|
|
30
|
+
features: ['energy']
|
|
31
|
+
}
|
|
32
|
+
};
|
|
9
33
|
/**
|
|
10
34
|
* VeSync Outlet Base Class
|
|
11
35
|
*/
|
|
12
36
|
class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
13
37
|
constructor(details, manager) {
|
|
38
|
+
var _a;
|
|
14
39
|
super(details, manager);
|
|
15
40
|
this.energy = {};
|
|
16
41
|
this.details = details;
|
|
42
|
+
this.features = ((_a = exports.outletConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
|
|
17
43
|
}
|
|
18
44
|
/**
|
|
19
45
|
* Get outlet details
|
|
20
46
|
*/
|
|
21
47
|
async getDetails() {
|
|
48
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting outlet details`);
|
|
22
49
|
const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/detail`;
|
|
23
50
|
const [response] = await helpers_1.Helpers.callApi(url, 'get', null, helpers_1.Helpers.reqHeaders(this.manager));
|
|
24
51
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
25
52
|
this.details = response.result;
|
|
26
53
|
this.deviceStatus = response.result.deviceStatus;
|
|
54
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
27
58
|
}
|
|
28
59
|
}
|
|
29
60
|
/**
|
|
30
61
|
* Update outlet energy data
|
|
31
62
|
*/
|
|
32
63
|
async updateEnergy() {
|
|
64
|
+
if (!this.features.includes('energy')) {
|
|
65
|
+
logger_1.logger.debug(`[${this.deviceName}] Energy monitoring not supported`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
logger_1.logger.debug(`[${this.deviceName}] Updating energy data`);
|
|
33
69
|
const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/detail`;
|
|
34
70
|
const [response] = await helpers_1.Helpers.callApi(url, 'get', null, helpers_1.Helpers.reqHeaders(this.manager));
|
|
35
71
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
36
72
|
this.energy = response.result;
|
|
73
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully updated energy data`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to update energy data: ${JSON.stringify(response)}`);
|
|
37
77
|
}
|
|
38
78
|
}
|
|
39
79
|
/**
|
|
40
80
|
* Get outlet energy usage
|
|
41
81
|
*/
|
|
42
82
|
async getEnergyUsage() {
|
|
83
|
+
if (!this.features.includes('energy')) {
|
|
84
|
+
logger_1.logger.debug(`[${this.deviceName}] Energy monitoring not supported`);
|
|
85
|
+
return {
|
|
86
|
+
power: 'Not supported',
|
|
87
|
+
voltage: 'Not supported',
|
|
88
|
+
energy_today: 'Not supported',
|
|
89
|
+
energy_week: 'Not supported',
|
|
90
|
+
energy_month: 'Not supported',
|
|
91
|
+
energy_year: 'Not supported'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
43
94
|
await this.updateEnergy();
|
|
44
95
|
return {
|
|
45
96
|
power: this.energy.power || 'Not available',
|
|
@@ -54,45 +105,110 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
54
105
|
* Get outlet status
|
|
55
106
|
*/
|
|
56
107
|
async getStatus() {
|
|
108
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting outlet status`);
|
|
57
109
|
await this.getDetails();
|
|
58
110
|
return this.deviceStatus;
|
|
59
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Get API prefix based on device type
|
|
114
|
+
*/
|
|
115
|
+
getApiPrefix() {
|
|
116
|
+
if (this.deviceType === 'wifi-switch-1.3') {
|
|
117
|
+
return `v1/device/${this.deviceType}-${this.cid}`;
|
|
118
|
+
}
|
|
119
|
+
else if (this.deviceType.startsWith('ESW15') || this.deviceType.startsWith('ESO15')) {
|
|
120
|
+
return '15a/v1/device';
|
|
121
|
+
}
|
|
122
|
+
else if (this.deviceType.startsWith('ESW03') || this.deviceType.startsWith('ESW01')) {
|
|
123
|
+
return '10a/v1/device';
|
|
124
|
+
}
|
|
125
|
+
return 'v1/device';
|
|
126
|
+
}
|
|
60
127
|
/**
|
|
61
128
|
* Get weekly energy data
|
|
62
129
|
*/
|
|
63
130
|
async getWeeklyEnergy() {
|
|
64
|
-
|
|
65
|
-
|
|
131
|
+
if (!this.features.includes('energy')) {
|
|
132
|
+
logger_1.logger.debug(`[${this.deviceName}] Energy monitoring not supported`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting weekly energy data`);
|
|
136
|
+
const isLegacyDevice = this.deviceType === 'wifi-switch-1.3';
|
|
137
|
+
const body = isLegacyDevice ? null : {
|
|
138
|
+
...helpers_1.Helpers.reqBody(this.manager, 'energyweek'),
|
|
139
|
+
uuid: this.uuid
|
|
140
|
+
};
|
|
141
|
+
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/week` : `/${this.getApiPrefix()}/energyweek`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
66
142
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
67
143
|
this.energy.week = response.result;
|
|
144
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved weekly energy data`);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to get weekly energy data: ${JSON.stringify(response)}`);
|
|
68
148
|
}
|
|
69
149
|
}
|
|
70
150
|
/**
|
|
71
151
|
* Get monthly energy data
|
|
72
152
|
*/
|
|
73
153
|
async getMonthlyEnergy() {
|
|
74
|
-
|
|
75
|
-
|
|
154
|
+
if (!this.features.includes('energy')) {
|
|
155
|
+
logger_1.logger.debug(`[${this.deviceName}] Energy monitoring not supported`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting monthly energy data`);
|
|
159
|
+
const isLegacyDevice = this.deviceType === 'wifi-switch-1.3';
|
|
160
|
+
const body = isLegacyDevice ? null : {
|
|
161
|
+
...helpers_1.Helpers.reqBody(this.manager, 'energymonth'),
|
|
162
|
+
uuid: this.uuid
|
|
163
|
+
};
|
|
164
|
+
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/month` : `/${this.getApiPrefix()}/energymonth`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
76
165
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
77
166
|
this.energy.month = response.result;
|
|
167
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved monthly energy data`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to get monthly energy data: ${JSON.stringify(response)}`);
|
|
78
171
|
}
|
|
79
172
|
}
|
|
80
173
|
/**
|
|
81
174
|
* Get yearly energy data
|
|
82
175
|
*/
|
|
83
176
|
async getYearlyEnergy() {
|
|
84
|
-
|
|
85
|
-
|
|
177
|
+
if (!this.features.includes('energy')) {
|
|
178
|
+
logger_1.logger.debug(`[${this.deviceName}] Energy monitoring not supported`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting yearly energy data`);
|
|
182
|
+
const isLegacyDevice = this.deviceType === 'wifi-switch-1.3';
|
|
183
|
+
const body = isLegacyDevice ? null : {
|
|
184
|
+
...helpers_1.Helpers.reqBody(this.manager, 'energyyear'),
|
|
185
|
+
uuid: this.uuid
|
|
186
|
+
};
|
|
187
|
+
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/year` : `/${this.getApiPrefix()}/energyyear`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
86
188
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
87
189
|
this.energy.year = response.result;
|
|
190
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved yearly energy data`);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to get yearly energy data: ${JSON.stringify(response)}`);
|
|
88
194
|
}
|
|
89
195
|
}
|
|
90
196
|
/**
|
|
91
197
|
* Update outlet details and energy info
|
|
92
198
|
*/
|
|
93
199
|
async update() {
|
|
200
|
+
logger_1.logger.debug(`[${this.deviceName}] Updating outlet information`);
|
|
94
201
|
await this.getDetails();
|
|
95
|
-
|
|
202
|
+
if (this.features.includes('energy')) {
|
|
203
|
+
await this.updateEnergy();
|
|
204
|
+
}
|
|
205
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully updated outlet information`);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if outlet has nightlight feature
|
|
209
|
+
*/
|
|
210
|
+
hasNightlight() {
|
|
211
|
+
return this.features.includes('nightlight');
|
|
96
212
|
}
|
|
97
213
|
}
|
|
98
214
|
exports.VeSyncOutlet = VeSyncOutlet;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.outletModules = exports.VeSyncOutdoorPlug = exports.VeSyncOutlet15A = exports.VeSyncOutlet10A = exports.VeSyncOutlet7A = void 0;
|
|
7
7
|
const vesyncOutlet_1 = require("./vesyncOutlet");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
9
10
|
/**
|
|
10
11
|
* VeSync 7A Outlet
|
|
11
12
|
*/
|
|
@@ -17,24 +18,30 @@ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
17
18
|
* Turn outlet on
|
|
18
19
|
*/
|
|
19
20
|
async turnOn() {
|
|
21
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
20
22
|
const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/on`;
|
|
21
23
|
const [response] = await helpers_1.Helpers.callApi(url, 'put', null, helpers_1.Helpers.reqHeaders(this.manager));
|
|
22
24
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
23
25
|
this.deviceStatus = 'on';
|
|
26
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
|
|
24
27
|
return true;
|
|
25
28
|
}
|
|
29
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
26
30
|
return false;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Turn outlet off
|
|
30
34
|
*/
|
|
31
35
|
async turnOff() {
|
|
36
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
32
37
|
const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/off`;
|
|
33
38
|
const [response] = await helpers_1.Helpers.callApi(url, 'put', null, helpers_1.Helpers.reqHeaders(this.manager));
|
|
34
39
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
35
40
|
this.deviceStatus = 'off';
|
|
41
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
|
|
36
42
|
return true;
|
|
37
43
|
}
|
|
44
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
38
45
|
return false;
|
|
39
46
|
}
|
|
40
47
|
}
|
|
@@ -50,6 +57,7 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
50
57
|
* Turn outlet on
|
|
51
58
|
*/
|
|
52
59
|
async turnOn() {
|
|
60
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
53
61
|
const body = {
|
|
54
62
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
55
63
|
uuid: this.uuid,
|
|
@@ -58,14 +66,17 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
58
66
|
const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
59
67
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
60
68
|
this.deviceStatus = 'on';
|
|
69
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
|
|
61
70
|
return true;
|
|
62
71
|
}
|
|
72
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
63
73
|
return false;
|
|
64
74
|
}
|
|
65
75
|
/**
|
|
66
76
|
* Turn outlet off
|
|
67
77
|
*/
|
|
68
78
|
async turnOff() {
|
|
79
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
69
80
|
const body = {
|
|
70
81
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
71
82
|
uuid: this.uuid,
|
|
@@ -74,8 +85,10 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
74
85
|
const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
75
86
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
76
87
|
this.deviceStatus = 'off';
|
|
88
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
|
|
77
89
|
return true;
|
|
78
90
|
}
|
|
91
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
79
92
|
return false;
|
|
80
93
|
}
|
|
81
94
|
}
|
|
@@ -91,6 +104,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
91
104
|
* Turn outlet on
|
|
92
105
|
*/
|
|
93
106
|
async turnOn() {
|
|
107
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
94
108
|
const body = {
|
|
95
109
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
96
110
|
uuid: this.uuid,
|
|
@@ -99,14 +113,17 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
99
113
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
100
114
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
101
115
|
this.deviceStatus = 'on';
|
|
116
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
|
|
102
117
|
return true;
|
|
103
118
|
}
|
|
119
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
104
120
|
return false;
|
|
105
121
|
}
|
|
106
122
|
/**
|
|
107
123
|
* Turn outlet off
|
|
108
124
|
*/
|
|
109
125
|
async turnOff() {
|
|
126
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
110
127
|
const body = {
|
|
111
128
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
112
129
|
uuid: this.uuid,
|
|
@@ -115,14 +132,21 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
115
132
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
116
133
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
117
134
|
this.deviceStatus = 'off';
|
|
135
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
|
|
118
136
|
return true;
|
|
119
137
|
}
|
|
138
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
120
139
|
return false;
|
|
121
140
|
}
|
|
122
141
|
/**
|
|
123
142
|
* Turn on nightlight
|
|
124
143
|
*/
|
|
125
144
|
async turnOnNightlight() {
|
|
145
|
+
if (!this.hasNightlight()) {
|
|
146
|
+
logger_1.logger.error(`[${this.deviceName}] Nightlight feature not supported`);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning nightlight on`);
|
|
126
150
|
const body = {
|
|
127
151
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
128
152
|
uuid: this.uuid,
|
|
@@ -131,14 +155,21 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
131
155
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
132
156
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
133
157
|
this.details.nightLightStatus = 'on';
|
|
158
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned nightlight on`);
|
|
134
159
|
return true;
|
|
135
160
|
}
|
|
161
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight on: ${JSON.stringify(response)}`);
|
|
136
162
|
return false;
|
|
137
163
|
}
|
|
138
164
|
/**
|
|
139
165
|
* Turn off nightlight
|
|
140
166
|
*/
|
|
141
167
|
async turnOffNightlight() {
|
|
168
|
+
if (!this.hasNightlight()) {
|
|
169
|
+
logger_1.logger.error(`[${this.deviceName}] Nightlight feature not supported`);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning nightlight off`);
|
|
142
173
|
const body = {
|
|
143
174
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
144
175
|
uuid: this.uuid,
|
|
@@ -147,8 +178,10 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
147
178
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
148
179
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
149
180
|
this.details.nightLightStatus = 'off';
|
|
181
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned nightlight off`);
|
|
150
182
|
return true;
|
|
151
183
|
}
|
|
184
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight off: ${JSON.stringify(response)}`);
|
|
152
185
|
return false;
|
|
153
186
|
}
|
|
154
187
|
}
|
|
@@ -164,6 +197,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
164
197
|
* Turn outlet on
|
|
165
198
|
*/
|
|
166
199
|
async turnOn() {
|
|
200
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
167
201
|
const body = {
|
|
168
202
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
169
203
|
uuid: this.uuid,
|
|
@@ -173,14 +207,17 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
173
207
|
const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
174
208
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
175
209
|
this.deviceStatus = 'on';
|
|
210
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
|
|
176
211
|
return true;
|
|
177
212
|
}
|
|
213
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
178
214
|
return false;
|
|
179
215
|
}
|
|
180
216
|
/**
|
|
181
217
|
* Turn outlet off
|
|
182
218
|
*/
|
|
183
219
|
async turnOff() {
|
|
220
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
184
221
|
const body = {
|
|
185
222
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
186
223
|
uuid: this.uuid,
|
|
@@ -190,8 +227,10 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
190
227
|
const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
191
228
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
192
229
|
this.deviceStatus = 'off';
|
|
230
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
|
|
193
231
|
return true;
|
|
194
232
|
}
|
|
233
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
195
234
|
return false;
|
|
196
235
|
}
|
|
197
236
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
5
|
import { VeSync } from './vesync';
|
|
6
|
-
type DeviceConstructor = new (config: Record<string, any>, manager: VeSync) => VeSyncBaseDevice;
|
|
7
6
|
interface SwitchConfig {
|
|
8
7
|
[key: string]: {
|
|
9
8
|
module: string;
|
|
@@ -43,127 +42,4 @@ export declare abstract class VeSyncSwitch extends VeSyncBaseDevice {
|
|
|
43
42
|
*/
|
|
44
43
|
update(): Promise<void>;
|
|
45
44
|
}
|
|
46
|
-
/**
|
|
47
|
-
* VeSync Wall Switch
|
|
48
|
-
*/
|
|
49
|
-
export declare class VeSyncWallSwitch extends VeSyncSwitch {
|
|
50
|
-
constructor(details: Record<string, any>, manager: VeSync);
|
|
51
|
-
/**
|
|
52
|
-
* Get wall switch details
|
|
53
|
-
*/
|
|
54
|
-
getDetails(): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Get switch device configuration info
|
|
57
|
-
*/
|
|
58
|
-
getConfig(): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Turn off wall switch
|
|
61
|
-
*/
|
|
62
|
-
turnOff(): Promise<boolean>;
|
|
63
|
-
/**
|
|
64
|
-
* Turn on wall switch
|
|
65
|
-
*/
|
|
66
|
-
turnOn(): Promise<boolean>;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* VeSync Dimmer Switch
|
|
70
|
-
*/
|
|
71
|
-
export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
72
|
-
private _brightness;
|
|
73
|
-
private _rgbValue;
|
|
74
|
-
private _rgbStatus;
|
|
75
|
-
private _indicatorLight;
|
|
76
|
-
constructor(details: Record<string, any>, manager: VeSync);
|
|
77
|
-
/**
|
|
78
|
-
* Get dimmer switch details
|
|
79
|
-
*/
|
|
80
|
-
getDetails(): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Get dimmer switch configuration info
|
|
83
|
-
*/
|
|
84
|
-
getConfig(): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Turn off dimmer switch
|
|
87
|
-
*/
|
|
88
|
-
turnOff(): Promise<boolean>;
|
|
89
|
-
/**
|
|
90
|
-
* Turn on dimmer switch
|
|
91
|
-
*/
|
|
92
|
-
turnOn(): Promise<boolean>;
|
|
93
|
-
/**
|
|
94
|
-
* Return brightness in percent
|
|
95
|
-
*/
|
|
96
|
-
get brightness(): number;
|
|
97
|
-
/**
|
|
98
|
-
* Return faceplate brightness light status
|
|
99
|
-
*/
|
|
100
|
-
get indicatorLightStatus(): string;
|
|
101
|
-
/**
|
|
102
|
-
* Return RGB faceplate light status
|
|
103
|
-
*/
|
|
104
|
-
get rgbLightStatus(): string;
|
|
105
|
-
/**
|
|
106
|
-
* Return RGB light values
|
|
107
|
-
*/
|
|
108
|
-
get rgbLightValue(): Record<string, number>;
|
|
109
|
-
/**
|
|
110
|
-
* Update device details
|
|
111
|
-
*/
|
|
112
|
-
update(): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Display device info
|
|
115
|
-
*/
|
|
116
|
-
display(): void;
|
|
117
|
-
/**
|
|
118
|
-
* Return JSON details for dimmer switch
|
|
119
|
-
*/
|
|
120
|
-
displayJSON(): string;
|
|
121
|
-
/**
|
|
122
|
-
* Set brightness level
|
|
123
|
-
* @param brightness - Brightness level (1-100)
|
|
124
|
-
*/
|
|
125
|
-
setBrightness(brightness: number): Promise<boolean>;
|
|
126
|
-
/**
|
|
127
|
-
* Toggle indicator light status
|
|
128
|
-
* @param status - Light status ('on' or 'off')
|
|
129
|
-
*/
|
|
130
|
-
indicatorLightToggle(status: string): Promise<boolean>;
|
|
131
|
-
/**
|
|
132
|
-
* Set RGB color values
|
|
133
|
-
* @param red - Red value (0-255)
|
|
134
|
-
* @param green - Green value (0-255)
|
|
135
|
-
* @param blue - Blue value (0-255)
|
|
136
|
-
*/
|
|
137
|
-
rgbColorSet(red: number, green: number, blue: number): Promise<boolean>;
|
|
138
|
-
/**
|
|
139
|
-
* Toggle switch status
|
|
140
|
-
* @param status - Switch status ('on' or 'off')
|
|
141
|
-
*/
|
|
142
|
-
switchToggle(status: string): Promise<boolean>;
|
|
143
|
-
/**
|
|
144
|
-
* Set faceplate RGB color status and optionally set RGB values
|
|
145
|
-
* @param status - RGB status ('on' or 'off')
|
|
146
|
-
* @param red - Optional red value (0-255)
|
|
147
|
-
* @param green - Optional green value (0-255)
|
|
148
|
-
* @param blue - Optional blue value (0-255)
|
|
149
|
-
*/
|
|
150
|
-
rgbColorStatus(status: string, red?: number, green?: number, blue?: number): Promise<boolean>;
|
|
151
|
-
/**
|
|
152
|
-
* Turn RGB Color Off
|
|
153
|
-
*/
|
|
154
|
-
rgbColorOff(): Promise<boolean>;
|
|
155
|
-
/**
|
|
156
|
-
* Turn RGB Color On
|
|
157
|
-
*/
|
|
158
|
-
rgbColorOn(): Promise<boolean>;
|
|
159
|
-
/**
|
|
160
|
-
* Turn indicator light on
|
|
161
|
-
*/
|
|
162
|
-
indicatorLightOn(): Promise<boolean>;
|
|
163
|
-
/**
|
|
164
|
-
* Turn indicator light off
|
|
165
|
-
*/
|
|
166
|
-
indicatorLightOff(): Promise<boolean>;
|
|
167
|
-
}
|
|
168
|
-
export declare const switchModules: Record<string, DeviceConstructor>;
|
|
169
45
|
export {};
|