tsvesync 1.0.11 → 1.0.12
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/index.d.ts +7 -0
- package/dist/index.js +25 -0
- package/dist/lib/helpers.d.ts +52 -51
- package/dist/lib/helpers.js +134 -112
- package/dist/lib/vesync.d.ts +57 -15
- package/dist/lib/vesync.js +339 -216
- package/dist/lib/vesyncBaseDevice.d.ts +25 -50
- package/dist/lib/vesyncBaseDevice.js +62 -90
- package/dist/lib/vesyncBulb.d.ts +79 -0
- package/dist/lib/vesyncBulb.js +198 -1
- package/dist/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/lib/vesyncBulbImpl.js +161 -0
- package/dist/lib/vesyncFan.d.ts +55 -67
- package/dist/lib/vesyncFan.js +365 -213
- package/dist/lib/vesyncFanImpl.d.ts +137 -0
- package/dist/lib/vesyncFanImpl.js +644 -0
- package/dist/lib/vesyncOutlet.d.ts +53 -0
- package/dist/lib/vesyncOutlet.js +97 -1
- package/dist/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/lib/vesyncOutletImpl.js +206 -0
- package/dist/lib/vesyncSwitch.d.ts +169 -0
- package/dist/lib/vesyncSwitch.js +417 -1
- package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/lib/vesyncSwitchImpl.js +290 -0
- package/package.json +1 -1
- package/src/index.ts +14 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* VeSync Switch Implementations
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.switchModules = exports.VeSyncDimmerSwitch = exports.VeSyncWallSwitch = void 0;
|
|
7
|
+
const vesyncSwitch_1 = require("./vesyncSwitch");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
/**
|
|
10
|
+
* Basic Wall Switch Implementation (ESWL01, ESWL03)
|
|
11
|
+
*/
|
|
12
|
+
class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
13
|
+
constructor(details, manager) {
|
|
14
|
+
super(details, manager);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get wall switch details
|
|
18
|
+
*/
|
|
19
|
+
async getDetails() {
|
|
20
|
+
const body = {
|
|
21
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
22
|
+
uuid: this.cid,
|
|
23
|
+
method: 'devicedetail'
|
|
24
|
+
};
|
|
25
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
26
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
27
|
+
const result = response.result;
|
|
28
|
+
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
29
|
+
this.details.active_time = result.activeTime || 0;
|
|
30
|
+
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get switch device configuration info
|
|
35
|
+
*/
|
|
36
|
+
async getConfig() {
|
|
37
|
+
const body = {
|
|
38
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
39
|
+
method: 'configurations',
|
|
40
|
+
uuid: this.cid
|
|
41
|
+
};
|
|
42
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
43
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
44
|
+
this.config = helpers_1.Helpers.buildConfigDict(response);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Turn off wall switch
|
|
49
|
+
*/
|
|
50
|
+
async turnOff() {
|
|
51
|
+
const body = {
|
|
52
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
53
|
+
status: 'off',
|
|
54
|
+
uuid: this.cid
|
|
55
|
+
};
|
|
56
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
57
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
58
|
+
this.deviceStatus = 'off';
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Turn on wall switch
|
|
65
|
+
*/
|
|
66
|
+
async turnOn() {
|
|
67
|
+
const body = {
|
|
68
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
69
|
+
status: 'on',
|
|
70
|
+
uuid: this.cid
|
|
71
|
+
};
|
|
72
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
73
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
74
|
+
this.deviceStatus = 'on';
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.VeSyncWallSwitch = VeSyncWallSwitch;
|
|
81
|
+
/**
|
|
82
|
+
* Dimmer Switch Implementation (ESWD16)
|
|
83
|
+
*/
|
|
84
|
+
class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
85
|
+
constructor(details, manager) {
|
|
86
|
+
super(details, manager);
|
|
87
|
+
this._brightness = 0;
|
|
88
|
+
this._rgbValue = { red: 0, blue: 0, green: 0 };
|
|
89
|
+
this._rgbStatus = 'unknown';
|
|
90
|
+
this._indicatorLight = 'unknown';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get dimmer switch details
|
|
94
|
+
*/
|
|
95
|
+
async getDetails() {
|
|
96
|
+
const body = {
|
|
97
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
98
|
+
uuid: this.cid,
|
|
99
|
+
method: 'devicedetail'
|
|
100
|
+
};
|
|
101
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
102
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
103
|
+
const result = response.result;
|
|
104
|
+
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
105
|
+
this.details.active_time = result.activeTime || 0;
|
|
106
|
+
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
107
|
+
this._brightness = result.brightness || this._brightness;
|
|
108
|
+
this._rgbStatus = result.rgbStatus || this._rgbStatus;
|
|
109
|
+
this._indicatorLight = result.indicatorlightStatus || this._indicatorLight;
|
|
110
|
+
if (result.rgbValue) {
|
|
111
|
+
this._rgbValue = {
|
|
112
|
+
red: result.rgbValue.red || 0,
|
|
113
|
+
green: result.rgbValue.green || 0,
|
|
114
|
+
blue: result.rgbValue.blue || 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get dimmer switch configuration info
|
|
121
|
+
*/
|
|
122
|
+
async getConfig() {
|
|
123
|
+
const body = {
|
|
124
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
125
|
+
method: 'configurations',
|
|
126
|
+
uuid: this.cid
|
|
127
|
+
};
|
|
128
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
129
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
130
|
+
this.config = helpers_1.Helpers.buildConfigDict(response);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Turn off dimmer switch
|
|
135
|
+
*/
|
|
136
|
+
async turnOff() {
|
|
137
|
+
const body = {
|
|
138
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
139
|
+
status: 'off',
|
|
140
|
+
uuid: this.cid
|
|
141
|
+
};
|
|
142
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
143
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
144
|
+
this.deviceStatus = 'off';
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Turn on dimmer switch
|
|
151
|
+
*/
|
|
152
|
+
async turnOn() {
|
|
153
|
+
const body = {
|
|
154
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
155
|
+
status: 'on',
|
|
156
|
+
uuid: this.cid
|
|
157
|
+
};
|
|
158
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
159
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
160
|
+
this.deviceStatus = 'on';
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Set brightness level
|
|
167
|
+
*/
|
|
168
|
+
async setBrightness(brightness) {
|
|
169
|
+
if (!this.isDimmable()) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
const body = {
|
|
173
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
174
|
+
brightness: brightness.toString(),
|
|
175
|
+
uuid: this.cid
|
|
176
|
+
};
|
|
177
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
178
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
179
|
+
this._brightness = brightness;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Set RGB indicator color
|
|
186
|
+
*/
|
|
187
|
+
async rgbColorSet(red, green, blue) {
|
|
188
|
+
const body = {
|
|
189
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
190
|
+
rgbValue: {
|
|
191
|
+
red: Math.round(red),
|
|
192
|
+
green: Math.round(green),
|
|
193
|
+
blue: Math.round(blue)
|
|
194
|
+
},
|
|
195
|
+
status: 'on',
|
|
196
|
+
uuid: this.cid
|
|
197
|
+
};
|
|
198
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
199
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
200
|
+
this._rgbValue = { red, green, blue };
|
|
201
|
+
this._rgbStatus = 'on';
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Turn on RGB indicator
|
|
208
|
+
*/
|
|
209
|
+
async rgbColorOn() {
|
|
210
|
+
const body = {
|
|
211
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
212
|
+
status: 'on',
|
|
213
|
+
uuid: this.cid
|
|
214
|
+
};
|
|
215
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
216
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
217
|
+
this._rgbStatus = 'on';
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Turn off RGB indicator
|
|
224
|
+
*/
|
|
225
|
+
async rgbColorOff() {
|
|
226
|
+
const body = {
|
|
227
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
228
|
+
status: 'off',
|
|
229
|
+
uuid: this.cid
|
|
230
|
+
};
|
|
231
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
232
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
233
|
+
this._rgbStatus = 'off';
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Turn on indicator light
|
|
240
|
+
*/
|
|
241
|
+
async indicatorLightOn() {
|
|
242
|
+
const body = {
|
|
243
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
244
|
+
status: 'on',
|
|
245
|
+
uuid: this.cid
|
|
246
|
+
};
|
|
247
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
248
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
249
|
+
this._indicatorLight = 'on';
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Turn off indicator light
|
|
256
|
+
*/
|
|
257
|
+
async indicatorLightOff() {
|
|
258
|
+
const body = {
|
|
259
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
260
|
+
status: 'off',
|
|
261
|
+
uuid: this.cid
|
|
262
|
+
};
|
|
263
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
264
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
265
|
+
this._indicatorLight = 'off';
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
// Getters
|
|
271
|
+
get brightness() {
|
|
272
|
+
return this._brightness;
|
|
273
|
+
}
|
|
274
|
+
get indicatorLightStatus() {
|
|
275
|
+
return this._indicatorLight;
|
|
276
|
+
}
|
|
277
|
+
get rgbLightStatus() {
|
|
278
|
+
return this._rgbStatus;
|
|
279
|
+
}
|
|
280
|
+
get rgbLightValue() {
|
|
281
|
+
return { ...this._rgbValue };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.VeSyncDimmerSwitch = VeSyncDimmerSwitch;
|
|
285
|
+
// Export the switch modules dictionary
|
|
286
|
+
exports.switchModules = {
|
|
287
|
+
'ESWL01': VeSyncWallSwitch,
|
|
288
|
+
'ESWL03': VeSyncWallSwitch,
|
|
289
|
+
'ESWD16': VeSyncDimmerSwitch
|
|
290
|
+
};
|
package/package.json
CHANGED
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Export main VeSync manager class
|
|
2
|
+
export { VeSync } from './lib/vesync';
|
|
3
|
+
|
|
4
|
+
// Export device classes
|
|
5
|
+
export { VeSyncAirBypass } from './lib/vesyncFanImpl';
|
|
6
|
+
export { VeSyncOutlet7A, VeSyncOutlet10A, VeSyncOutlet15A, VeSyncOutdoorPlug } from './lib/vesyncOutletImpl';
|
|
7
|
+
export { VeSyncBulb } from './lib/vesyncBulb';
|
|
8
|
+
export { VeSyncWallSwitch } from './lib/vesyncSwitchImpl';
|
|
9
|
+
|
|
10
|
+
// Export base device class
|
|
11
|
+
export { VeSyncBaseDevice } from './lib/vesyncBaseDevice';
|
|
12
|
+
|
|
13
|
+
// Export helper functions
|
|
14
|
+
export { Helpers, setApiBaseUrl } from './lib/helpers';
|