tsvesync 1.0.11 → 1.0.13
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 +135 -112
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.js +54 -0
- package/dist/lib/vesync.d.ts +57 -15
- package/dist/lib/vesync.js +341 -217
- package/dist/lib/vesyncBaseDevice.d.ts +25 -50
- package/dist/lib/vesyncBaseDevice.js +63 -90
- package/dist/lib/vesyncBulb.d.ts +88 -0
- package/dist/lib/vesyncBulb.js +295 -1
- package/dist/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/lib/vesyncBulbImpl.js +230 -0
- package/dist/lib/vesyncFan.d.ts +55 -67
- package/dist/lib/vesyncFan.js +366 -213
- package/dist/lib/vesyncFanImpl.d.ts +173 -0
- package/dist/lib/vesyncFanImpl.js +909 -0
- package/dist/lib/vesyncOutlet.d.ts +70 -0
- package/dist/lib/vesyncOutlet.js +213 -1
- package/dist/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/lib/vesyncOutletImpl.js +245 -0
- package/dist/lib/vesyncSwitch.d.ts +45 -0
- package/dist/lib/vesyncSwitch.js +77 -1
- package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/lib/vesyncSwitchImpl.js +344 -0
- package/package.json +1 -1
- package/src/index.ts +14 -0
- package/src/lib/helpers.ts +3 -2
- package/src/lib/logger.ts +60 -0
- package/src/lib/vesync.ts +42 -43
- package/src/lib/vesyncBaseDevice.ts +8 -7
- package/src/lib/vesyncBulb.ts +138 -30
- package/src/lib/vesyncBulbImpl.ts +113 -44
- package/src/lib/vesyncFan.ts +2 -4
- package/src/lib/vesyncFanImpl.ts +314 -42
- package/src/lib/vesyncOutlet.ts +140 -13
- package/src/lib/vesyncOutletImpl.ts +41 -0
- package/src/lib/vesyncSwitch.ts +3 -454
- package/src/lib/vesyncSwitchImpl.ts +66 -16
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,56 @@
|
|
|
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
|
+
const logger_1 = require("./logger");
|
|
15
|
+
// API configuration
|
|
16
|
+
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
17
|
+
function getApiBaseUrl() {
|
|
18
|
+
return _apiBaseUrl;
|
|
19
|
+
}
|
|
20
|
+
function setApiBaseUrl(url) {
|
|
21
|
+
_apiBaseUrl = url;
|
|
22
|
+
}
|
|
13
23
|
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';
|
|
24
|
+
exports.API_TIMEOUT = 5000;
|
|
18
25
|
exports.APP_VERSION = '2.8.6';
|
|
19
26
|
exports.PHONE_BRAND = 'SM N9005';
|
|
20
27
|
exports.PHONE_OS = 'Android';
|
|
21
|
-
exports.MOBILE_ID = '1234567890123456';
|
|
22
28
|
exports.USER_TYPE = '1';
|
|
23
|
-
exports.
|
|
29
|
+
exports.DEFAULT_TZ = 'America/New_York';
|
|
30
|
+
exports.DEFAULT_REGION = 'US';
|
|
31
|
+
exports.MOBILE_ID = '1234567890123456';
|
|
24
32
|
exports.BYPASS_HEADER_UA = 'okhttp/3.12.1';
|
|
25
33
|
class Helpers {
|
|
34
|
+
/**
|
|
35
|
+
* Calculate MD5 hash
|
|
36
|
+
*/
|
|
37
|
+
static md5(text) {
|
|
38
|
+
return crypto_1.default.createHash('md5').update(text).digest('hex');
|
|
39
|
+
}
|
|
26
40
|
/**
|
|
27
41
|
* Build header for legacy api GET requests
|
|
28
42
|
*/
|
|
29
43
|
static reqHeaders(manager) {
|
|
44
|
+
if (!manager.accountId || !manager.token) {
|
|
45
|
+
throw new Error('Manager accountId and token must be set');
|
|
46
|
+
}
|
|
30
47
|
return {
|
|
31
48
|
'accept-language': 'en',
|
|
32
49
|
'accountId': manager.accountId,
|
|
33
50
|
'appVersion': exports.APP_VERSION,
|
|
34
51
|
'content-type': 'application/json',
|
|
35
52
|
'tk': manager.token,
|
|
36
|
-
'tz': manager.timeZone
|
|
53
|
+
'tz': manager.timeZone
|
|
37
54
|
};
|
|
38
55
|
}
|
|
39
56
|
/**
|
|
@@ -42,7 +59,7 @@ class Helpers {
|
|
|
42
59
|
static reqHeaderBypass() {
|
|
43
60
|
return {
|
|
44
61
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
45
|
-
'User-Agent': exports.BYPASS_HEADER_UA
|
|
62
|
+
'User-Agent': exports.BYPASS_HEADER_UA
|
|
46
63
|
};
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
@@ -58,6 +75,9 @@ class Helpers {
|
|
|
58
75
|
* Keys for authenticating api requests
|
|
59
76
|
*/
|
|
60
77
|
static reqBodyAuth(manager) {
|
|
78
|
+
if (!manager.accountId || !manager.token) {
|
|
79
|
+
throw new Error('Manager accountId and token must be set');
|
|
80
|
+
}
|
|
61
81
|
return {
|
|
62
82
|
'accountID': manager.accountId,
|
|
63
83
|
'token': manager.token
|
|
@@ -71,16 +91,18 @@ class Helpers {
|
|
|
71
91
|
'appVersion': exports.APP_VERSION,
|
|
72
92
|
'phoneBrand': exports.PHONE_BRAND,
|
|
73
93
|
'phoneOS': exports.PHONE_OS,
|
|
74
|
-
'traceId':
|
|
94
|
+
'traceId': Date.now().toString()
|
|
75
95
|
};
|
|
76
96
|
}
|
|
77
97
|
/**
|
|
78
98
|
* Builder for body of api requests
|
|
79
99
|
*/
|
|
80
100
|
static reqBody(manager, type) {
|
|
81
|
-
|
|
101
|
+
const body = {
|
|
102
|
+
...this.reqBodyBase(manager)
|
|
103
|
+
};
|
|
82
104
|
if (type === 'login') {
|
|
83
|
-
|
|
105
|
+
return {
|
|
84
106
|
...body,
|
|
85
107
|
...this.reqBodyDetails(),
|
|
86
108
|
email: manager.username,
|
|
@@ -89,72 +111,64 @@ class Helpers {
|
|
|
89
111
|
userType: exports.USER_TYPE,
|
|
90
112
|
method: 'login'
|
|
91
113
|
};
|
|
92
|
-
return body;
|
|
93
114
|
}
|
|
94
|
-
|
|
115
|
+
const authBody = {
|
|
116
|
+
...body,
|
|
117
|
+
...this.reqBodyAuth(manager)
|
|
118
|
+
};
|
|
95
119
|
if (type === 'devicestatus') {
|
|
96
|
-
return
|
|
120
|
+
return authBody;
|
|
97
121
|
}
|
|
98
|
-
|
|
122
|
+
const fullBody = {
|
|
123
|
+
...authBody,
|
|
124
|
+
...this.reqBodyDetails()
|
|
125
|
+
};
|
|
99
126
|
switch (type) {
|
|
100
127
|
case 'devicelist':
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
return {
|
|
129
|
+
...fullBody,
|
|
130
|
+
method: 'devices',
|
|
131
|
+
pageNo: '1',
|
|
132
|
+
pageSize: '100'
|
|
133
|
+
};
|
|
105
134
|
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;
|
|
135
|
+
return {
|
|
136
|
+
...fullBody,
|
|
137
|
+
method: 'devicedetail',
|
|
138
|
+
mobileId: exports.MOBILE_ID
|
|
139
|
+
};
|
|
121
140
|
case 'bypass':
|
|
122
|
-
|
|
123
|
-
|
|
141
|
+
return {
|
|
142
|
+
...fullBody,
|
|
143
|
+
method: 'bypass'
|
|
144
|
+
};
|
|
124
145
|
case 'bypassV2':
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
return {
|
|
147
|
+
...fullBody,
|
|
148
|
+
deviceRegion: exports.DEFAULT_REGION,
|
|
149
|
+
method: 'bypassV2'
|
|
150
|
+
};
|
|
128
151
|
case 'bypass_config':
|
|
129
|
-
|
|
130
|
-
|
|
152
|
+
return {
|
|
153
|
+
...fullBody,
|
|
154
|
+
method: 'firmwareUpdateInfo'
|
|
155
|
+
};
|
|
156
|
+
default:
|
|
157
|
+
return fullBody;
|
|
131
158
|
}
|
|
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
159
|
}
|
|
141
160
|
/**
|
|
142
|
-
*
|
|
161
|
+
* Call VeSync API
|
|
143
162
|
*/
|
|
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) {
|
|
163
|
+
static async callApi(endpoint, method, data = null, headers = {}) {
|
|
151
164
|
try {
|
|
165
|
+
const url = _apiBaseUrl + endpoint;
|
|
152
166
|
const response = await (0, axios_1.default)({
|
|
153
|
-
method
|
|
154
|
-
url
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
timeout: exports.API_TIMEOUT
|
|
167
|
+
method,
|
|
168
|
+
url,
|
|
169
|
+
data,
|
|
170
|
+
headers,
|
|
171
|
+
timeout: exports.API_TIMEOUT
|
|
158
172
|
});
|
|
159
173
|
return [response.data, response.status];
|
|
160
174
|
}
|
|
@@ -162,61 +176,70 @@ class Helpers {
|
|
|
162
176
|
if (error.response) {
|
|
163
177
|
return [error.response.data, error.response.status];
|
|
164
178
|
}
|
|
165
|
-
|
|
179
|
+
logger_1.logger.error('API call failed:', error.message);
|
|
180
|
+
return [null, 0];
|
|
166
181
|
}
|
|
167
182
|
}
|
|
168
183
|
/**
|
|
169
|
-
*
|
|
184
|
+
* Calculate hex value from energy response
|
|
170
185
|
*/
|
|
171
|
-
static
|
|
172
|
-
if (!
|
|
173
|
-
return
|
|
186
|
+
static calculateHex(hexStr) {
|
|
187
|
+
if (!hexStr || !hexStr.includes(':')) {
|
|
188
|
+
return '0';
|
|
189
|
+
}
|
|
190
|
+
const [prefix, value] = hexStr.split(':');
|
|
191
|
+
if (!prefix || !value) {
|
|
192
|
+
return '0';
|
|
174
193
|
}
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
return
|
|
194
|
+
try {
|
|
195
|
+
const decoded = Buffer.from(value, 'hex');
|
|
196
|
+
return decoded.readFloatBE(0).toString();
|
|
178
197
|
}
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
catch (error) {
|
|
199
|
+
logger_1.logger.debug('Error decoding hex value:', error);
|
|
200
|
+
return '0';
|
|
181
201
|
}
|
|
182
|
-
return value;
|
|
183
202
|
}
|
|
184
|
-
|
|
185
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Build energy dictionary from API response
|
|
205
|
+
*/
|
|
206
|
+
static buildEnergyDict(result) {
|
|
207
|
+
if (!result) {
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
energy_consumption_of_today: result.energyConsumptionOfToday || 0,
|
|
212
|
+
cost_per_kwh: result.costPerKWH || 0,
|
|
213
|
+
max_energy: result.maxEnergy || 0,
|
|
214
|
+
total_energy: result.totalEnergy || 0,
|
|
215
|
+
data: result.data || [],
|
|
216
|
+
energy_consumption: result.energy || 0,
|
|
217
|
+
start_time: result.startTime || '',
|
|
218
|
+
end_time: result.endTime || ''
|
|
219
|
+
};
|
|
186
220
|
}
|
|
187
|
-
|
|
188
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Build configuration dictionary from API response
|
|
223
|
+
*/
|
|
224
|
+
static buildConfigDict(result) {
|
|
225
|
+
if (!result) {
|
|
226
|
+
return {};
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
configModule: result.configModule || '',
|
|
230
|
+
firmwareVersion: result.currentFirmVersion || '',
|
|
231
|
+
deviceRegion: result.deviceRegion || '',
|
|
232
|
+
debugMode: result.debugMode || false,
|
|
233
|
+
deviceTimezone: result.deviceTimezone || exports.DEFAULT_TZ,
|
|
234
|
+
...result
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Calculate MD5 hash
|
|
239
|
+
*/
|
|
240
|
+
static hashPassword(text) {
|
|
241
|
+
return crypto_1.default.createHash('md5').update(text).digest('hex');
|
|
189
242
|
}
|
|
190
243
|
}
|
|
191
244
|
exports.Helpers = Helpers;
|
|
192
245
|
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
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility for TSVeSync
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
DEBUG = 0,
|
|
6
|
+
INFO = 1,
|
|
7
|
+
WARN = 2,
|
|
8
|
+
ERROR = 3,
|
|
9
|
+
NONE = 4
|
|
10
|
+
}
|
|
11
|
+
export declare class Logger {
|
|
12
|
+
private static instance;
|
|
13
|
+
private currentLevel;
|
|
14
|
+
private constructor();
|
|
15
|
+
static getInstance(): Logger;
|
|
16
|
+
setLevel(level: LogLevel): void;
|
|
17
|
+
getLevel(): LogLevel;
|
|
18
|
+
debug(message: string, ...args: any[]): void;
|
|
19
|
+
info(message: string, ...args: any[]): void;
|
|
20
|
+
warn(message: string, ...args: any[]): void;
|
|
21
|
+
error(message: string, ...args: any[]): void;
|
|
22
|
+
}
|
|
23
|
+
export declare const logger: Logger;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger utility for TSVeSync
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = exports.Logger = exports.LogLevel = void 0;
|
|
7
|
+
var LogLevel;
|
|
8
|
+
(function (LogLevel) {
|
|
9
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
10
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
11
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
12
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
13
|
+
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
14
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
15
|
+
class Logger {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.currentLevel = LogLevel.INFO;
|
|
18
|
+
}
|
|
19
|
+
static getInstance() {
|
|
20
|
+
if (!Logger.instance) {
|
|
21
|
+
Logger.instance = new Logger();
|
|
22
|
+
}
|
|
23
|
+
return Logger.instance;
|
|
24
|
+
}
|
|
25
|
+
setLevel(level) {
|
|
26
|
+
this.currentLevel = level;
|
|
27
|
+
}
|
|
28
|
+
getLevel() {
|
|
29
|
+
return this.currentLevel;
|
|
30
|
+
}
|
|
31
|
+
debug(message, ...args) {
|
|
32
|
+
if (this.currentLevel <= LogLevel.DEBUG) {
|
|
33
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
info(message, ...args) {
|
|
37
|
+
if (this.currentLevel <= LogLevel.INFO) {
|
|
38
|
+
console.log(`[INFO] ${message}`, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
warn(message, ...args) {
|
|
42
|
+
if (this.currentLevel <= LogLevel.WARN) {
|
|
43
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
error(message, ...args) {
|
|
47
|
+
if (this.currentLevel <= LogLevel.ERROR) {
|
|
48
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.Logger = Logger;
|
|
53
|
+
// Export singleton instance
|
|
54
|
+
exports.logger = Logger.getInstance();
|