tsvesync 1.0.41 → 1.0.42
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/vesyncFanImpl.d.ts +12 -4
- package/dist/lib/vesyncFanImpl.js +81 -18
- package/package.json +1 -1
- package/src/lib/vesyncFanImpl.ts +89 -18
|
@@ -12,6 +12,10 @@ export declare class VeSyncAirBypass extends VeSyncFan {
|
|
|
12
12
|
protected readonly displayModes: readonly ["on", "off"];
|
|
13
13
|
protected readonly childLockModes: readonly ["on", "off"];
|
|
14
14
|
constructor(details: Record<string, any>, manager: VeSync);
|
|
15
|
+
/**
|
|
16
|
+
* Build API dictionary
|
|
17
|
+
*/
|
|
18
|
+
protected buildApiDict(method: string): [Record<string, any>, Record<string, any>];
|
|
15
19
|
/**
|
|
16
20
|
* Get device details
|
|
17
21
|
*/
|
|
@@ -57,17 +61,21 @@ export declare class VeSyncAirBypass extends VeSyncFan {
|
|
|
57
61
|
*/
|
|
58
62
|
automaticStopOff(): Promise<boolean>;
|
|
59
63
|
/**
|
|
60
|
-
* Set
|
|
64
|
+
* Set mode
|
|
61
65
|
*/
|
|
62
|
-
|
|
66
|
+
mode_toggle(mode: string): Promise<boolean>;
|
|
63
67
|
/**
|
|
64
68
|
* Set manual mode
|
|
65
69
|
*/
|
|
66
|
-
|
|
70
|
+
manual_mode(): Promise<boolean>;
|
|
67
71
|
/**
|
|
68
72
|
* Set sleep mode
|
|
69
73
|
*/
|
|
70
|
-
|
|
74
|
+
sleep_mode(): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Set auto mode
|
|
77
|
+
*/
|
|
78
|
+
auto_mode(): Promise<boolean>;
|
|
71
79
|
/**
|
|
72
80
|
* Turn off display
|
|
73
81
|
*/
|
|
@@ -19,6 +19,23 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
19
19
|
this.childLockModes = ['on', 'off'];
|
|
20
20
|
logger_1.logger.debug(`Initialized VeSyncAirBypass device: ${this.deviceName}`);
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Build API dictionary
|
|
24
|
+
*/
|
|
25
|
+
buildApiDict(method) {
|
|
26
|
+
const head = helpers_1.Helpers.reqHeaderBypass();
|
|
27
|
+
const body = {
|
|
28
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
29
|
+
deviceId: this.cid,
|
|
30
|
+
configModule: this.configModule,
|
|
31
|
+
payload: {
|
|
32
|
+
method,
|
|
33
|
+
source: 'APP',
|
|
34
|
+
data: {}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return [head, body];
|
|
38
|
+
}
|
|
22
39
|
/**
|
|
23
40
|
* Get device details
|
|
24
41
|
*/
|
|
@@ -406,37 +423,79 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
406
423
|
return success;
|
|
407
424
|
}
|
|
408
425
|
/**
|
|
409
|
-
* Set
|
|
426
|
+
* Set mode
|
|
410
427
|
*/
|
|
411
|
-
async
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
428
|
+
async mode_toggle(mode) {
|
|
429
|
+
if (!this.modes.includes(mode.toLowerCase())) {
|
|
430
|
+
logger_1.logger.debug(`Invalid purifier mode used - ${mode}`);
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
const [head, body] = this.buildApiDict('setPurifierMode');
|
|
434
|
+
if (!head || !body) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
if (mode === 'manual') {
|
|
438
|
+
body.payload = {
|
|
439
|
+
data: {
|
|
440
|
+
id: 0,
|
|
441
|
+
level: 1,
|
|
442
|
+
type: 'wind'
|
|
443
|
+
},
|
|
444
|
+
method: 'setLevel',
|
|
445
|
+
type: 'APP'
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
body.payload.data = {
|
|
450
|
+
mode: mode.toLowerCase()
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, head);
|
|
454
|
+
const success = this.checkResponse([response, status], 'mode_toggle');
|
|
455
|
+
if (success) {
|
|
456
|
+
if (mode === 'manual') {
|
|
457
|
+
this.details.speed = 1;
|
|
458
|
+
this.details.mode = 'manual';
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
this.details.mode = mode;
|
|
462
|
+
this.details.speed = 0;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
logger_1.logger.debug('Error setting purifier mode');
|
|
416
467
|
}
|
|
417
468
|
return success;
|
|
418
469
|
}
|
|
419
470
|
/**
|
|
420
471
|
* Set manual mode
|
|
421
472
|
*/
|
|
422
|
-
async
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
logger_1.logger.error(`Failed to set manual mode for device: ${this.deviceName}`);
|
|
473
|
+
async manual_mode() {
|
|
474
|
+
if (!this.modes.includes('manual')) {
|
|
475
|
+
logger_1.logger.debug(`${this.deviceName} does not have manual mode`);
|
|
476
|
+
return false;
|
|
427
477
|
}
|
|
428
|
-
return
|
|
478
|
+
return this.mode_toggle('manual');
|
|
429
479
|
}
|
|
430
480
|
/**
|
|
431
481
|
* Set sleep mode
|
|
432
482
|
*/
|
|
433
|
-
async
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
logger_1.logger.error(`Failed to set sleep mode for device: ${this.deviceName}`);
|
|
483
|
+
async sleep_mode() {
|
|
484
|
+
if (!this.modes.includes('sleep')) {
|
|
485
|
+
logger_1.logger.debug(`${this.deviceName} does not have sleep mode`);
|
|
486
|
+
return false;
|
|
438
487
|
}
|
|
439
|
-
return
|
|
488
|
+
return this.mode_toggle('sleep');
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Set auto mode
|
|
492
|
+
*/
|
|
493
|
+
async auto_mode() {
|
|
494
|
+
if (!this.modes.includes('auto')) {
|
|
495
|
+
logger_1.logger.debug(`${this.deviceName} does not have auto mode`);
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
return this.mode_toggle('auto');
|
|
440
499
|
}
|
|
441
500
|
/**
|
|
442
501
|
* Turn off display
|
|
@@ -1167,6 +1226,10 @@ class VeSyncAirBaseV2 extends VeSyncAirBypass {
|
|
|
1167
1226
|
* Set auto mode
|
|
1168
1227
|
*/
|
|
1169
1228
|
async auto_mode() {
|
|
1229
|
+
if (!this.modes.includes('auto')) {
|
|
1230
|
+
logger_1.logger.debug(`${this.deviceName} does not have auto mode`);
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1170
1233
|
return this.mode_toggle('auto');
|
|
1171
1234
|
}
|
|
1172
1235
|
/**
|
package/package.json
CHANGED
package/src/lib/vesyncFanImpl.ts
CHANGED
|
@@ -21,6 +21,24 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
21
21
|
logger.debug(`Initialized VeSyncAirBypass device: ${this.deviceName}`);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Build API dictionary
|
|
26
|
+
*/
|
|
27
|
+
protected buildApiDict(method: string): [Record<string, any>, Record<string, any>] {
|
|
28
|
+
const head = Helpers.reqHeaderBypass();
|
|
29
|
+
const body = {
|
|
30
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
31
|
+
deviceId: this.cid,
|
|
32
|
+
configModule: this.configModule,
|
|
33
|
+
payload: {
|
|
34
|
+
method,
|
|
35
|
+
source: 'APP',
|
|
36
|
+
data: {}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return [head, body];
|
|
40
|
+
}
|
|
41
|
+
|
|
24
42
|
/**
|
|
25
43
|
* Get device details
|
|
26
44
|
*/
|
|
@@ -515,13 +533,53 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
515
533
|
}
|
|
516
534
|
|
|
517
535
|
/**
|
|
518
|
-
* Set
|
|
536
|
+
* Set mode
|
|
519
537
|
*/
|
|
520
|
-
async
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
538
|
+
async mode_toggle(mode: string): Promise<boolean> {
|
|
539
|
+
if (!this.modes.includes(mode.toLowerCase() as any)) {
|
|
540
|
+
logger.debug(`Invalid purifier mode used - ${mode}`);
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const [head, body] = this.buildApiDict('setPurifierMode');
|
|
545
|
+
if (!head || !body) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (mode === 'manual') {
|
|
550
|
+
body.payload = {
|
|
551
|
+
data: {
|
|
552
|
+
id: 0,
|
|
553
|
+
level: 1,
|
|
554
|
+
type: 'wind'
|
|
555
|
+
},
|
|
556
|
+
method: 'setLevel',
|
|
557
|
+
type: 'APP'
|
|
558
|
+
};
|
|
559
|
+
} else {
|
|
560
|
+
body.payload.data = {
|
|
561
|
+
mode: mode.toLowerCase()
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const [response, status] = await this.callApi(
|
|
566
|
+
'/cloud/v2/deviceManaged/bypassV2',
|
|
567
|
+
'post',
|
|
568
|
+
body,
|
|
569
|
+
head
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
const success = this.checkResponse([response, status], 'mode_toggle');
|
|
573
|
+
if (success) {
|
|
574
|
+
if (mode === 'manual') {
|
|
575
|
+
this.details.speed = 1;
|
|
576
|
+
this.details.mode = 'manual';
|
|
577
|
+
} else {
|
|
578
|
+
this.details.mode = mode;
|
|
579
|
+
this.details.speed = 0;
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
logger.debug('Error setting purifier mode');
|
|
525
583
|
}
|
|
526
584
|
return success;
|
|
527
585
|
}
|
|
@@ -529,25 +587,34 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
529
587
|
/**
|
|
530
588
|
* Set manual mode
|
|
531
589
|
*/
|
|
532
|
-
async
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
logger.error(`Failed to set manual mode for device: ${this.deviceName}`);
|
|
590
|
+
async manual_mode(): Promise<boolean> {
|
|
591
|
+
if (!this.modes.includes('manual')) {
|
|
592
|
+
logger.debug(`${this.deviceName} does not have manual mode`);
|
|
593
|
+
return false;
|
|
537
594
|
}
|
|
538
|
-
return
|
|
595
|
+
return this.mode_toggle('manual');
|
|
539
596
|
}
|
|
540
597
|
|
|
541
598
|
/**
|
|
542
599
|
* Set sleep mode
|
|
543
600
|
*/
|
|
544
|
-
async
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
logger.error(`Failed to set sleep mode for device: ${this.deviceName}`);
|
|
601
|
+
async sleep_mode(): Promise<boolean> {
|
|
602
|
+
if (!this.modes.includes('sleep')) {
|
|
603
|
+
logger.debug(`${this.deviceName} does not have sleep mode`);
|
|
604
|
+
return false;
|
|
549
605
|
}
|
|
550
|
-
return
|
|
606
|
+
return this.mode_toggle('sleep');
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Set auto mode
|
|
611
|
+
*/
|
|
612
|
+
async auto_mode(): Promise<boolean> {
|
|
613
|
+
if (!this.modes.includes('auto')) {
|
|
614
|
+
logger.debug(`${this.deviceName} does not have auto mode`);
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
return this.mode_toggle('auto');
|
|
551
618
|
}
|
|
552
619
|
|
|
553
620
|
/**
|
|
@@ -1428,6 +1495,10 @@ export class VeSyncAirBaseV2 extends VeSyncAirBypass {
|
|
|
1428
1495
|
* Set auto mode
|
|
1429
1496
|
*/
|
|
1430
1497
|
async auto_mode(): Promise<boolean> {
|
|
1498
|
+
if (!this.modes.includes('auto')) {
|
|
1499
|
+
logger.debug(`${this.deviceName} does not have auto mode`);
|
|
1500
|
+
return false;
|
|
1501
|
+
}
|
|
1431
1502
|
return this.mode_toggle('auto');
|
|
1432
1503
|
}
|
|
1433
1504
|
|