tsvesync 1.0.11 → 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.
Files changed (40) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.js +25 -0
  3. package/dist/lib/helpers.d.ts +52 -51
  4. package/dist/lib/helpers.js +135 -112
  5. package/dist/lib/logger.d.ts +23 -0
  6. package/dist/lib/logger.js +54 -0
  7. package/dist/lib/vesync.d.ts +57 -15
  8. package/dist/lib/vesync.js +341 -217
  9. package/dist/lib/vesyncBaseDevice.d.ts +25 -50
  10. package/dist/lib/vesyncBaseDevice.js +63 -90
  11. package/dist/lib/vesyncBulb.d.ts +88 -0
  12. package/dist/lib/vesyncBulb.js +295 -1
  13. package/dist/lib/vesyncBulbImpl.d.ts +38 -0
  14. package/dist/lib/vesyncBulbImpl.js +230 -0
  15. package/dist/lib/vesyncFan.d.ts +55 -67
  16. package/dist/lib/vesyncFan.js +366 -213
  17. package/dist/lib/vesyncFanImpl.d.ts +173 -0
  18. package/dist/lib/vesyncFanImpl.js +909 -0
  19. package/dist/lib/vesyncOutlet.d.ts +70 -0
  20. package/dist/lib/vesyncOutlet.js +213 -1
  21. package/dist/lib/vesyncOutletImpl.d.ts +70 -0
  22. package/dist/lib/vesyncOutletImpl.js +245 -0
  23. package/dist/lib/vesyncSwitch.d.ts +45 -0
  24. package/dist/lib/vesyncSwitch.js +77 -1
  25. package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
  26. package/dist/lib/vesyncSwitchImpl.js +344 -0
  27. package/package.json +1 -1
  28. package/src/index.ts +14 -0
  29. package/src/lib/helpers.ts +3 -2
  30. package/src/lib/logger.ts +60 -0
  31. package/src/lib/vesync.ts +42 -43
  32. package/src/lib/vesyncBaseDevice.ts +8 -7
  33. package/src/lib/vesyncBulb.ts +138 -30
  34. package/src/lib/vesyncBulbImpl.ts +113 -44
  35. package/src/lib/vesyncFan.ts +2 -4
  36. package/src/lib/vesyncFanImpl.ts +314 -42
  37. package/src/lib/vesyncOutlet.ts +140 -13
  38. package/src/lib/vesyncOutletImpl.ts +41 -0
  39. package/src/lib/vesyncSwitch.ts +3 -454
  40. package/src/lib/vesyncSwitchImpl.ts +66 -16
@@ -0,0 +1,70 @@
1
+ /**
2
+ * VeSync Outlets
3
+ */
4
+ import { VeSyncBaseDevice } from './vesyncBaseDevice';
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;
13
+ /**
14
+ * VeSync Outlet Base Class
15
+ */
16
+ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
17
+ protected energy: Record<string, any>;
18
+ protected details: Record<string, any>;
19
+ protected features: string[];
20
+ constructor(details: Record<string, any>, manager: VeSync);
21
+ /**
22
+ * Get outlet details
23
+ */
24
+ getDetails(): Promise<void>;
25
+ /**
26
+ * Update outlet energy data
27
+ */
28
+ updateEnergy(): Promise<void>;
29
+ /**
30
+ * Get outlet energy usage
31
+ */
32
+ getEnergyUsage(): Promise<Record<string, any>>;
33
+ /**
34
+ * Get outlet status
35
+ */
36
+ getStatus(): Promise<string>;
37
+ /**
38
+ * Get API prefix based on device type
39
+ */
40
+ private getApiPrefix;
41
+ /**
42
+ * Get weekly energy data
43
+ */
44
+ getWeeklyEnergy(): Promise<void>;
45
+ /**
46
+ * Get monthly energy data
47
+ */
48
+ getMonthlyEnergy(): Promise<void>;
49
+ /**
50
+ * Get yearly energy data
51
+ */
52
+ getYearlyEnergy(): Promise<void>;
53
+ /**
54
+ * Update outlet details and energy info
55
+ */
56
+ update(): Promise<void>;
57
+ /**
58
+ * Check if outlet has nightlight feature
59
+ */
60
+ hasNightlight(): boolean;
61
+ /**
62
+ * Turn outlet on
63
+ */
64
+ abstract turnOn(): Promise<boolean>;
65
+ /**
66
+ * Turn outlet off
67
+ */
68
+ abstract turnOff(): Promise<boolean>;
69
+ }
70
+ export {};
@@ -1,2 +1,214 @@
1
1
  "use strict";
2
- //# sourceMappingURL=vesyncOutlet.js.map
2
+ /**
3
+ * VeSync Outlets
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VeSyncOutlet = exports.outletConfig = void 0;
7
+ const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
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
+ };
33
+ /**
34
+ * VeSync Outlet Base Class
35
+ */
36
+ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
37
+ constructor(details, manager) {
38
+ var _a;
39
+ super(details, manager);
40
+ this.energy = {};
41
+ this.details = details;
42
+ this.features = ((_a = exports.outletConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
43
+ }
44
+ /**
45
+ * Get outlet details
46
+ */
47
+ async getDetails() {
48
+ logger_1.logger.debug(`[${this.deviceName}] Getting outlet details`);
49
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/detail`;
50
+ const [response] = await helpers_1.Helpers.callApi(url, 'get', null, helpers_1.Helpers.reqHeaders(this.manager));
51
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
52
+ this.details = response.result;
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)}`);
58
+ }
59
+ }
60
+ /**
61
+ * Update outlet energy data
62
+ */
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`);
69
+ const url = `/v1/${this.deviceType}/${this.deviceType}-${this.cid}/energy/detail`;
70
+ const [response] = await helpers_1.Helpers.callApi(url, 'get', null, helpers_1.Helpers.reqHeaders(this.manager));
71
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
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)}`);
77
+ }
78
+ }
79
+ /**
80
+ * Get outlet energy usage
81
+ */
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
+ }
94
+ await this.updateEnergy();
95
+ return {
96
+ power: this.energy.power || 'Not available',
97
+ voltage: this.energy.voltage || 'Not available',
98
+ energy_today: this.energy.energyToday || 'Not available',
99
+ energy_week: this.energy.energyWeek || 'Not available',
100
+ energy_month: this.energy.energyMonth || 'Not available',
101
+ energy_year: this.energy.energyYear || 'Not available'
102
+ };
103
+ }
104
+ /**
105
+ * Get outlet status
106
+ */
107
+ async getStatus() {
108
+ logger_1.logger.debug(`[${this.deviceName}] Getting outlet status`);
109
+ await this.getDetails();
110
+ return this.deviceStatus;
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
+ }
127
+ /**
128
+ * Get weekly energy data
129
+ */
130
+ async getWeeklyEnergy() {
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));
142
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
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)}`);
148
+ }
149
+ }
150
+ /**
151
+ * Get monthly energy data
152
+ */
153
+ async getMonthlyEnergy() {
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));
165
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
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)}`);
171
+ }
172
+ }
173
+ /**
174
+ * Get yearly energy data
175
+ */
176
+ async getYearlyEnergy() {
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));
188
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
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)}`);
194
+ }
195
+ }
196
+ /**
197
+ * Update outlet details and energy info
198
+ */
199
+ async update() {
200
+ logger_1.logger.debug(`[${this.deviceName}] Updating outlet information`);
201
+ await this.getDetails();
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');
212
+ }
213
+ }
214
+ exports.VeSyncOutlet = VeSyncOutlet;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * VeSync Outlet Implementations
3
+ */
4
+ import { VeSyncOutlet } from './vesyncOutlet';
5
+ import { VeSync } from './vesync';
6
+ /**
7
+ * VeSync 7A Outlet
8
+ */
9
+ export declare class VeSyncOutlet7A extends VeSyncOutlet {
10
+ constructor(details: Record<string, any>, manager: VeSync);
11
+ /**
12
+ * Turn outlet on
13
+ */
14
+ turnOn(): Promise<boolean>;
15
+ /**
16
+ * Turn outlet off
17
+ */
18
+ turnOff(): Promise<boolean>;
19
+ }
20
+ /**
21
+ * VeSync 10A Outlet
22
+ */
23
+ export declare class VeSyncOutlet10A extends VeSyncOutlet {
24
+ constructor(details: Record<string, any>, manager: VeSync);
25
+ /**
26
+ * Turn outlet on
27
+ */
28
+ turnOn(): Promise<boolean>;
29
+ /**
30
+ * Turn outlet off
31
+ */
32
+ turnOff(): Promise<boolean>;
33
+ }
34
+ /**
35
+ * VeSync 15A Outlet
36
+ */
37
+ export declare class VeSyncOutlet15A extends VeSyncOutlet {
38
+ constructor(details: Record<string, any>, manager: VeSync);
39
+ /**
40
+ * Turn outlet on
41
+ */
42
+ turnOn(): Promise<boolean>;
43
+ /**
44
+ * Turn outlet off
45
+ */
46
+ turnOff(): Promise<boolean>;
47
+ /**
48
+ * Turn on nightlight
49
+ */
50
+ turnOnNightlight(): Promise<boolean>;
51
+ /**
52
+ * Turn off nightlight
53
+ */
54
+ turnOffNightlight(): Promise<boolean>;
55
+ }
56
+ /**
57
+ * VeSync Outdoor Plug
58
+ */
59
+ export declare class VeSyncOutdoorPlug extends VeSyncOutlet {
60
+ constructor(details: Record<string, any>, manager: VeSync);
61
+ /**
62
+ * Turn outlet on
63
+ */
64
+ turnOn(): Promise<boolean>;
65
+ /**
66
+ * Turn outlet off
67
+ */
68
+ turnOff(): Promise<boolean>;
69
+ }
70
+ export declare const outletModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncOutlet>;
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * VeSync Outlet Implementations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.outletModules = exports.VeSyncOutdoorPlug = exports.VeSyncOutlet15A = exports.VeSyncOutlet10A = exports.VeSyncOutlet7A = void 0;
7
+ const vesyncOutlet_1 = require("./vesyncOutlet");
8
+ const helpers_1 = require("./helpers");
9
+ const logger_1 = require("./logger");
10
+ /**
11
+ * VeSync 7A Outlet
12
+ */
13
+ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
14
+ constructor(details, manager) {
15
+ super(details, manager);
16
+ }
17
+ /**
18
+ * Turn outlet on
19
+ */
20
+ async turnOn() {
21
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
22
+ const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/on`;
23
+ const [response] = await helpers_1.Helpers.callApi(url, 'put', null, helpers_1.Helpers.reqHeaders(this.manager));
24
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
25
+ this.deviceStatus = 'on';
26
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
27
+ return true;
28
+ }
29
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
30
+ return false;
31
+ }
32
+ /**
33
+ * Turn outlet off
34
+ */
35
+ async turnOff() {
36
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
37
+ const url = `/v1/wifi-switch-1.3/wifi-switch-1.3-${this.cid}/status/off`;
38
+ const [response] = await helpers_1.Helpers.callApi(url, 'put', null, helpers_1.Helpers.reqHeaders(this.manager));
39
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
40
+ this.deviceStatus = 'off';
41
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
42
+ return true;
43
+ }
44
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
45
+ return false;
46
+ }
47
+ }
48
+ exports.VeSyncOutlet7A = VeSyncOutlet7A;
49
+ /**
50
+ * VeSync 10A Outlet
51
+ */
52
+ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
53
+ constructor(details, manager) {
54
+ super(details, manager);
55
+ }
56
+ /**
57
+ * Turn outlet on
58
+ */
59
+ async turnOn() {
60
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
61
+ const body = {
62
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
63
+ uuid: this.uuid,
64
+ status: 'on'
65
+ };
66
+ const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
67
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
68
+ this.deviceStatus = 'on';
69
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
70
+ return true;
71
+ }
72
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
73
+ return false;
74
+ }
75
+ /**
76
+ * Turn outlet off
77
+ */
78
+ async turnOff() {
79
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
80
+ const body = {
81
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
82
+ uuid: this.uuid,
83
+ status: 'off'
84
+ };
85
+ const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
86
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
87
+ this.deviceStatus = 'off';
88
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
89
+ return true;
90
+ }
91
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
92
+ return false;
93
+ }
94
+ }
95
+ exports.VeSyncOutlet10A = VeSyncOutlet10A;
96
+ /**
97
+ * VeSync 15A Outlet
98
+ */
99
+ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
100
+ constructor(details, manager) {
101
+ super(details, manager);
102
+ }
103
+ /**
104
+ * Turn outlet on
105
+ */
106
+ async turnOn() {
107
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
108
+ const body = {
109
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
110
+ uuid: this.uuid,
111
+ status: 'on'
112
+ };
113
+ const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
114
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
115
+ this.deviceStatus = 'on';
116
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
117
+ return true;
118
+ }
119
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
120
+ return false;
121
+ }
122
+ /**
123
+ * Turn outlet off
124
+ */
125
+ async turnOff() {
126
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
127
+ const body = {
128
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
129
+ uuid: this.uuid,
130
+ status: 'off'
131
+ };
132
+ const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
133
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
134
+ this.deviceStatus = 'off';
135
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
136
+ return true;
137
+ }
138
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
139
+ return false;
140
+ }
141
+ /**
142
+ * Turn on nightlight
143
+ */
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`);
150
+ const body = {
151
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
152
+ uuid: this.uuid,
153
+ mode: 'auto'
154
+ };
155
+ const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
156
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
157
+ this.details.nightLightStatus = 'on';
158
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned nightlight on`);
159
+ return true;
160
+ }
161
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight on: ${JSON.stringify(response)}`);
162
+ return false;
163
+ }
164
+ /**
165
+ * Turn off nightlight
166
+ */
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`);
173
+ const body = {
174
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
175
+ uuid: this.uuid,
176
+ mode: 'manual'
177
+ };
178
+ const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
179
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
180
+ this.details.nightLightStatus = 'off';
181
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned nightlight off`);
182
+ return true;
183
+ }
184
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight off: ${JSON.stringify(response)}`);
185
+ return false;
186
+ }
187
+ }
188
+ exports.VeSyncOutlet15A = VeSyncOutlet15A;
189
+ /**
190
+ * VeSync Outdoor Plug
191
+ */
192
+ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
193
+ constructor(details, manager) {
194
+ super(details, manager);
195
+ }
196
+ /**
197
+ * Turn outlet on
198
+ */
199
+ async turnOn() {
200
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
201
+ const body = {
202
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
203
+ uuid: this.uuid,
204
+ status: 'on',
205
+ switchNo: 1
206
+ };
207
+ const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
208
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
209
+ this.deviceStatus = 'on';
210
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet on`);
211
+ return true;
212
+ }
213
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
214
+ return false;
215
+ }
216
+ /**
217
+ * Turn outlet off
218
+ */
219
+ async turnOff() {
220
+ logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
221
+ const body = {
222
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
223
+ uuid: this.uuid,
224
+ status: 'off',
225
+ switchNo: 1
226
+ };
227
+ const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
228
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
229
+ this.deviceStatus = 'off';
230
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned outlet off`);
231
+ return true;
232
+ }
233
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
234
+ return false;
235
+ }
236
+ }
237
+ exports.VeSyncOutdoorPlug = VeSyncOutdoorPlug;
238
+ // Export outlet modules dictionary
239
+ exports.outletModules = {
240
+ 'wifi-switch-1.3': VeSyncOutlet7A,
241
+ 'ESW03-USA': VeSyncOutlet10A,
242
+ 'ESW01-EU': VeSyncOutlet10A,
243
+ 'ESW15-USA': VeSyncOutlet15A,
244
+ 'ESO15-TB': VeSyncOutdoorPlug
245
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * VeSync Switch Classes
3
+ */
4
+ import { VeSyncBaseDevice } from './vesyncBaseDevice';
5
+ import { VeSync } from './vesync';
6
+ interface SwitchConfig {
7
+ [key: string]: {
8
+ module: string;
9
+ features: string[];
10
+ };
11
+ }
12
+ export declare const switchConfig: SwitchConfig;
13
+ /**
14
+ * Base class for VeSync Switches
15
+ */
16
+ export declare abstract class VeSyncSwitch extends VeSyncBaseDevice {
17
+ protected details: Record<string, any>;
18
+ protected features: string[];
19
+ constructor(details: Record<string, any>, manager: VeSync);
20
+ /**
21
+ * Get active time of switch
22
+ */
23
+ get activeTime(): number;
24
+ /**
25
+ * Return true if switch is dimmable
26
+ */
27
+ isDimmable(): boolean;
28
+ /**
29
+ * Return formatted device info to stdout
30
+ */
31
+ display(): void;
32
+ /**
33
+ * Return JSON details for switch
34
+ */
35
+ displayJSON(): string;
36
+ abstract getDetails(): Promise<void>;
37
+ abstract getConfig(): Promise<void>;
38
+ abstract turnOn(): Promise<boolean>;
39
+ abstract turnOff(): Promise<boolean>;
40
+ /**
41
+ * Update device details
42
+ */
43
+ update(): Promise<void>;
44
+ }
45
+ export {};