tsvesync 1.0.73 → 1.0.74

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.
@@ -0,0 +1,68 @@
1
+ import { VeSyncFan } from '../vesyncFan';
2
+ import { VeSync } from '../vesync';
3
+ /**
4
+ * VeSync Air Purifier 131 Series (LV-PUR131S, LV-RH131S)
5
+ * This class implements the specific API for LV series devices
6
+ */
7
+ export declare class VeSyncAir131 extends VeSyncFan {
8
+ protected readonly modes: readonly ["auto", "manual", "sleep"];
9
+ protected readonly displayModes: readonly ["on", "off"];
10
+ protected readonly childLockModes: readonly ["on", "off"];
11
+ constructor(details: Record<string, any>, manager: VeSync);
12
+ /**
13
+ * Get device details
14
+ */
15
+ getDetails(): Promise<Boolean>;
16
+ /**
17
+ * Turn device on
18
+ */
19
+ turnOn(): Promise<boolean>;
20
+ /**
21
+ * Turn device off
22
+ */
23
+ turnOff(): Promise<boolean>;
24
+ /**
25
+ * Change fan speed
26
+ */
27
+ changeFanSpeed(speed: number): Promise<boolean>;
28
+ /**
29
+ * Set device mode
30
+ */
31
+ setMode(mode: string): Promise<boolean>;
32
+ /**
33
+ * Set display status
34
+ */
35
+ setDisplay(enabled: boolean): Promise<boolean>;
36
+ /**
37
+ * Set child lock
38
+ */
39
+ setChildLock(enabled: boolean): Promise<boolean>;
40
+ /**
41
+ * Set timer
42
+ */
43
+ setTimer(hours: number): Promise<boolean>;
44
+ /**
45
+ * Clear timer
46
+ */
47
+ clearTimer(): Promise<boolean>;
48
+ /**
49
+ * Set auto mode
50
+ */
51
+ autoMode(): Promise<boolean>;
52
+ /**
53
+ * Set manual mode
54
+ */
55
+ manualMode(): Promise<boolean>;
56
+ /**
57
+ * Set sleep mode
58
+ */
59
+ sleepMode(): Promise<boolean>;
60
+ /**
61
+ * Turn off display
62
+ */
63
+ turnOffDisplay(): Promise<boolean>;
64
+ /**
65
+ * Turn on display
66
+ */
67
+ turnOnDisplay(): Promise<boolean>;
68
+ }
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VeSyncAir131 = void 0;
4
+ const vesyncFan_1 = require("../vesyncFan");
5
+ const logger_1 = require("../logger");
6
+ /**
7
+ * VeSync Air Purifier 131 Series (LV-PUR131S, LV-RH131S)
8
+ * This class implements the specific API for LV series devices
9
+ */
10
+ class VeSyncAir131 extends vesyncFan_1.VeSyncFan {
11
+ constructor(details, manager) {
12
+ super(details, manager);
13
+ this.modes = ['auto', 'manual', 'sleep'];
14
+ this.displayModes = ['on', 'off'];
15
+ this.childLockModes = ['on', 'off'];
16
+ logger_1.logger.debug(`Initialized VeSyncAir131 device: ${this.deviceName}`);
17
+ }
18
+ /**
19
+ * Get device details
20
+ */
21
+ async getDetails() {
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
23
+ logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
24
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/devicedetail', 'post', {
25
+ acceptLanguage: 'en',
26
+ accountID: this.manager.accountId,
27
+ appVersion: '2.8.6',
28
+ method: 'devicedetail',
29
+ mobileId: '1234567890123456',
30
+ phoneBrand: 'SM N9005',
31
+ phoneOS: 'Android',
32
+ timeZone: this.manager.timeZone,
33
+ token: this.manager.token,
34
+ uuid: this.uuid
35
+ }, {
36
+ 'accept-language': 'en',
37
+ 'accountId': this.manager.accountId,
38
+ 'appVersion': '2.8.6',
39
+ 'content-type': 'application/json',
40
+ 'tk': this.manager.token,
41
+ 'tz': this.manager.timeZone
42
+ });
43
+ const success = this.checkResponse([response, status], 'getDetails');
44
+ if (success && response) {
45
+ this.deviceStatus = ((_b = (_a = response.result) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.deviceStatus) === 'on' ? 'on' : 'off';
46
+ this.details = {
47
+ mode: ((_d = (_c = response.result) === null || _c === void 0 ? void 0 : _c.result) === null || _d === void 0 ? void 0 : _d.mode) || '',
48
+ speed: ((_f = (_e = response.result) === null || _e === void 0 ? void 0 : _e.result) === null || _f === void 0 ? void 0 : _f.level) || 0,
49
+ filterLife: ((_h = (_g = response.result) === null || _g === void 0 ? void 0 : _g.result) === null || _h === void 0 ? void 0 : _h.filterLife) || 0,
50
+ screenStatus: ((_k = (_j = response.result) === null || _j === void 0 ? void 0 : _j.result) === null || _k === void 0 ? void 0 : _k.display) ? 'on' : 'off',
51
+ childLock: ((_m = (_l = response.result) === null || _l === void 0 ? void 0 : _l.result) === null || _m === void 0 ? void 0 : _m.childLock) || false,
52
+ airQuality: ((_p = (_o = response.result) === null || _o === void 0 ? void 0 : _o.result) === null || _p === void 0 ? void 0 : _p.airQuality) || 0
53
+ };
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ /**
59
+ * Turn device on
60
+ */
61
+ async turnOn() {
62
+ logger_1.logger.info(`Turning on device: ${this.deviceName}`);
63
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/deviceStatus', 'put', {
64
+ acceptLanguage: 'en',
65
+ accountID: this.manager.accountId,
66
+ status: 'on',
67
+ timeZone: this.manager.timeZone,
68
+ token: this.manager.token,
69
+ uuid: this.uuid
70
+ }, {
71
+ 'accept-language': 'en',
72
+ 'accountId': this.manager.accountId,
73
+ 'appVersion': '2.8.6',
74
+ 'content-type': 'application/json',
75
+ 'tk': this.manager.token,
76
+ 'tz': this.manager.timeZone
77
+ });
78
+ const success = this.checkResponse([response, status], 'turnOn');
79
+ if (!success) {
80
+ logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
81
+ }
82
+ return success;
83
+ }
84
+ /**
85
+ * Turn device off
86
+ */
87
+ async turnOff() {
88
+ logger_1.logger.info(`Turning off device: ${this.deviceName}`);
89
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/deviceStatus', 'put', {
90
+ acceptLanguage: 'en',
91
+ accountID: this.manager.accountId,
92
+ status: 'off',
93
+ timeZone: this.manager.timeZone,
94
+ token: this.manager.token,
95
+ uuid: this.uuid
96
+ }, {
97
+ 'accept-language': 'en',
98
+ 'accountId': this.manager.accountId,
99
+ 'appVersion': '2.8.6',
100
+ 'content-type': 'application/json',
101
+ 'tk': this.manager.token,
102
+ 'tz': this.manager.timeZone
103
+ });
104
+ const success = this.checkResponse([response, status], 'turnOff');
105
+ if (!success) {
106
+ logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
107
+ }
108
+ return success;
109
+ }
110
+ /**
111
+ * Change fan speed
112
+ */
113
+ async changeFanSpeed(speed) {
114
+ logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
115
+ // Check if device is in manual mode
116
+ if (this.details.mode !== 'manual') {
117
+ logger_1.logger.debug(`${this.deviceName} not in manual mode, cannot change speed`);
118
+ return false;
119
+ }
120
+ // Validate speed for LV series (1-3)
121
+ if (speed < 1 || speed > 3) {
122
+ logger_1.logger.error(`Invalid fan speed: ${speed}. Must be between 1 and 3 for device: ${this.deviceName}`);
123
+ return false;
124
+ }
125
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/updateSpeed', 'put', {
126
+ acceptLanguage: 'en',
127
+ accountID: this.manager.accountId,
128
+ level: speed,
129
+ timeZone: this.manager.timeZone,
130
+ token: this.manager.token,
131
+ uuid: this.uuid
132
+ }, {
133
+ 'accept-language': 'en',
134
+ 'accountId': this.manager.accountId,
135
+ 'appVersion': '2.8.6',
136
+ 'content-type': 'application/json',
137
+ 'tk': this.manager.token,
138
+ 'tz': this.manager.timeZone
139
+ });
140
+ const success = this.checkResponse([response, status], 'changeFanSpeed');
141
+ if (success) {
142
+ this.details.speed = speed;
143
+ return true;
144
+ }
145
+ else {
146
+ logger_1.logger.error(`Failed to change fan speed to ${speed} for device: ${this.deviceName}`);
147
+ return false;
148
+ }
149
+ }
150
+ /**
151
+ * Set device mode
152
+ */
153
+ async setMode(mode) {
154
+ if (!this.modes.includes(mode)) {
155
+ const error = `Invalid mode: ${mode}. Must be one of: ${this.modes.join(', ')}`;
156
+ logger_1.logger.error(`${error} for device: ${this.deviceName}`);
157
+ throw new Error(error);
158
+ }
159
+ logger_1.logger.debug(`Setting mode to ${mode} for device: ${this.deviceName}`);
160
+ const payload = {
161
+ acceptLanguage: 'en',
162
+ accountID: this.manager.accountId,
163
+ mode: mode,
164
+ timeZone: this.manager.timeZone,
165
+ token: this.manager.token,
166
+ uuid: this.uuid
167
+ };
168
+ // For manual mode, we need to set the level
169
+ if (mode === 'manual') {
170
+ payload.level = this.details.speed || 1;
171
+ }
172
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/updateMode', 'put', payload, {
173
+ 'accept-language': 'en',
174
+ 'accountId': this.manager.accountId,
175
+ 'appVersion': '2.8.6',
176
+ 'content-type': 'application/json',
177
+ 'tk': this.manager.token,
178
+ 'tz': this.manager.timeZone
179
+ });
180
+ const success = this.checkResponse([response, status], 'setMode');
181
+ if (success) {
182
+ this.details.mode = mode;
183
+ return true;
184
+ }
185
+ else {
186
+ logger_1.logger.error(`Failed to set mode to ${mode} for device: ${this.deviceName}`);
187
+ return false;
188
+ }
189
+ }
190
+ /**
191
+ * Set display status
192
+ */
193
+ async setDisplay(enabled) {
194
+ if (!this.hasFeature('display')) {
195
+ const error = 'Display control not supported';
196
+ logger_1.logger.error(`${error} for device: ${this.deviceName}`);
197
+ throw new Error(error);
198
+ }
199
+ // Check if device is in sleep mode - display control may not work in sleep mode
200
+ if (this.details.mode === 'sleep') {
201
+ logger_1.logger.warn(`Device ${this.deviceName} is in sleep mode, display control may not work`);
202
+ }
203
+ logger_1.logger.debug(`Setting display to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
204
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/updateScreen', 'put', {
205
+ acceptLanguage: 'en',
206
+ accountID: this.manager.accountId,
207
+ status: enabled ? 'on' : 'off',
208
+ timeZone: this.manager.timeZone,
209
+ token: this.manager.token,
210
+ uuid: this.uuid
211
+ }, {
212
+ 'accept-language': 'en',
213
+ 'accountId': this.manager.accountId,
214
+ 'appVersion': '2.8.6',
215
+ 'content-type': 'application/json',
216
+ 'tk': this.manager.token,
217
+ 'tz': this.manager.timeZone
218
+ });
219
+ const success = this.checkResponse([response, status], 'setDisplay');
220
+ if (success) {
221
+ this.details.screenStatus = enabled ? 'on' : 'off';
222
+ return true;
223
+ }
224
+ else {
225
+ logger_1.logger.error(`Failed to set display to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
226
+ return false;
227
+ }
228
+ }
229
+ /**
230
+ * Set child lock
231
+ */
232
+ async setChildLock(enabled) {
233
+ if (!this.hasFeature('child_lock')) {
234
+ const error = 'Child lock not supported';
235
+ logger_1.logger.error(`${error} for device: ${this.deviceName}`);
236
+ throw new Error(error);
237
+ }
238
+ // Check if device is in sleep mode - child lock may not work in sleep mode
239
+ if (this.details.mode === 'sleep') {
240
+ logger_1.logger.warn(`Device ${this.deviceName} is in sleep mode, child lock control may not work`);
241
+ }
242
+ logger_1.logger.debug(`Setting child lock to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
243
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/updateChildLock', 'put', {
244
+ acceptLanguage: 'en',
245
+ accountID: this.manager.accountId,
246
+ status: enabled ? 'on' : 'off',
247
+ timeZone: this.manager.timeZone,
248
+ token: this.manager.token,
249
+ uuid: this.uuid
250
+ }, {
251
+ 'accept-language': 'en',
252
+ 'accountId': this.manager.accountId,
253
+ 'appVersion': '2.8.6',
254
+ 'content-type': 'application/json',
255
+ 'tk': this.manager.token,
256
+ 'tz': this.manager.timeZone
257
+ });
258
+ const success = this.checkResponse([response, status], 'setChildLock');
259
+ if (success) {
260
+ this.details.childLock = enabled;
261
+ return true;
262
+ }
263
+ else {
264
+ // Check for error code 11000000 (feature not supported)
265
+ if ((response === null || response === void 0 ? void 0 : response.code) === 11000000) {
266
+ logger_1.logger.warn(`Child lock control not supported via API for device: ${this.deviceName}`);
267
+ return false;
268
+ }
269
+ logger_1.logger.error(`Failed to set child lock to ${enabled ? 'on' : 'off'} for device: ${this.deviceName}`);
270
+ return false;
271
+ }
272
+ }
273
+ /**
274
+ * Set timer
275
+ */
276
+ async setTimer(hours) {
277
+ if (!this.hasFeature('timer')) {
278
+ const error = 'Timer not supported';
279
+ logger_1.logger.error(`${error} for device: ${this.deviceName}`);
280
+ throw new Error(error);
281
+ }
282
+ logger_1.logger.debug(`Setting timer to ${hours} hours for device: ${this.deviceName}`);
283
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/updateTimer', 'put', {
284
+ acceptLanguage: 'en',
285
+ accountID: this.manager.accountId,
286
+ action: 'off',
287
+ duration: hours,
288
+ timeZone: this.manager.timeZone,
289
+ token: this.manager.token,
290
+ uuid: this.uuid
291
+ }, {
292
+ 'accept-language': 'en',
293
+ 'accountId': this.manager.accountId,
294
+ 'appVersion': '2.8.6',
295
+ 'content-type': 'application/json',
296
+ 'tk': this.manager.token,
297
+ 'tz': this.manager.timeZone
298
+ });
299
+ const success = this.checkResponse([response, status], 'setTimer');
300
+ if (success) {
301
+ this.timer = { duration: hours * 3600, action: 'off' };
302
+ return true;
303
+ }
304
+ else {
305
+ logger_1.logger.error(`Failed to set timer to ${hours} hours for device: ${this.deviceName}`);
306
+ return false;
307
+ }
308
+ }
309
+ /**
310
+ * Clear timer
311
+ */
312
+ async clearTimer() {
313
+ if (!this.hasFeature('timer')) {
314
+ const error = 'Timer not supported';
315
+ logger_1.logger.error(`${error} for device: ${this.deviceName}`);
316
+ throw new Error(error);
317
+ }
318
+ // If no timer is set, return success
319
+ if (!this.timer) {
320
+ logger_1.logger.debug(`No timer to clear for device: ${this.deviceName}`);
321
+ return true;
322
+ }
323
+ logger_1.logger.debug(`Clearing timer for device: ${this.deviceName}`);
324
+ const [response, status] = await this.callApi('/131airPurifier/v1/device/cancelTimer', 'put', {
325
+ acceptLanguage: 'en',
326
+ accountID: this.manager.accountId,
327
+ timeZone: this.manager.timeZone,
328
+ token: this.manager.token,
329
+ uuid: this.uuid
330
+ }, {
331
+ 'accept-language': 'en',
332
+ 'accountId': this.manager.accountId,
333
+ 'appVersion': '2.8.6',
334
+ 'content-type': 'application/json',
335
+ 'tk': this.manager.token,
336
+ 'tz': this.manager.timeZone
337
+ });
338
+ const success = this.checkResponse([response, status], 'clearTimer');
339
+ if (success) {
340
+ this.timer = null;
341
+ return true;
342
+ }
343
+ else {
344
+ logger_1.logger.error(`Failed to clear timer for device: ${this.deviceName}`);
345
+ return false;
346
+ }
347
+ }
348
+ /**
349
+ * Set auto mode
350
+ */
351
+ async autoMode() {
352
+ logger_1.logger.debug(`Setting auto mode for device: ${this.deviceName}`);
353
+ const success = await this.setMode('auto');
354
+ if (!success) {
355
+ logger_1.logger.error(`Failed to set auto mode for device: ${this.deviceName}`);
356
+ }
357
+ return success;
358
+ }
359
+ /**
360
+ * Set manual mode
361
+ */
362
+ async manualMode() {
363
+ logger_1.logger.debug(`Setting manual mode for device: ${this.deviceName}`);
364
+ const success = await this.setMode('manual');
365
+ if (!success) {
366
+ logger_1.logger.error(`Failed to set manual mode for device: ${this.deviceName}`);
367
+ }
368
+ return success;
369
+ }
370
+ /**
371
+ * Set sleep mode
372
+ */
373
+ async sleepMode() {
374
+ logger_1.logger.debug(`Setting sleep mode for device: ${this.deviceName}`);
375
+ const success = await this.setMode('sleep');
376
+ if (!success) {
377
+ logger_1.logger.error(`Failed to set sleep mode for device: ${this.deviceName}`);
378
+ }
379
+ return success;
380
+ }
381
+ /**
382
+ * Turn off display
383
+ */
384
+ async turnOffDisplay() {
385
+ logger_1.logger.debug(`Turning off display for device: ${this.deviceName}`);
386
+ const success = await this.setDisplay(false);
387
+ if (!success) {
388
+ logger_1.logger.error(`Failed to turn off display for device: ${this.deviceName}`);
389
+ }
390
+ return success;
391
+ }
392
+ /**
393
+ * Turn on display
394
+ */
395
+ async turnOnDisplay() {
396
+ logger_1.logger.debug(`Turning on display for device: ${this.deviceName}`);
397
+ const success = await this.setDisplay(true);
398
+ if (!success) {
399
+ logger_1.logger.error(`Failed to turn on display for device: ${this.deviceName}`);
400
+ }
401
+ return success;
402
+ }
403
+ }
404
+ exports.VeSyncAir131 = VeSyncAir131;