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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { VeSync } from './lib/vesync';
|
|
2
|
+
export { VeSyncAirBypass } from './lib/vesyncFanImpl';
|
|
3
|
+
export { VeSyncOutlet7A, VeSyncOutlet10A, VeSyncOutlet15A, VeSyncOutdoorPlug } from './lib/vesyncOutletImpl';
|
|
4
|
+
export { VeSyncBulb } from './lib/vesyncBulb';
|
|
5
|
+
export { VeSyncWallSwitch } from './lib/vesyncSwitchImpl';
|
|
6
|
+
export { VeSyncBaseDevice } from './lib/vesyncBaseDevice';
|
|
7
|
+
export { Helpers, setApiBaseUrl } from './lib/helpers';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setApiBaseUrl = exports.Helpers = exports.VeSyncBaseDevice = exports.VeSyncWallSwitch = exports.VeSyncBulb = exports.VeSyncOutdoorPlug = exports.VeSyncOutlet15A = exports.VeSyncOutlet10A = exports.VeSyncOutlet7A = exports.VeSyncAirBypass = exports.VeSync = void 0;
|
|
4
|
+
// Export main VeSync manager class
|
|
5
|
+
var vesync_1 = require("./lib/vesync");
|
|
6
|
+
Object.defineProperty(exports, "VeSync", { enumerable: true, get: function () { return vesync_1.VeSync; } });
|
|
7
|
+
// Export device classes
|
|
8
|
+
var vesyncFanImpl_1 = require("./lib/vesyncFanImpl");
|
|
9
|
+
Object.defineProperty(exports, "VeSyncAirBypass", { enumerable: true, get: function () { return vesyncFanImpl_1.VeSyncAirBypass; } });
|
|
10
|
+
var vesyncOutletImpl_1 = require("./lib/vesyncOutletImpl");
|
|
11
|
+
Object.defineProperty(exports, "VeSyncOutlet7A", { enumerable: true, get: function () { return vesyncOutletImpl_1.VeSyncOutlet7A; } });
|
|
12
|
+
Object.defineProperty(exports, "VeSyncOutlet10A", { enumerable: true, get: function () { return vesyncOutletImpl_1.VeSyncOutlet10A; } });
|
|
13
|
+
Object.defineProperty(exports, "VeSyncOutlet15A", { enumerable: true, get: function () { return vesyncOutletImpl_1.VeSyncOutlet15A; } });
|
|
14
|
+
Object.defineProperty(exports, "VeSyncOutdoorPlug", { enumerable: true, get: function () { return vesyncOutletImpl_1.VeSyncOutdoorPlug; } });
|
|
15
|
+
var vesyncBulb_1 = require("./lib/vesyncBulb");
|
|
16
|
+
Object.defineProperty(exports, "VeSyncBulb", { enumerable: true, get: function () { return vesyncBulb_1.VeSyncBulb; } });
|
|
17
|
+
var vesyncSwitchImpl_1 = require("./lib/vesyncSwitchImpl");
|
|
18
|
+
Object.defineProperty(exports, "VeSyncWallSwitch", { enumerable: true, get: function () { return vesyncSwitchImpl_1.VeSyncWallSwitch; } });
|
|
19
|
+
// Export base device class
|
|
20
|
+
var vesyncBaseDevice_1 = require("./lib/vesyncBaseDevice");
|
|
21
|
+
Object.defineProperty(exports, "VeSyncBaseDevice", { enumerable: true, get: function () { return vesyncBaseDevice_1.VeSyncBaseDevice; } });
|
|
22
|
+
// Export helper functions
|
|
23
|
+
var helpers_1 = require("./lib/helpers");
|
|
24
|
+
Object.defineProperty(exports, "Helpers", { enumerable: true, get: function () { return helpers_1.Helpers; } });
|
|
25
|
+
Object.defineProperty(exports, "setApiBaseUrl", { enumerable: true, get: function () { return helpers_1.setApiBaseUrl; } });
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -1,87 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for VeSync API
|
|
3
|
+
*/
|
|
1
4
|
import { VeSync } from './vesync';
|
|
2
|
-
export declare
|
|
5
|
+
export declare function getApiBaseUrl(): string;
|
|
6
|
+
export declare function setApiBaseUrl(url: string): void;
|
|
3
7
|
export declare const API_RATE_LIMIT = 30;
|
|
4
|
-
export declare const API_TIMEOUT =
|
|
5
|
-
export declare const USER_AGENT = "VeSync/3.2.39 (com.etekcity.vesyncPlatform; build:5; iOS 15.5.0) Alamofire/5.2.1";
|
|
6
|
-
export declare const DEFAULT_TZ = "America/New_York";
|
|
7
|
-
export declare const DEFAULT_REGION = "US";
|
|
8
|
+
export declare const API_TIMEOUT = 5000;
|
|
8
9
|
export declare const APP_VERSION = "2.8.6";
|
|
9
10
|
export declare const PHONE_BRAND = "SM N9005";
|
|
10
11
|
export declare const PHONE_OS = "Android";
|
|
11
|
-
export declare const MOBILE_ID = "1234567890123456";
|
|
12
12
|
export declare const USER_TYPE = "1";
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const DEFAULT_TZ = "America/New_York";
|
|
14
|
+
export declare const DEFAULT_REGION = "US";
|
|
15
|
+
export declare const MOBILE_ID = "1234567890123456";
|
|
14
16
|
export declare const BYPASS_HEADER_UA = "okhttp/3.12.1";
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
+
export interface RequestBody {
|
|
18
|
+
acceptLanguage?: string;
|
|
19
|
+
accountID?: string;
|
|
20
|
+
appVersion?: string;
|
|
21
|
+
cid?: string;
|
|
22
|
+
configModule?: string;
|
|
23
|
+
debugMode?: boolean;
|
|
24
|
+
deviceRegion?: string;
|
|
25
|
+
email?: string;
|
|
26
|
+
method?: string;
|
|
27
|
+
password?: string;
|
|
28
|
+
phoneBrand?: string;
|
|
29
|
+
phoneOS?: string;
|
|
30
|
+
timeZone?: string;
|
|
31
|
+
token?: string;
|
|
32
|
+
traceId?: string;
|
|
33
|
+
userType?: string;
|
|
34
|
+
uuid?: string;
|
|
35
|
+
status?: string;
|
|
17
36
|
[key: string]: any;
|
|
18
|
-
}
|
|
37
|
+
}
|
|
19
38
|
export declare class Helpers {
|
|
20
|
-
|
|
39
|
+
static shouldRedact: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Calculate MD5 hash
|
|
42
|
+
*/
|
|
43
|
+
static md5(text: string): string;
|
|
21
44
|
/**
|
|
22
45
|
* Build header for legacy api GET requests
|
|
23
46
|
*/
|
|
24
|
-
static reqHeaders(manager: VeSync):
|
|
25
|
-
[key: string]: string;
|
|
26
|
-
};
|
|
47
|
+
static reqHeaders(manager: VeSync): Record<string, string>;
|
|
27
48
|
/**
|
|
28
49
|
* Build header for api requests on 'bypass' endpoint
|
|
29
50
|
*/
|
|
30
|
-
static reqHeaderBypass():
|
|
31
|
-
[key: string]: string;
|
|
32
|
-
};
|
|
51
|
+
static reqHeaderBypass(): Record<string, string>;
|
|
33
52
|
/**
|
|
34
53
|
* Return universal keys for body of api requests
|
|
35
54
|
*/
|
|
36
|
-
static reqBodyBase(manager: VeSync):
|
|
37
|
-
[key: string]: string;
|
|
38
|
-
};
|
|
55
|
+
static reqBodyBase(manager: VeSync): Record<string, string>;
|
|
39
56
|
/**
|
|
40
57
|
* Keys for authenticating api requests
|
|
41
58
|
*/
|
|
42
|
-
static reqBodyAuth(manager: VeSync):
|
|
59
|
+
static reqBodyAuth(manager: VeSync): Record<string, any>;
|
|
43
60
|
/**
|
|
44
61
|
* Detail keys for api requests
|
|
45
62
|
*/
|
|
46
|
-
static reqBodyDetails():
|
|
63
|
+
static reqBodyDetails(): Record<string, string>;
|
|
47
64
|
/**
|
|
48
65
|
* Builder for body of api requests
|
|
49
66
|
*/
|
|
50
|
-
static reqBody(manager: VeSync, type: string):
|
|
67
|
+
static reqBody(manager: VeSync, type: string): Record<string, any>;
|
|
51
68
|
/**
|
|
52
|
-
*
|
|
69
|
+
* Call VeSync API
|
|
53
70
|
*/
|
|
54
|
-
static
|
|
71
|
+
static callApi(endpoint: string, method: string, data?: any, headers?: Record<string, string>): Promise<[any, number]>;
|
|
55
72
|
/**
|
|
56
|
-
*
|
|
73
|
+
* Calculate hex value from energy response
|
|
57
74
|
*/
|
|
58
|
-
static
|
|
75
|
+
static calculateHex(hexStr: string): string;
|
|
59
76
|
/**
|
|
60
|
-
*
|
|
77
|
+
* Build energy dictionary from API response
|
|
61
78
|
*/
|
|
62
|
-
static
|
|
63
|
-
[key: string]: string;
|
|
64
|
-
}): Promise<[any, number]>;
|
|
79
|
+
static buildEnergyDict(result: any): Record<string, any>;
|
|
65
80
|
/**
|
|
66
|
-
*
|
|
81
|
+
* Build configuration dictionary from API response
|
|
67
82
|
*/
|
|
68
|
-
static
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* Timer class for device scheduling
|
|
74
|
-
*/
|
|
75
|
-
export declare class Timer {
|
|
76
|
-
status: string;
|
|
77
|
-
type: string;
|
|
78
|
-
id: string;
|
|
79
|
-
time: string;
|
|
80
|
-
action: string;
|
|
81
|
-
week: string;
|
|
82
|
-
state: string;
|
|
83
|
-
enabled: boolean;
|
|
84
|
-
private timer;
|
|
85
|
-
constructor(status?: string, type?: string, id?: string, time?: string, action?: string, week?: string, state?: string, enabled?: boolean);
|
|
86
|
-
toJson(): string;
|
|
83
|
+
static buildConfigDict(result: any): Record<string, any>;
|
|
84
|
+
/**
|
|
85
|
+
* Calculate MD5 hash
|
|
86
|
+
*/
|
|
87
|
+
static hashPassword(text: string): string;
|
|
87
88
|
}
|
package/dist/lib/helpers.js
CHANGED
|
@@ -1,39 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions for VeSync API
|
|
4
|
+
*/
|
|
2
5
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
6
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
7
|
};
|
|
5
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
9
|
+
exports.Helpers = exports.BYPASS_HEADER_UA = exports.MOBILE_ID = exports.DEFAULT_REGION = exports.DEFAULT_TZ = exports.USER_TYPE = exports.PHONE_OS = exports.PHONE_BRAND = exports.APP_VERSION = exports.API_TIMEOUT = exports.API_RATE_LIMIT = void 0;
|
|
10
|
+
exports.getApiBaseUrl = getApiBaseUrl;
|
|
11
|
+
exports.setApiBaseUrl = setApiBaseUrl;
|
|
10
12
|
const axios_1 = __importDefault(require("axios"));
|
|
11
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
-
|
|
14
|
+
// API configuration
|
|
15
|
+
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
16
|
+
function getApiBaseUrl() {
|
|
17
|
+
return _apiBaseUrl;
|
|
18
|
+
}
|
|
19
|
+
function setApiBaseUrl(url) {
|
|
20
|
+
_apiBaseUrl = url;
|
|
21
|
+
}
|
|
13
22
|
exports.API_RATE_LIMIT = 30;
|
|
14
|
-
exports.API_TIMEOUT =
|
|
15
|
-
exports.USER_AGENT = "VeSync/3.2.39 (com.etekcity.vesyncPlatform; build:5; iOS 15.5.0) Alamofire/5.2.1";
|
|
16
|
-
exports.DEFAULT_TZ = 'America/New_York';
|
|
17
|
-
exports.DEFAULT_REGION = 'US';
|
|
23
|
+
exports.API_TIMEOUT = 5000;
|
|
18
24
|
exports.APP_VERSION = '2.8.6';
|
|
19
25
|
exports.PHONE_BRAND = 'SM N9005';
|
|
20
26
|
exports.PHONE_OS = 'Android';
|
|
21
|
-
exports.MOBILE_ID = '1234567890123456';
|
|
22
27
|
exports.USER_TYPE = '1';
|
|
23
|
-
exports.
|
|
28
|
+
exports.DEFAULT_TZ = 'America/New_York';
|
|
29
|
+
exports.DEFAULT_REGION = 'US';
|
|
30
|
+
exports.MOBILE_ID = '1234567890123456';
|
|
24
31
|
exports.BYPASS_HEADER_UA = 'okhttp/3.12.1';
|
|
25
32
|
class Helpers {
|
|
33
|
+
/**
|
|
34
|
+
* Calculate MD5 hash
|
|
35
|
+
*/
|
|
36
|
+
static md5(text) {
|
|
37
|
+
return crypto_1.default.createHash('md5').update(text).digest('hex');
|
|
38
|
+
}
|
|
26
39
|
/**
|
|
27
40
|
* Build header for legacy api GET requests
|
|
28
41
|
*/
|
|
29
42
|
static reqHeaders(manager) {
|
|
43
|
+
if (!manager.accountId || !manager.token) {
|
|
44
|
+
throw new Error('Manager accountId and token must be set');
|
|
45
|
+
}
|
|
30
46
|
return {
|
|
31
47
|
'accept-language': 'en',
|
|
32
48
|
'accountId': manager.accountId,
|
|
33
49
|
'appVersion': exports.APP_VERSION,
|
|
34
50
|
'content-type': 'application/json',
|
|
35
51
|
'tk': manager.token,
|
|
36
|
-
'tz': manager.timeZone
|
|
52
|
+
'tz': manager.timeZone
|
|
37
53
|
};
|
|
38
54
|
}
|
|
39
55
|
/**
|
|
@@ -42,7 +58,7 @@ class Helpers {
|
|
|
42
58
|
static reqHeaderBypass() {
|
|
43
59
|
return {
|
|
44
60
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
45
|
-
'User-Agent': exports.BYPASS_HEADER_UA
|
|
61
|
+
'User-Agent': exports.BYPASS_HEADER_UA
|
|
46
62
|
};
|
|
47
63
|
}
|
|
48
64
|
/**
|
|
@@ -58,6 +74,9 @@ class Helpers {
|
|
|
58
74
|
* Keys for authenticating api requests
|
|
59
75
|
*/
|
|
60
76
|
static reqBodyAuth(manager) {
|
|
77
|
+
if (!manager.accountId || !manager.token) {
|
|
78
|
+
throw new Error('Manager accountId and token must be set');
|
|
79
|
+
}
|
|
61
80
|
return {
|
|
62
81
|
'accountID': manager.accountId,
|
|
63
82
|
'token': manager.token
|
|
@@ -71,16 +90,18 @@ class Helpers {
|
|
|
71
90
|
'appVersion': exports.APP_VERSION,
|
|
72
91
|
'phoneBrand': exports.PHONE_BRAND,
|
|
73
92
|
'phoneOS': exports.PHONE_OS,
|
|
74
|
-
'traceId':
|
|
93
|
+
'traceId': Date.now().toString()
|
|
75
94
|
};
|
|
76
95
|
}
|
|
77
96
|
/**
|
|
78
97
|
* Builder for body of api requests
|
|
79
98
|
*/
|
|
80
99
|
static reqBody(manager, type) {
|
|
81
|
-
|
|
100
|
+
const body = {
|
|
101
|
+
...this.reqBodyBase(manager)
|
|
102
|
+
};
|
|
82
103
|
if (type === 'login') {
|
|
83
|
-
|
|
104
|
+
return {
|
|
84
105
|
...body,
|
|
85
106
|
...this.reqBodyDetails(),
|
|
86
107
|
email: manager.username,
|
|
@@ -89,72 +110,64 @@ class Helpers {
|
|
|
89
110
|
userType: exports.USER_TYPE,
|
|
90
111
|
method: 'login'
|
|
91
112
|
};
|
|
92
|
-
return body;
|
|
93
113
|
}
|
|
94
|
-
|
|
114
|
+
const authBody = {
|
|
115
|
+
...body,
|
|
116
|
+
...this.reqBodyAuth(manager)
|
|
117
|
+
};
|
|
95
118
|
if (type === 'devicestatus') {
|
|
96
|
-
return
|
|
119
|
+
return authBody;
|
|
97
120
|
}
|
|
98
|
-
|
|
121
|
+
const fullBody = {
|
|
122
|
+
...authBody,
|
|
123
|
+
...this.reqBodyDetails()
|
|
124
|
+
};
|
|
99
125
|
switch (type) {
|
|
100
126
|
case 'devicelist':
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
return {
|
|
128
|
+
...fullBody,
|
|
129
|
+
method: 'devices',
|
|
130
|
+
pageNo: '1',
|
|
131
|
+
pageSize: '100'
|
|
132
|
+
};
|
|
105
133
|
case 'devicedetail':
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
body.mobileId = exports.MOBILE_ID;
|
|
112
|
-
break;
|
|
113
|
-
case 'energy_month':
|
|
114
|
-
body.method = 'energymonth';
|
|
115
|
-
body.mobileId = exports.MOBILE_ID;
|
|
116
|
-
break;
|
|
117
|
-
case 'energy_year':
|
|
118
|
-
body.method = 'energyyear';
|
|
119
|
-
body.mobileId = exports.MOBILE_ID;
|
|
120
|
-
break;
|
|
134
|
+
return {
|
|
135
|
+
...fullBody,
|
|
136
|
+
method: 'devicedetail',
|
|
137
|
+
mobileId: exports.MOBILE_ID
|
|
138
|
+
};
|
|
121
139
|
case 'bypass':
|
|
122
|
-
|
|
123
|
-
|
|
140
|
+
return {
|
|
141
|
+
...fullBody,
|
|
142
|
+
method: 'bypass'
|
|
143
|
+
};
|
|
124
144
|
case 'bypassV2':
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
return {
|
|
146
|
+
...fullBody,
|
|
147
|
+
deviceRegion: exports.DEFAULT_REGION,
|
|
148
|
+
method: 'bypassV2'
|
|
149
|
+
};
|
|
128
150
|
case 'bypass_config':
|
|
129
|
-
|
|
130
|
-
|
|
151
|
+
return {
|
|
152
|
+
...fullBody,
|
|
153
|
+
method: 'firmwareUpdateInfo'
|
|
154
|
+
};
|
|
155
|
+
default:
|
|
156
|
+
return fullBody;
|
|
131
157
|
}
|
|
132
|
-
return body;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Calculate hex value
|
|
136
|
-
*/
|
|
137
|
-
static calculateHex(hexString) {
|
|
138
|
-
const hexConv = hexString.split(':');
|
|
139
|
-
return (parseInt(hexConv[0], 16) + parseInt(hexConv[1], 16)) / 8192;
|
|
140
158
|
}
|
|
141
159
|
/**
|
|
142
|
-
*
|
|
160
|
+
* Call VeSync API
|
|
143
161
|
*/
|
|
144
|
-
static
|
|
145
|
-
return crypto_1.default.createHash('md5').update(password).digest('hex');
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Call the VeSync API
|
|
149
|
-
*/
|
|
150
|
-
static async callApi(api, method, jsonObject, headers) {
|
|
162
|
+
static async callApi(endpoint, method, data = null, headers = {}) {
|
|
151
163
|
try {
|
|
164
|
+
const url = _apiBaseUrl + endpoint;
|
|
152
165
|
const response = await (0, axios_1.default)({
|
|
153
|
-
method
|
|
154
|
-
url
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
timeout: exports.API_TIMEOUT
|
|
166
|
+
method,
|
|
167
|
+
url,
|
|
168
|
+
data,
|
|
169
|
+
headers,
|
|
170
|
+
timeout: exports.API_TIMEOUT
|
|
158
171
|
});
|
|
159
172
|
return [response.data, response.status];
|
|
160
173
|
}
|
|
@@ -162,61 +175,70 @@ class Helpers {
|
|
|
162
175
|
if (error.response) {
|
|
163
176
|
return [error.response.data, error.response.status];
|
|
164
177
|
}
|
|
165
|
-
|
|
178
|
+
console.error('API call failed:', error.message);
|
|
179
|
+
return [null, 0];
|
|
166
180
|
}
|
|
167
181
|
}
|
|
168
182
|
/**
|
|
169
|
-
*
|
|
183
|
+
* Calculate hex value from energy response
|
|
170
184
|
*/
|
|
171
|
-
static
|
|
172
|
-
if (!
|
|
173
|
-
return
|
|
185
|
+
static calculateHex(hexStr) {
|
|
186
|
+
if (!hexStr || !hexStr.includes(':')) {
|
|
187
|
+
return '0';
|
|
188
|
+
}
|
|
189
|
+
const [prefix, value] = hexStr.split(':');
|
|
190
|
+
if (!prefix || !value) {
|
|
191
|
+
return '0';
|
|
174
192
|
}
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
return
|
|
193
|
+
try {
|
|
194
|
+
const decoded = Buffer.from(value, 'hex');
|
|
195
|
+
return decoded.readFloatBE(0).toString();
|
|
178
196
|
}
|
|
179
|
-
|
|
180
|
-
|
|
197
|
+
catch (error) {
|
|
198
|
+
console.debug('Error decoding hex value:', error);
|
|
199
|
+
return '0';
|
|
181
200
|
}
|
|
182
|
-
return value;
|
|
183
201
|
}
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Build energy dictionary from API response
|
|
204
|
+
*/
|
|
205
|
+
static buildEnergyDict(result) {
|
|
206
|
+
if (!result) {
|
|
207
|
+
return {};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
energy_consumption_of_today: result.energyConsumptionOfToday || 0,
|
|
211
|
+
cost_per_kwh: result.costPerKWH || 0,
|
|
212
|
+
max_energy: result.maxEnergy || 0,
|
|
213
|
+
total_energy: result.totalEnergy || 0,
|
|
214
|
+
data: result.data || [],
|
|
215
|
+
energy_consumption: result.energy || 0,
|
|
216
|
+
start_time: result.startTime || '',
|
|
217
|
+
end_time: result.endTime || ''
|
|
218
|
+
};
|
|
186
219
|
}
|
|
187
|
-
|
|
188
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Build configuration dictionary from API response
|
|
222
|
+
*/
|
|
223
|
+
static buildConfigDict(result) {
|
|
224
|
+
if (!result) {
|
|
225
|
+
return {};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
configModule: result.configModule || '',
|
|
229
|
+
firmwareVersion: result.currentFirmVersion || '',
|
|
230
|
+
deviceRegion: result.deviceRegion || '',
|
|
231
|
+
debugMode: result.debugMode || false,
|
|
232
|
+
deviceTimezone: result.deviceTimezone || exports.DEFAULT_TZ,
|
|
233
|
+
...result
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Calculate MD5 hash
|
|
238
|
+
*/
|
|
239
|
+
static hashPassword(text) {
|
|
240
|
+
return crypto_1.default.createHash('md5').update(text).digest('hex');
|
|
189
241
|
}
|
|
190
242
|
}
|
|
191
243
|
exports.Helpers = Helpers;
|
|
192
244
|
Helpers.shouldRedact = true;
|
|
193
|
-
/**
|
|
194
|
-
* Timer class for device scheduling
|
|
195
|
-
*/
|
|
196
|
-
class Timer {
|
|
197
|
-
constructor(status = '', type = '', id = '', time = '', action = '', week = '', state = '', enabled = false) {
|
|
198
|
-
this.status = status;
|
|
199
|
-
this.type = type;
|
|
200
|
-
this.id = id;
|
|
201
|
-
this.time = time;
|
|
202
|
-
this.action = action;
|
|
203
|
-
this.week = week;
|
|
204
|
-
this.state = state;
|
|
205
|
-
this.enabled = enabled;
|
|
206
|
-
this.timer = null;
|
|
207
|
-
}
|
|
208
|
-
toJson() {
|
|
209
|
-
return JSON.stringify({
|
|
210
|
-
status: this.status,
|
|
211
|
-
type: this.type,
|
|
212
|
-
id: this.id,
|
|
213
|
-
time: this.time,
|
|
214
|
-
action: this.action,
|
|
215
|
-
week: this.week,
|
|
216
|
-
state: this.state,
|
|
217
|
-
enabled: this.enabled
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
exports.Timer = Timer;
|
|
222
|
-
//# sourceMappingURL=helpers.js.map
|
package/dist/lib/vesync.d.ts
CHANGED
|
@@ -1,47 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* VeSync API Device Library
|
|
3
|
+
*/
|
|
4
|
+
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
|
+
/**
|
|
6
|
+
* VeSync Manager Class
|
|
7
|
+
*/
|
|
2
8
|
export declare class VeSync {
|
|
3
|
-
[x: number]: [any, number];
|
|
4
9
|
private _debug;
|
|
5
10
|
private _redact;
|
|
6
11
|
private _energyUpdateInterval;
|
|
7
12
|
private _energyCheck;
|
|
8
13
|
private _devList;
|
|
14
|
+
private _lastUpdateTs;
|
|
15
|
+
private _inProcess;
|
|
9
16
|
username: string;
|
|
10
17
|
password: string;
|
|
11
18
|
token: string | null;
|
|
12
19
|
accountId: string | null;
|
|
13
20
|
countryCode: string | null;
|
|
14
|
-
devices:
|
|
21
|
+
devices: VeSyncBaseDevice[] | null;
|
|
15
22
|
enabled: boolean;
|
|
16
23
|
updateInterval: number;
|
|
17
|
-
lastUpdateTs: number | null;
|
|
18
|
-
inProcess: boolean;
|
|
19
24
|
timeZone: string;
|
|
20
25
|
fans: VeSyncBaseDevice[];
|
|
21
26
|
outlets: VeSyncBaseDevice[];
|
|
22
27
|
switches: VeSyncBaseDevice[];
|
|
23
28
|
bulbs: VeSyncBaseDevice[];
|
|
24
29
|
scales: VeSyncBaseDevice[];
|
|
25
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Initialize VeSync Manager
|
|
32
|
+
*/
|
|
26
33
|
constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean);
|
|
34
|
+
/**
|
|
35
|
+
* Get/Set debug mode
|
|
36
|
+
*/
|
|
27
37
|
get debug(): boolean;
|
|
28
|
-
set debug(
|
|
38
|
+
set debug(flag: boolean);
|
|
39
|
+
/**
|
|
40
|
+
* Get/Set redact mode
|
|
41
|
+
*/
|
|
29
42
|
get redact(): boolean;
|
|
30
|
-
set redact(
|
|
43
|
+
set redact(flag: boolean);
|
|
44
|
+
/**
|
|
45
|
+
* Get/Set energy update interval
|
|
46
|
+
*/
|
|
31
47
|
get energyUpdateInterval(): number;
|
|
32
|
-
set energyUpdateInterval(
|
|
48
|
+
set energyUpdateInterval(interval: number);
|
|
33
49
|
/**
|
|
34
|
-
* Test if device should be removed
|
|
50
|
+
* Test if device should be removed
|
|
35
51
|
*/
|
|
36
|
-
static removeDevTest(device: VeSyncBaseDevice, newList:
|
|
52
|
+
static removeDevTest(device: VeSyncBaseDevice, newList: any[]): boolean;
|
|
37
53
|
/**
|
|
38
|
-
*
|
|
54
|
+
* Test if new device should be added
|
|
39
55
|
*/
|
|
40
|
-
|
|
56
|
+
addDevTest(newDev: Record<string, any>): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Remove devices not found in device list return
|
|
59
|
+
*/
|
|
60
|
+
removeOldDevices(devices: any[]): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Correct devices without cid or uuid
|
|
63
|
+
*/
|
|
64
|
+
static setDevId(devices: any[]): any[];
|
|
65
|
+
/**
|
|
66
|
+
* Process device list and instantiate device objects
|
|
67
|
+
*/
|
|
68
|
+
processDevices(devList: any[]): boolean;
|
|
41
69
|
/**
|
|
42
70
|
* Get list of VeSync devices
|
|
43
71
|
*/
|
|
44
72
|
getDevices(): Promise<boolean>;
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Login to VeSync server
|
|
75
|
+
*/
|
|
76
|
+
login(): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Test if update interval has been exceeded
|
|
79
|
+
*/
|
|
80
|
+
deviceTimeCheck(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Update device list and details
|
|
83
|
+
*/
|
|
84
|
+
update(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Create device instance from details
|
|
87
|
+
*/
|
|
88
|
+
createDevice(details: Record<string, any>): VeSyncBaseDevice | null;
|
|
47
89
|
}
|