tsvesync 1.0.12 → 1.0.14

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.
Files changed (70) hide show
  1. package/dist/lib/helpers.js +3 -2
  2. package/dist/lib/logger.d.ts +23 -0
  3. package/dist/lib/logger.js +54 -0
  4. package/dist/lib/vesync.js +42 -41
  5. package/dist/lib/vesyncBaseDevice.js +8 -7
  6. package/dist/lib/vesyncBulb.d.ts +9 -0
  7. package/dist/lib/vesyncBulb.js +125 -28
  8. package/dist/lib/vesyncBulbImpl.d.ts +1 -1
  9. package/dist/lib/vesyncBulbImpl.js +105 -36
  10. package/dist/lib/vesyncFan.js +2 -1
  11. package/dist/lib/vesyncFanImpl.d.ts +36 -0
  12. package/dist/lib/vesyncFanImpl.js +307 -42
  13. package/dist/lib/vesyncOutlet.d.ts +17 -0
  14. package/dist/lib/vesyncOutlet.js +124 -8
  15. package/dist/lib/vesyncOutletImpl.js +39 -0
  16. package/dist/lib/vesyncSwitch.d.ts +0 -124
  17. package/dist/lib/vesyncSwitch.js +3 -343
  18. package/dist/lib/vesyncSwitchImpl.d.ts +6 -6
  19. package/dist/lib/vesyncSwitchImpl.js +69 -15
  20. package/package.json +1 -1
  21. package/src/lib/helpers.ts +3 -2
  22. package/src/lib/logger.ts +60 -0
  23. package/src/lib/vesync.ts +42 -43
  24. package/src/lib/vesyncBaseDevice.ts +8 -7
  25. package/src/lib/vesyncBulb.ts +138 -30
  26. package/src/lib/vesyncBulbImpl.ts +113 -44
  27. package/src/lib/vesyncFan.ts +2 -4
  28. package/src/lib/vesyncFanImpl.ts +314 -42
  29. package/src/lib/vesyncOutlet.ts +140 -13
  30. package/src/lib/vesyncOutletImpl.ts +41 -0
  31. package/src/lib/vesyncSwitch.ts +3 -454
  32. package/src/lib/vesyncSwitchImpl.ts +66 -16
  33. package/dist/lib/helpers.js.map +0 -1
  34. package/dist/lib/vesync.js.map +0 -1
  35. package/dist/lib/vesyncBaseDevice.js.map +0 -1
  36. package/dist/lib/vesyncBulb.js.map +0 -1
  37. package/dist/lib/vesyncFan.js.map +0 -1
  38. package/dist/lib/vesyncKitchen.d.ts +0 -0
  39. package/dist/lib/vesyncKitchen.js +0 -2
  40. package/dist/lib/vesyncKitchen.js.map +0 -1
  41. package/dist/lib/vesyncOutlet.js.map +0 -1
  42. package/dist/lib/vesyncSwitch.js.map +0 -1
  43. package/dist/src/lib/helpers.d.ts +0 -88
  44. package/dist/src/lib/helpers.js +0 -244
  45. package/dist/src/lib/vesync.d.ts +0 -89
  46. package/dist/src/lib/vesync.js +0 -430
  47. package/dist/src/lib/vesyncBaseDevice.d.ts +0 -43
  48. package/dist/src/lib/vesyncBaseDevice.js +0 -87
  49. package/dist/src/lib/vesyncBulb.d.ts +0 -79
  50. package/dist/src/lib/vesyncBulb.js +0 -198
  51. package/dist/src/lib/vesyncBulbImpl.d.ts +0 -38
  52. package/dist/src/lib/vesyncBulbImpl.js +0 -161
  53. package/dist/src/lib/vesyncFan.d.ts +0 -80
  54. package/dist/src/lib/vesyncFan.js +0 -406
  55. package/dist/src/lib/vesyncFanImpl.d.ts +0 -137
  56. package/dist/src/lib/vesyncFanImpl.js +0 -643
  57. package/dist/src/lib/vesyncOutlet.d.ts +0 -53
  58. package/dist/src/lib/vesyncOutlet.js +0 -98
  59. package/dist/src/lib/vesyncOutletImpl.d.ts +0 -70
  60. package/dist/src/lib/vesyncOutletImpl.js +0 -206
  61. package/dist/src/lib/vesyncSwitch.d.ts +0 -169
  62. package/dist/src/lib/vesyncSwitch.js +0 -414
  63. package/dist/src/lib/vesyncSwitchImpl.d.ts +0 -82
  64. package/dist/src/lib/vesyncSwitchImpl.js +0 -290
  65. package/dist/test/testFeatures.d.ts +0 -4
  66. package/dist/test/testFeatures.js +0 -394
  67. package/dist/test/testService.d.ts +0 -62
  68. package/dist/test/testService.js +0 -540
  69. package/dist/test/testSpecial.d.ts +0 -5
  70. package/dist/test/testSpecial.js +0 -227
@@ -1,244 +0,0 @@
1
- "use strict";
2
- /**
3
- * Helper functions for VeSync API
4
- */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
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;
12
- const axios_1 = __importDefault(require("axios"));
13
- const crypto_1 = __importDefault(require("crypto"));
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
- }
22
- exports.API_RATE_LIMIT = 30;
23
- exports.API_TIMEOUT = 5000;
24
- exports.APP_VERSION = '2.8.6';
25
- exports.PHONE_BRAND = 'SM N9005';
26
- exports.PHONE_OS = 'Android';
27
- exports.USER_TYPE = '1';
28
- exports.DEFAULT_TZ = 'America/New_York';
29
- exports.DEFAULT_REGION = 'US';
30
- exports.MOBILE_ID = '1234567890123456';
31
- exports.BYPASS_HEADER_UA = 'okhttp/3.12.1';
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
- }
39
- /**
40
- * Build header for legacy api GET requests
41
- */
42
- static reqHeaders(manager) {
43
- if (!manager.accountId || !manager.token) {
44
- throw new Error('Manager accountId and token must be set');
45
- }
46
- return {
47
- 'accept-language': 'en',
48
- 'accountId': manager.accountId,
49
- 'appVersion': exports.APP_VERSION,
50
- 'content-type': 'application/json',
51
- 'tk': manager.token,
52
- 'tz': manager.timeZone
53
- };
54
- }
55
- /**
56
- * Build header for api requests on 'bypass' endpoint
57
- */
58
- static reqHeaderBypass() {
59
- return {
60
- 'Content-Type': 'application/json; charset=UTF-8',
61
- 'User-Agent': exports.BYPASS_HEADER_UA
62
- };
63
- }
64
- /**
65
- * Return universal keys for body of api requests
66
- */
67
- static reqBodyBase(manager) {
68
- return {
69
- 'timeZone': manager.timeZone,
70
- 'acceptLanguage': 'en'
71
- };
72
- }
73
- /**
74
- * Keys for authenticating api requests
75
- */
76
- static reqBodyAuth(manager) {
77
- if (!manager.accountId || !manager.token) {
78
- throw new Error('Manager accountId and token must be set');
79
- }
80
- return {
81
- 'accountID': manager.accountId,
82
- 'token': manager.token
83
- };
84
- }
85
- /**
86
- * Detail keys for api requests
87
- */
88
- static reqBodyDetails() {
89
- return {
90
- 'appVersion': exports.APP_VERSION,
91
- 'phoneBrand': exports.PHONE_BRAND,
92
- 'phoneOS': exports.PHONE_OS,
93
- 'traceId': Date.now().toString()
94
- };
95
- }
96
- /**
97
- * Builder for body of api requests
98
- */
99
- static reqBody(manager, type) {
100
- const body = {
101
- ...this.reqBodyBase(manager)
102
- };
103
- if (type === 'login') {
104
- return {
105
- ...body,
106
- ...this.reqBodyDetails(),
107
- email: manager.username,
108
- password: this.hashPassword(manager.password),
109
- devToken: '',
110
- userType: exports.USER_TYPE,
111
- method: 'login'
112
- };
113
- }
114
- const authBody = {
115
- ...body,
116
- ...this.reqBodyAuth(manager)
117
- };
118
- if (type === 'devicestatus') {
119
- return authBody;
120
- }
121
- const fullBody = {
122
- ...authBody,
123
- ...this.reqBodyDetails()
124
- };
125
- switch (type) {
126
- case 'devicelist':
127
- return {
128
- ...fullBody,
129
- method: 'devices',
130
- pageNo: '1',
131
- pageSize: '100'
132
- };
133
- case 'devicedetail':
134
- return {
135
- ...fullBody,
136
- method: 'devicedetail',
137
- mobileId: exports.MOBILE_ID
138
- };
139
- case 'bypass':
140
- return {
141
- ...fullBody,
142
- method: 'bypass'
143
- };
144
- case 'bypassV2':
145
- return {
146
- ...fullBody,
147
- deviceRegion: exports.DEFAULT_REGION,
148
- method: 'bypassV2'
149
- };
150
- case 'bypass_config':
151
- return {
152
- ...fullBody,
153
- method: 'firmwareUpdateInfo'
154
- };
155
- default:
156
- return fullBody;
157
- }
158
- }
159
- /**
160
- * Call VeSync API
161
- */
162
- static async callApi(endpoint, method, data = null, headers = {}) {
163
- try {
164
- const url = _apiBaseUrl + endpoint;
165
- const response = await (0, axios_1.default)({
166
- method,
167
- url,
168
- data,
169
- headers,
170
- timeout: exports.API_TIMEOUT
171
- });
172
- return [response.data, response.status];
173
- }
174
- catch (error) {
175
- if (error.response) {
176
- return [error.response.data, error.response.status];
177
- }
178
- console.error('API call failed:', error.message);
179
- return [null, 0];
180
- }
181
- }
182
- /**
183
- * Calculate hex value from energy response
184
- */
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';
192
- }
193
- try {
194
- const decoded = Buffer.from(value, 'hex');
195
- return decoded.readFloatBE(0).toString();
196
- }
197
- catch (error) {
198
- console.debug('Error decoding hex value:', error);
199
- return '0';
200
- }
201
- }
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
- };
219
- }
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');
241
- }
242
- }
243
- exports.Helpers = Helpers;
244
- Helpers.shouldRedact = true;
@@ -1,89 +0,0 @@
1
- /**
2
- * VeSync API Device Library
3
- */
4
- import { VeSyncBaseDevice } from './vesyncBaseDevice';
5
- /**
6
- * VeSync Manager Class
7
- */
8
- export declare class VeSync {
9
- private _debug;
10
- private _redact;
11
- private _energyUpdateInterval;
12
- private _energyCheck;
13
- private _devList;
14
- private _lastUpdateTs;
15
- private _inProcess;
16
- username: string;
17
- password: string;
18
- token: string | null;
19
- accountId: string | null;
20
- countryCode: string | null;
21
- devices: VeSyncBaseDevice[] | null;
22
- enabled: boolean;
23
- updateInterval: number;
24
- timeZone: string;
25
- fans: VeSyncBaseDevice[];
26
- outlets: VeSyncBaseDevice[];
27
- switches: VeSyncBaseDevice[];
28
- bulbs: VeSyncBaseDevice[];
29
- scales: VeSyncBaseDevice[];
30
- /**
31
- * Initialize VeSync Manager
32
- */
33
- constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean);
34
- /**
35
- * Get/Set debug mode
36
- */
37
- get debug(): boolean;
38
- set debug(flag: boolean);
39
- /**
40
- * Get/Set redact mode
41
- */
42
- get redact(): boolean;
43
- set redact(flag: boolean);
44
- /**
45
- * Get/Set energy update interval
46
- */
47
- get energyUpdateInterval(): number;
48
- set energyUpdateInterval(interval: number);
49
- /**
50
- * Test if device should be removed
51
- */
52
- static removeDevTest(device: VeSyncBaseDevice, newList: any[]): boolean;
53
- /**
54
- * Test if new device should be added
55
- */
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;
69
- /**
70
- * Get list of VeSync devices
71
- */
72
- getDevices(): Promise<boolean>;
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;
89
- }