tsvesync 1.0.26 → 1.0.28
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/vesyncBaseDevice.d.ts +2 -2
- package/dist/lib/vesyncBaseDevice.js +1 -1
- package/dist/lib/vesyncBulb.d.ts +3 -3
- package/dist/lib/vesyncBulb.js +7 -7
- package/dist/lib/vesyncFan.d.ts +1 -1
- package/dist/lib/vesyncFanImpl.d.ts +2 -2
- package/dist/lib/vesyncFanImpl.js +12 -14
- package/dist/lib/vesyncOutlet.d.ts +2 -2
- package/dist/lib/vesyncOutlet.js +10 -7
- package/dist/lib/vesyncSwitch.d.ts +8 -5
- package/dist/lib/vesyncSwitch.js +5 -2
- package/dist/lib/vesyncSwitchImpl.d.ts +2 -2
- package/dist/lib/vesyncSwitchImpl.js +12 -14
- package/package.json +1 -1
- package/src/lib/vesyncBaseDevice.ts +3 -3
- package/src/lib/vesyncBulb.ts +9 -8
- package/src/lib/vesyncFan.ts +1 -1
- package/src/lib/vesyncFanImpl.ts +13 -14
- package/src/lib/vesyncOutlet.ts +12 -9
- package/src/lib/vesyncSwitch.ts +14 -7
- package/src/lib/vesyncSwitchImpl.ts +14 -14
|
@@ -35,11 +35,11 @@ export declare abstract class VeSyncBaseDevice {
|
|
|
35
35
|
/**
|
|
36
36
|
* Get device details
|
|
37
37
|
*/
|
|
38
|
-
abstract getDetails(): Promise<
|
|
38
|
+
abstract getDetails(): Promise<Boolean>;
|
|
39
39
|
/**
|
|
40
40
|
* Update device details
|
|
41
41
|
*/
|
|
42
|
-
update(): Promise<
|
|
42
|
+
update(): Promise<Boolean>;
|
|
43
43
|
/**
|
|
44
44
|
* Call API with proper headers
|
|
45
45
|
*/
|
package/dist/lib/vesyncBulb.d.ts
CHANGED
|
@@ -31,11 +31,11 @@ export declare abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
31
31
|
/**
|
|
32
32
|
* Get bulb details
|
|
33
33
|
*/
|
|
34
|
-
getDetails(): Promise<
|
|
34
|
+
getDetails(): Promise<Boolean>;
|
|
35
35
|
/**
|
|
36
|
-
* Update bulb
|
|
36
|
+
* Update bulb details
|
|
37
37
|
*/
|
|
38
|
-
update(): Promise<
|
|
38
|
+
update(): Promise<Boolean>;
|
|
39
39
|
/**
|
|
40
40
|
* Turn bulb on
|
|
41
41
|
*/
|
package/dist/lib/vesyncBulb.js
CHANGED
|
@@ -74,8 +74,9 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
74
74
|
getLightStatus: 'get'
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
78
|
-
|
|
77
|
+
const [response, statusCode] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
78
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
79
|
+
if (success && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
79
80
|
this.deviceStatus = response.result.enabled ? 'on' : 'off';
|
|
80
81
|
this.brightness = response.result.brightness || this.brightness;
|
|
81
82
|
if (this.features.includes('color_temp')) {
|
|
@@ -97,17 +98,16 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
97
98
|
}
|
|
98
99
|
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
102
|
-
}
|
|
101
|
+
return success;
|
|
103
102
|
}
|
|
104
103
|
/**
|
|
105
|
-
* Update bulb
|
|
104
|
+
* Update bulb details
|
|
106
105
|
*/
|
|
107
106
|
async update() {
|
|
108
107
|
logger_1.logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
109
|
-
await this.getDetails();
|
|
108
|
+
const success = await this.getDetails();
|
|
110
109
|
logger_1.logger.info(`[${this.deviceName}] Successfully updated bulb information`);
|
|
110
|
+
return success;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* Turn bulb on
|
package/dist/lib/vesyncFan.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare abstract class VeSyncFan extends VeSyncBaseDevice {
|
|
|
71
71
|
* Return JSON details for fan
|
|
72
72
|
*/
|
|
73
73
|
displayJSON(): string;
|
|
74
|
-
abstract getDetails(): Promise<
|
|
74
|
+
abstract getDetails(): Promise<Boolean>;
|
|
75
75
|
abstract turnOn(): Promise<boolean>;
|
|
76
76
|
abstract turnOff(): Promise<boolean>;
|
|
77
77
|
abstract changeFanSpeed(speed: number): Promise<boolean>;
|
|
@@ -15,7 +15,7 @@ export declare class VeSyncAirBypass extends VeSyncFan {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get device details
|
|
17
17
|
*/
|
|
18
|
-
getDetails(): Promise<
|
|
18
|
+
getDetails(): Promise<Boolean>;
|
|
19
19
|
/**
|
|
20
20
|
* Turn device on
|
|
21
21
|
*/
|
|
@@ -93,7 +93,7 @@ export declare class VeSyncHumidifier extends VeSyncFan {
|
|
|
93
93
|
/**
|
|
94
94
|
* Get device details
|
|
95
95
|
*/
|
|
96
|
-
getDetails(): Promise<
|
|
96
|
+
getDetails(): Promise<Boolean>;
|
|
97
97
|
/**
|
|
98
98
|
* Turn device on
|
|
99
99
|
*/
|
|
@@ -35,7 +35,8 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
35
35
|
source: 'APP'
|
|
36
36
|
}
|
|
37
37
|
}, helpers_1.Helpers.reqHeaderBypass());
|
|
38
|
-
|
|
38
|
+
const success = this.checkResponse([response, status], 'getDetails');
|
|
39
|
+
if (success) {
|
|
39
40
|
const result = (_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result;
|
|
40
41
|
if (result) {
|
|
41
42
|
// Update device status
|
|
@@ -56,15 +57,13 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
56
57
|
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
61
|
-
}
|
|
60
|
+
return success;
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
63
|
* Turn device on
|
|
65
64
|
*/
|
|
66
65
|
async turnOn() {
|
|
67
|
-
logger_1.logger.
|
|
66
|
+
logger_1.logger.info(`Turning on device: ${this.deviceName}`);
|
|
68
67
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
69
68
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
70
69
|
cid: this.cid,
|
|
@@ -88,7 +87,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
88
87
|
* Turn device off
|
|
89
88
|
*/
|
|
90
89
|
async turnOff() {
|
|
91
|
-
logger_1.logger.
|
|
90
|
+
logger_1.logger.info(`Turning off device: ${this.deviceName}`);
|
|
92
91
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
93
92
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
94
93
|
cid: this.cid,
|
|
@@ -117,7 +116,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
|
|
|
117
116
|
logger_1.logger.error(`${error} for device: ${this.deviceName}`);
|
|
118
117
|
throw new Error(error);
|
|
119
118
|
}
|
|
120
|
-
logger_1.logger.
|
|
119
|
+
logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
121
120
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
122
121
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
123
122
|
cid: this.cid,
|
|
@@ -398,6 +397,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
398
397
|
* Get device details
|
|
399
398
|
*/
|
|
400
399
|
async getDetails() {
|
|
400
|
+
var _a;
|
|
401
401
|
logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
402
402
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
403
403
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
@@ -410,19 +410,17 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
410
410
|
}
|
|
411
411
|
}, helpers_1.Helpers.reqHeaderBypass());
|
|
412
412
|
const success = this.checkResponse([response, status], 'getDetails');
|
|
413
|
-
if (success) {
|
|
413
|
+
if (success && ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result)) {
|
|
414
414
|
this.details = response.result.result;
|
|
415
415
|
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
416
416
|
}
|
|
417
|
-
|
|
418
|
-
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
419
|
-
}
|
|
417
|
+
return success;
|
|
420
418
|
}
|
|
421
419
|
/**
|
|
422
420
|
* Turn device on
|
|
423
421
|
*/
|
|
424
422
|
async turnOn() {
|
|
425
|
-
logger_1.logger.
|
|
423
|
+
logger_1.logger.info(`Turning on device: ${this.deviceName}`);
|
|
426
424
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
427
425
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
428
426
|
cid: this.cid,
|
|
@@ -446,7 +444,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
446
444
|
* Turn device off
|
|
447
445
|
*/
|
|
448
446
|
async turnOff() {
|
|
449
|
-
logger_1.logger.
|
|
447
|
+
logger_1.logger.info(`Turning off device: ${this.deviceName}`);
|
|
450
448
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
451
449
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
452
450
|
cid: this.cid,
|
|
@@ -475,7 +473,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
|
|
|
475
473
|
logger_1.logger.error(`${error} for device: ${this.deviceName}`);
|
|
476
474
|
throw new Error(error);
|
|
477
475
|
}
|
|
478
|
-
logger_1.logger.
|
|
476
|
+
logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
479
477
|
const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
|
|
480
478
|
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
481
479
|
cid: this.cid,
|
|
@@ -21,7 +21,7 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
21
21
|
/**
|
|
22
22
|
* Get outlet details
|
|
23
23
|
*/
|
|
24
|
-
getDetails(): Promise<
|
|
24
|
+
getDetails(): Promise<Boolean>;
|
|
25
25
|
/**
|
|
26
26
|
* Update outlet energy data
|
|
27
27
|
*/
|
|
@@ -53,7 +53,7 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
53
53
|
/**
|
|
54
54
|
* Update outlet details and energy info
|
|
55
55
|
*/
|
|
56
|
-
update(): Promise<
|
|
56
|
+
update(): Promise<Boolean>;
|
|
57
57
|
/**
|
|
58
58
|
* Check if outlet has nightlight feature
|
|
59
59
|
*/
|
package/dist/lib/vesyncOutlet.js
CHANGED
|
@@ -66,15 +66,15 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
66
66
|
else {
|
|
67
67
|
url = '/v1/device/devicedetail';
|
|
68
68
|
}
|
|
69
|
-
const [response] = await this.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', this.deviceType === 'wifi-switch-1.3' ? null : body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
69
|
+
const [response, statusCode] = await this.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', this.deviceType === 'wifi-switch-1.3' ? null : body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
70
70
|
if (!response) {
|
|
71
71
|
logger_1.logger.debug(`[${this.deviceName}] No response received from API`);
|
|
72
|
-
return;
|
|
72
|
+
return false;
|
|
73
73
|
}
|
|
74
74
|
// Handle error responses
|
|
75
75
|
if (response.error) {
|
|
76
76
|
logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
77
|
-
return;
|
|
77
|
+
return false;
|
|
78
78
|
}
|
|
79
79
|
// Handle successful responses
|
|
80
80
|
if (response.code === 0) {
|
|
@@ -102,7 +102,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
102
102
|
if (subDevice) {
|
|
103
103
|
this.deviceStatus = subDevice.subDeviceStatus;
|
|
104
104
|
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved sub-device status: ${this.deviceStatus}`);
|
|
105
|
-
return;
|
|
105
|
+
return true;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
// Handle regular devices
|
|
@@ -117,12 +117,14 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
119
|
logger_1.logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
|
|
120
|
-
return;
|
|
120
|
+
return false;
|
|
121
121
|
}
|
|
122
122
|
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
123
|
+
return true;
|
|
123
124
|
}
|
|
124
125
|
else {
|
|
125
126
|
logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
127
|
+
return false;
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
@@ -313,11 +315,12 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
313
315
|
*/
|
|
314
316
|
async update() {
|
|
315
317
|
logger_1.logger.debug(`[${this.deviceName}] Updating outlet information`);
|
|
316
|
-
await this.getDetails();
|
|
317
|
-
if (this.features.includes('energy')) {
|
|
318
|
+
const success = await this.getDetails();
|
|
319
|
+
if (success && this.features.includes('energy')) {
|
|
318
320
|
await this.updateEnergy();
|
|
319
321
|
}
|
|
320
322
|
logger_1.logger.info(`[${this.deviceName}] Successfully updated outlet information`);
|
|
323
|
+
return success;
|
|
321
324
|
}
|
|
322
325
|
/**
|
|
323
326
|
* Check if outlet has nightlight feature
|
|
@@ -33,13 +33,16 @@ export declare abstract class VeSyncSwitch extends VeSyncBaseDevice {
|
|
|
33
33
|
* Return JSON details for switch
|
|
34
34
|
*/
|
|
35
35
|
displayJSON(): string;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Get switch details
|
|
38
|
+
*/
|
|
39
|
+
abstract getDetails(): Promise<Boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Update switch details
|
|
42
|
+
*/
|
|
43
|
+
update(): Promise<Boolean>;
|
|
37
44
|
abstract getConfig(): Promise<void>;
|
|
38
45
|
abstract turnOn(): Promise<boolean>;
|
|
39
46
|
abstract turnOff(): Promise<boolean>;
|
|
40
|
-
/**
|
|
41
|
-
* Update device details
|
|
42
|
-
*/
|
|
43
|
-
update(): Promise<void>;
|
|
44
47
|
}
|
|
45
48
|
export {};
|
package/dist/lib/vesyncSwitch.js
CHANGED
|
@@ -69,10 +69,13 @@ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
69
69
|
}, null, 4);
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
* Update
|
|
72
|
+
* Update switch details
|
|
73
73
|
*/
|
|
74
74
|
async update() {
|
|
75
|
-
|
|
75
|
+
logger_1.logger.debug(`[${this.deviceName}] Updating switch information`);
|
|
76
|
+
const success = await this.getDetails();
|
|
77
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully updated switch information`);
|
|
78
|
+
return success;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
exports.VeSyncSwitch = VeSyncSwitch;
|
|
@@ -11,7 +11,7 @@ export declare class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
11
11
|
/**
|
|
12
12
|
* Get wall switch details
|
|
13
13
|
*/
|
|
14
|
-
getDetails(): Promise<
|
|
14
|
+
getDetails(): Promise<Boolean>;
|
|
15
15
|
/**
|
|
16
16
|
* Get switch device configuration info
|
|
17
17
|
*/
|
|
@@ -37,7 +37,7 @@ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
37
37
|
/**
|
|
38
38
|
* Get dimmer switch details
|
|
39
39
|
*/
|
|
40
|
-
getDetails(): Promise<
|
|
40
|
+
getDetails(): Promise<Boolean>;
|
|
41
41
|
/**
|
|
42
42
|
* Get dimmer switch configuration info
|
|
43
43
|
*/
|
|
@@ -25,17 +25,16 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
25
25
|
uuid: this.cid,
|
|
26
26
|
method: 'devicedetail'
|
|
27
27
|
};
|
|
28
|
-
const [response] = await this.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
29
|
-
|
|
28
|
+
const [response, statusCode] = await this.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
29
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
30
|
+
if (success && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
30
31
|
const result = response.result;
|
|
31
32
|
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
32
33
|
this.details.active_time = result.activeTime || 0;
|
|
33
34
|
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
34
35
|
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
38
|
-
}
|
|
37
|
+
return success;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* Get switch device configuration info
|
|
@@ -60,7 +59,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
60
59
|
* Turn off wall switch
|
|
61
60
|
*/
|
|
62
61
|
async turnOff() {
|
|
63
|
-
logger_1.logger.
|
|
62
|
+
logger_1.logger.info(`Turning off device: ${this.deviceName}`);
|
|
64
63
|
const body = {
|
|
65
64
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
66
65
|
status: 'off',
|
|
@@ -79,7 +78,7 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
79
78
|
* Turn on wall switch
|
|
80
79
|
*/
|
|
81
80
|
async turnOn() {
|
|
82
|
-
logger_1.logger.
|
|
81
|
+
logger_1.logger.info(`Turning on device: ${this.deviceName}`);
|
|
83
82
|
const body = {
|
|
84
83
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
85
84
|
status: 'on',
|
|
@@ -118,8 +117,9 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
118
117
|
uuid: this.cid,
|
|
119
118
|
method: 'devicedetail'
|
|
120
119
|
};
|
|
121
|
-
const [response] = await this.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
122
|
-
|
|
120
|
+
const [response, statusCode] = await this.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
121
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
122
|
+
if (success && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
123
123
|
const result = response.result;
|
|
124
124
|
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
125
125
|
this.details.active_time = result.activeTime || 0;
|
|
@@ -136,9 +136,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
136
136
|
}
|
|
137
137
|
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
141
|
-
}
|
|
139
|
+
return success;
|
|
142
140
|
}
|
|
143
141
|
/**
|
|
144
142
|
* Get dimmer switch configuration info
|
|
@@ -163,7 +161,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
163
161
|
* Turn off dimmer switch
|
|
164
162
|
*/
|
|
165
163
|
async turnOff() {
|
|
166
|
-
logger_1.logger.
|
|
164
|
+
logger_1.logger.info(`Turning off device: ${this.deviceName}`);
|
|
167
165
|
const body = {
|
|
168
166
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
169
167
|
status: 'off',
|
|
@@ -182,7 +180,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
|
182
180
|
* Turn on dimmer switch
|
|
183
181
|
*/
|
|
184
182
|
async turnOn() {
|
|
185
|
-
logger_1.logger.
|
|
183
|
+
logger_1.logger.info(`Turning on device: ${this.deviceName}`);
|
|
186
184
|
const body = {
|
|
187
185
|
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
188
186
|
status: 'on',
|
package/package.json
CHANGED
|
@@ -105,13 +105,13 @@ export abstract class VeSyncBaseDevice {
|
|
|
105
105
|
/**
|
|
106
106
|
* Get device details
|
|
107
107
|
*/
|
|
108
|
-
abstract getDetails(): Promise<
|
|
108
|
+
abstract getDetails(): Promise<Boolean>;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Update device details
|
|
112
112
|
*/
|
|
113
|
-
async update(): Promise<
|
|
114
|
-
await this.getDetails();
|
|
113
|
+
async update(): Promise<Boolean> {
|
|
114
|
+
return await this.getDetails();
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
package/src/lib/vesyncBulb.ts
CHANGED
|
@@ -71,7 +71,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
71
71
|
/**
|
|
72
72
|
* Get bulb details
|
|
73
73
|
*/
|
|
74
|
-
async getDetails(): Promise<
|
|
74
|
+
async getDetails(): Promise<Boolean> {
|
|
75
75
|
logger.debug(`[${this.deviceName}] Getting bulb details`);
|
|
76
76
|
|
|
77
77
|
const isV2Device = this.deviceType === 'XYD0001';
|
|
@@ -94,14 +94,15 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
const [response] = await this.callApi(
|
|
97
|
+
const [response, statusCode] = await this.callApi(
|
|
98
98
|
endpoint,
|
|
99
99
|
'post',
|
|
100
100
|
body,
|
|
101
101
|
Helpers.reqHeaders(this.manager)
|
|
102
102
|
);
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
105
|
+
if (success && response?.result) {
|
|
105
106
|
this.deviceStatus = response.result.enabled ? 'on' : 'off';
|
|
106
107
|
this.brightness = response.result.brightness || this.brightness;
|
|
107
108
|
if (this.features.includes('color_temp')) {
|
|
@@ -121,18 +122,18 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
124
|
-
} else {
|
|
125
|
-
logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
126
125
|
}
|
|
126
|
+
return success;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* Update bulb
|
|
130
|
+
* Update bulb details
|
|
131
131
|
*/
|
|
132
|
-
async update(): Promise<
|
|
132
|
+
async update(): Promise<Boolean> {
|
|
133
133
|
logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
134
|
-
await this.getDetails();
|
|
134
|
+
const success = await this.getDetails();
|
|
135
135
|
logger.info(`[${this.deviceName}] Successfully updated bulb information`);
|
|
136
|
+
return success;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
/**
|
package/src/lib/vesyncFan.ts
CHANGED
|
@@ -437,7 +437,7 @@ export abstract class VeSyncFan extends VeSyncBaseDevice {
|
|
|
437
437
|
}, null, 4);
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
abstract getDetails(): Promise<
|
|
440
|
+
abstract getDetails(): Promise<Boolean>;
|
|
441
441
|
abstract turnOn(): Promise<boolean>;
|
|
442
442
|
abstract turnOff(): Promise<boolean>;
|
|
443
443
|
abstract changeFanSpeed(speed: number): Promise<boolean>;
|
package/src/lib/vesyncFanImpl.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
24
24
|
/**
|
|
25
25
|
* Get device details
|
|
26
26
|
*/
|
|
27
|
-
async getDetails(): Promise<
|
|
27
|
+
async getDetails(): Promise<Boolean> {
|
|
28
28
|
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
29
29
|
const [response, status] = await this.callApi(
|
|
30
30
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
@@ -42,7 +42,8 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
42
42
|
Helpers.reqHeaderBypass()
|
|
43
43
|
);
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const success = this.checkResponse([response, status], 'getDetails');
|
|
46
|
+
if (success) {
|
|
46
47
|
const result = response?.result?.result;
|
|
47
48
|
if (result) {
|
|
48
49
|
// Update device status
|
|
@@ -64,16 +65,15 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
64
65
|
}
|
|
65
66
|
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
66
67
|
}
|
|
67
|
-
} else {
|
|
68
|
-
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
69
68
|
}
|
|
69
|
+
return success;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Turn device on
|
|
74
74
|
*/
|
|
75
75
|
async turnOn(): Promise<boolean> {
|
|
76
|
-
logger.
|
|
76
|
+
logger.info(`Turning on device: ${this.deviceName}`);
|
|
77
77
|
const [response, status] = await this.callApi(
|
|
78
78
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
79
79
|
'post',
|
|
@@ -104,7 +104,7 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
104
104
|
* Turn device off
|
|
105
105
|
*/
|
|
106
106
|
async turnOff(): Promise<boolean> {
|
|
107
|
-
logger.
|
|
107
|
+
logger.info(`Turning off device: ${this.deviceName}`);
|
|
108
108
|
const [response, status] = await this.callApi(
|
|
109
109
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
110
110
|
'post',
|
|
@@ -141,7 +141,7 @@ export class VeSyncAirBypass extends VeSyncFan {
|
|
|
141
141
|
throw new Error(error);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
logger.
|
|
144
|
+
logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
145
145
|
const [response, status] = await this.callApi(
|
|
146
146
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
147
147
|
'post',
|
|
@@ -488,7 +488,7 @@ export class VeSyncHumidifier extends VeSyncFan {
|
|
|
488
488
|
/**
|
|
489
489
|
* Get device details
|
|
490
490
|
*/
|
|
491
|
-
async getDetails(): Promise<
|
|
491
|
+
async getDetails(): Promise<Boolean> {
|
|
492
492
|
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
493
493
|
const [response, status] = await this.callApi(
|
|
494
494
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
@@ -507,19 +507,18 @@ export class VeSyncHumidifier extends VeSyncFan {
|
|
|
507
507
|
);
|
|
508
508
|
|
|
509
509
|
const success = this.checkResponse([response, status], 'getDetails');
|
|
510
|
-
if (success) {
|
|
510
|
+
if (success && response?.result?.result) {
|
|
511
511
|
this.details = response.result.result;
|
|
512
512
|
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
513
|
-
} else {
|
|
514
|
-
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
515
513
|
}
|
|
514
|
+
return success;
|
|
516
515
|
}
|
|
517
516
|
|
|
518
517
|
/**
|
|
519
518
|
* Turn device on
|
|
520
519
|
*/
|
|
521
520
|
async turnOn(): Promise<boolean> {
|
|
522
|
-
logger.
|
|
521
|
+
logger.info(`Turning on device: ${this.deviceName}`);
|
|
523
522
|
const [response, status] = await this.callApi(
|
|
524
523
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
525
524
|
'post',
|
|
@@ -550,7 +549,7 @@ export class VeSyncHumidifier extends VeSyncFan {
|
|
|
550
549
|
* Turn device off
|
|
551
550
|
*/
|
|
552
551
|
async turnOff(): Promise<boolean> {
|
|
553
|
-
logger.
|
|
552
|
+
logger.info(`Turning off device: ${this.deviceName}`);
|
|
554
553
|
const [response, status] = await this.callApi(
|
|
555
554
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
556
555
|
'post',
|
|
@@ -587,7 +586,7 @@ export class VeSyncHumidifier extends VeSyncFan {
|
|
|
587
586
|
throw new Error(error);
|
|
588
587
|
}
|
|
589
588
|
|
|
590
|
-
logger.
|
|
589
|
+
logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
|
|
591
590
|
const [response, status] = await this.callApi(
|
|
592
591
|
'/cloud/v2/deviceManaged/bypassV2',
|
|
593
592
|
'post',
|
package/src/lib/vesyncOutlet.ts
CHANGED
|
@@ -56,7 +56,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
56
56
|
/**
|
|
57
57
|
* Get outlet details
|
|
58
58
|
*/
|
|
59
|
-
async getDetails(): Promise<
|
|
59
|
+
async getDetails(): Promise<Boolean> {
|
|
60
60
|
logger.debug(`[${this.deviceName}] Getting outlet details`);
|
|
61
61
|
|
|
62
62
|
const body = {
|
|
@@ -77,7 +77,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
77
77
|
url = '/v1/device/devicedetail';
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const [response] = await this.callApi(
|
|
80
|
+
const [response, statusCode] = await this.callApi(
|
|
81
81
|
url,
|
|
82
82
|
this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post',
|
|
83
83
|
this.deviceType === 'wifi-switch-1.3' ? null : body,
|
|
@@ -86,13 +86,13 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
86
86
|
|
|
87
87
|
if (!response) {
|
|
88
88
|
logger.debug(`[${this.deviceName}] No response received from API`);
|
|
89
|
-
return;
|
|
89
|
+
return false;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// Handle error responses
|
|
93
93
|
if (response.error) {
|
|
94
94
|
logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
95
|
-
return;
|
|
95
|
+
return false;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// Handle successful responses
|
|
@@ -126,7 +126,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
126
126
|
if (subDevice) {
|
|
127
127
|
this.deviceStatus = subDevice.subDeviceStatus;
|
|
128
128
|
logger.debug(`[${this.deviceName}] Successfully retrieved sub-device status: ${this.deviceStatus}`);
|
|
129
|
-
return;
|
|
129
|
+
return true;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -139,11 +139,13 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
139
139
|
this.deviceStatus = response.power === 'on' ? 'on' : 'off';
|
|
140
140
|
} else {
|
|
141
141
|
logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
|
|
142
|
-
return;
|
|
142
|
+
return false;
|
|
143
143
|
}
|
|
144
144
|
logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
145
|
+
return true;
|
|
145
146
|
} else {
|
|
146
147
|
logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
148
|
+
return false;
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|
|
@@ -364,13 +366,14 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
364
366
|
/**
|
|
365
367
|
* Update outlet details and energy info
|
|
366
368
|
*/
|
|
367
|
-
async update(): Promise<
|
|
369
|
+
async update(): Promise<Boolean> {
|
|
368
370
|
logger.debug(`[${this.deviceName}] Updating outlet information`);
|
|
369
|
-
await this.getDetails();
|
|
370
|
-
if (this.features.includes('energy')) {
|
|
371
|
+
const success = await this.getDetails();
|
|
372
|
+
if (success && this.features.includes('energy')) {
|
|
371
373
|
await this.updateEnergy();
|
|
372
374
|
}
|
|
373
375
|
logger.info(`[${this.deviceName}] Successfully updated outlet information`);
|
|
376
|
+
return success;
|
|
374
377
|
}
|
|
375
378
|
|
|
376
379
|
/**
|
package/src/lib/vesyncSwitch.ts
CHANGED
|
@@ -81,15 +81,22 @@ export abstract class VeSyncSwitch extends VeSyncBaseDevice {
|
|
|
81
81
|
}, null, 4);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
abstract
|
|
84
|
+
/**
|
|
85
|
+
* Get switch details
|
|
86
|
+
*/
|
|
87
|
+
abstract getDetails(): Promise<Boolean>;
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Update
|
|
90
|
+
* Update switch details
|
|
91
91
|
*/
|
|
92
|
-
async update(): Promise<
|
|
93
|
-
|
|
92
|
+
async update(): Promise<Boolean> {
|
|
93
|
+
logger.debug(`[${this.deviceName}] Updating switch information`);
|
|
94
|
+
const success = await this.getDetails();
|
|
95
|
+
logger.debug(`[${this.deviceName}] Successfully updated switch information`);
|
|
96
|
+
return success;
|
|
94
97
|
}
|
|
98
|
+
|
|
99
|
+
abstract getConfig(): Promise<void>;
|
|
100
|
+
abstract turnOn(): Promise<boolean>;
|
|
101
|
+
abstract turnOff(): Promise<boolean>;
|
|
95
102
|
}
|
|
@@ -19,7 +19,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
19
19
|
/**
|
|
20
20
|
* Get wall switch details
|
|
21
21
|
*/
|
|
22
|
-
async getDetails(): Promise<
|
|
22
|
+
async getDetails(): Promise<Boolean> {
|
|
23
23
|
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
24
24
|
const body = {
|
|
25
25
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
@@ -27,22 +27,22 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
27
27
|
method: 'devicedetail'
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const [response] = await this.callApi(
|
|
30
|
+
const [response, statusCode] = await this.callApi(
|
|
31
31
|
'/inwallswitch/v1/device/devicedetail',
|
|
32
32
|
'post',
|
|
33
33
|
body,
|
|
34
34
|
Helpers.reqHeaders(this.manager)
|
|
35
35
|
);
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
38
|
+
if (success && response?.result) {
|
|
38
39
|
const result = response.result;
|
|
39
40
|
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
40
41
|
this.details.active_time = result.activeTime || 0;
|
|
41
42
|
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
42
43
|
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
43
|
-
} else {
|
|
44
|
-
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
45
44
|
}
|
|
45
|
+
return success;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -75,7 +75,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
75
75
|
* Turn off wall switch
|
|
76
76
|
*/
|
|
77
77
|
async turnOff(): Promise<boolean> {
|
|
78
|
-
logger.
|
|
78
|
+
logger.info(`Turning off device: ${this.deviceName}`);
|
|
79
79
|
const body = {
|
|
80
80
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
81
81
|
status: 'off',
|
|
@@ -102,7 +102,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
|
|
|
102
102
|
* Turn on wall switch
|
|
103
103
|
*/
|
|
104
104
|
async turnOn(): Promise<boolean> {
|
|
105
|
-
logger.
|
|
105
|
+
logger.info(`Turning on device: ${this.deviceName}`);
|
|
106
106
|
const body = {
|
|
107
107
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
108
108
|
status: 'on',
|
|
@@ -143,7 +143,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
143
143
|
/**
|
|
144
144
|
* Get dimmer switch details
|
|
145
145
|
*/
|
|
146
|
-
async getDetails(): Promise<
|
|
146
|
+
async getDetails(): Promise<Boolean> {
|
|
147
147
|
logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
148
148
|
const body = {
|
|
149
149
|
...Helpers.reqBody(this.manager, 'devicedetail'),
|
|
@@ -151,14 +151,15 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
151
151
|
method: 'devicedetail'
|
|
152
152
|
};
|
|
153
153
|
|
|
154
|
-
const [response] = await this.callApi(
|
|
154
|
+
const [response, statusCode] = await this.callApi(
|
|
155
155
|
'/dimmer/v1/device/devicedetail',
|
|
156
156
|
'post',
|
|
157
157
|
body,
|
|
158
158
|
Helpers.reqHeaders(this.manager)
|
|
159
159
|
);
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
const success = this.checkResponse([response, statusCode], 'getDetails');
|
|
162
|
+
if (success && response?.result) {
|
|
162
163
|
const result = response.result;
|
|
163
164
|
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
164
165
|
this.details.active_time = result.activeTime || 0;
|
|
@@ -174,9 +175,8 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
174
175
|
};
|
|
175
176
|
}
|
|
176
177
|
logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
177
|
-
} else {
|
|
178
|
-
logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
179
178
|
}
|
|
179
|
+
return success;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
@@ -209,7 +209,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
209
209
|
* Turn off dimmer switch
|
|
210
210
|
*/
|
|
211
211
|
async turnOff(): Promise<boolean> {
|
|
212
|
-
logger.
|
|
212
|
+
logger.info(`Turning off device: ${this.deviceName}`);
|
|
213
213
|
const body = {
|
|
214
214
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
215
215
|
status: 'off',
|
|
@@ -236,7 +236,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
|
236
236
|
* Turn on dimmer switch
|
|
237
237
|
*/
|
|
238
238
|
async turnOn(): Promise<boolean> {
|
|
239
|
-
logger.
|
|
239
|
+
logger.info(`Turning on device: ${this.deviceName}`);
|
|
240
240
|
const body = {
|
|
241
241
|
...Helpers.reqBody(this.manager, 'devicestatus'),
|
|
242
242
|
status: 'on',
|