tsvesync 1.0.13 → 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.
- package/package.json +1 -1
- package/dist/lib/helpers.js.map +0 -1
- package/dist/lib/vesync.js.map +0 -1
- package/dist/lib/vesyncBaseDevice.js.map +0 -1
- package/dist/lib/vesyncBulb.js.map +0 -1
- package/dist/lib/vesyncFan.js.map +0 -1
- package/dist/lib/vesyncKitchen.d.ts +0 -0
- package/dist/lib/vesyncKitchen.js +0 -2
- package/dist/lib/vesyncKitchen.js.map +0 -1
- package/dist/lib/vesyncOutlet.js.map +0 -1
- package/dist/lib/vesyncSwitch.js.map +0 -1
- package/dist/src/lib/helpers.d.ts +0 -88
- package/dist/src/lib/helpers.js +0 -244
- package/dist/src/lib/vesync.d.ts +0 -89
- package/dist/src/lib/vesync.js +0 -430
- package/dist/src/lib/vesyncBaseDevice.d.ts +0 -43
- package/dist/src/lib/vesyncBaseDevice.js +0 -87
- package/dist/src/lib/vesyncBulb.d.ts +0 -79
- package/dist/src/lib/vesyncBulb.js +0 -198
- package/dist/src/lib/vesyncBulbImpl.d.ts +0 -38
- package/dist/src/lib/vesyncBulbImpl.js +0 -161
- package/dist/src/lib/vesyncFan.d.ts +0 -80
- package/dist/src/lib/vesyncFan.js +0 -406
- package/dist/src/lib/vesyncFanImpl.d.ts +0 -137
- package/dist/src/lib/vesyncFanImpl.js +0 -643
- package/dist/src/lib/vesyncOutlet.d.ts +0 -53
- package/dist/src/lib/vesyncOutlet.js +0 -98
- package/dist/src/lib/vesyncOutletImpl.d.ts +0 -70
- package/dist/src/lib/vesyncOutletImpl.js +0 -206
- package/dist/src/lib/vesyncSwitch.d.ts +0 -169
- package/dist/src/lib/vesyncSwitch.js +0 -414
- package/dist/src/lib/vesyncSwitchImpl.d.ts +0 -82
- package/dist/src/lib/vesyncSwitchImpl.js +0 -290
- package/dist/test/testFeatures.d.ts +0 -4
- package/dist/test/testFeatures.js +0 -394
- package/dist/test/testService.d.ts +0 -62
- package/dist/test/testService.js +0 -540
- package/dist/test/testSpecial.d.ts +0 -5
- package/dist/test/testSpecial.js +0 -227
package/dist/test/testSpecial.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Special test for VeSync API
|
|
4
|
-
* Uses credentials from .env file in test directory
|
|
5
|
-
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
// Load environment variables first
|
|
41
|
-
const dotenv = __importStar(require("dotenv"));
|
|
42
|
-
// Load .env file from test directory before any other imports
|
|
43
|
-
dotenv.config({ path: '.env' });
|
|
44
|
-
// Now import the rest of the modules
|
|
45
|
-
const vesync_1 = require("../src/lib/vesync");
|
|
46
|
-
const helpers_1 = require("../src/lib/helpers");
|
|
47
|
-
const helpers_2 = require("../src/lib/helpers");
|
|
48
|
-
/**
|
|
49
|
-
* Print detailed device status
|
|
50
|
-
*/
|
|
51
|
-
async function printDeviceStatus(device) {
|
|
52
|
-
console.log(`\n${device.deviceName} Status:`);
|
|
53
|
-
console.log('-'.repeat(device.deviceName.length + 8));
|
|
54
|
-
console.log('Device Name:', device.deviceName);
|
|
55
|
-
console.log('Device Type:', device.deviceType);
|
|
56
|
-
console.log('Config Module:', device.configModule);
|
|
57
|
-
console.log('Device Status:', device.deviceStatus);
|
|
58
|
-
console.log('UUID:', device.uuid);
|
|
59
|
-
console.log('MAC ID:', device.macId || 'Not available');
|
|
60
|
-
// Get latest device details
|
|
61
|
-
await device.update();
|
|
62
|
-
// Handle power devices (outlets and switches)
|
|
63
|
-
if (['ESO15-TB', 'ESW03-USA', 'wifi-switch-1.3'].includes(device.deviceType)) {
|
|
64
|
-
try {
|
|
65
|
-
// Get device details based on type
|
|
66
|
-
if (device.deviceType === 'wifi-switch-1.3') {
|
|
67
|
-
const [response] = await helpers_2.Helpers.callApi(`/v1/device/${device.cid}/detail`, 'get', null, helpers_2.Helpers.reqHeaders(device.manager));
|
|
68
|
-
if (response?.code === 0) {
|
|
69
|
-
console.log('Power:', response.power ? `${response.power} W` : 'Not available');
|
|
70
|
-
console.log('Voltage:', response.voltage ? `${response.voltage} V` : 'Not available');
|
|
71
|
-
console.log('Today\'s Energy:', response.energy ? `${response.energy} kWh` : 'Not available');
|
|
72
|
-
console.log('Active Time:', response.activeTime ? `${response.activeTime} minutes` : 'Not available');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// For 10A and 15A outlets
|
|
77
|
-
const body = {
|
|
78
|
-
...helpers_2.Helpers.reqBody(device.manager, 'devicedetail'),
|
|
79
|
-
uuid: device.uuid
|
|
80
|
-
};
|
|
81
|
-
const endpoint = device.deviceType === 'ESW03-USA' ? '/10a/v1/device/devicedetail' : '/15a/v1/device/devicedetail';
|
|
82
|
-
const [response] = await helpers_2.Helpers.callApi(endpoint, 'post', body, helpers_2.Helpers.reqHeaders(device.manager));
|
|
83
|
-
if (response?.code === 0) {
|
|
84
|
-
console.log('Power:', response.power ? `${response.power} W` : 'Not available');
|
|
85
|
-
console.log('Voltage:', response.voltage ? `${response.voltage} V` : 'Not available');
|
|
86
|
-
console.log('Today\'s Energy:', response.energy ? `${response.energy} kWh` : 'Not available');
|
|
87
|
-
console.log('Active Time:', response.activeTime ? `${response.activeTime} minutes` : 'Not available');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Get energy history
|
|
91
|
-
console.log('Energy Usage:');
|
|
92
|
-
// Weekly energy
|
|
93
|
-
const weekBody = {
|
|
94
|
-
...helpers_2.Helpers.reqBody(device.manager, 'energy_week'),
|
|
95
|
-
uuid: device.uuid
|
|
96
|
-
};
|
|
97
|
-
const weekEndpoint = device.deviceType === 'ESW03-USA' ? '/10a/v1/device/energyweek' : '/15a/v1/device/energyweek';
|
|
98
|
-
const [weekResponse] = await helpers_2.Helpers.callApi(weekEndpoint, 'post', weekBody, helpers_2.Helpers.reqHeaders(device.manager));
|
|
99
|
-
console.log(' Week:', weekResponse?.code === 0 ? `${weekResponse.totalEnergy} kWh` : 'Not available');
|
|
100
|
-
// Monthly energy
|
|
101
|
-
const monthBody = {
|
|
102
|
-
...helpers_2.Helpers.reqBody(device.manager, 'energy_month'),
|
|
103
|
-
uuid: device.uuid
|
|
104
|
-
};
|
|
105
|
-
const monthEndpoint = device.deviceType === 'ESW03-USA' ? '/10a/v1/device/energymonth' : '/15a/v1/device/energymonth';
|
|
106
|
-
const [monthResponse] = await helpers_2.Helpers.callApi(monthEndpoint, 'post', monthBody, helpers_2.Helpers.reqHeaders(device.manager));
|
|
107
|
-
console.log(' Month:', monthResponse?.code === 0 ? `${monthResponse.totalEnergy} kWh` : 'Not available');
|
|
108
|
-
// Yearly energy
|
|
109
|
-
const yearBody = {
|
|
110
|
-
...helpers_2.Helpers.reqBody(device.manager, 'energy_year'),
|
|
111
|
-
uuid: device.uuid
|
|
112
|
-
};
|
|
113
|
-
const yearEndpoint = device.deviceType === 'ESW03-USA' ? '/10a/v1/device/energyyear' : '/15a/v1/device/energyyear';
|
|
114
|
-
const [yearResponse] = await helpers_2.Helpers.callApi(yearEndpoint, 'post', yearBody, helpers_2.Helpers.reqHeaders(device.manager));
|
|
115
|
-
console.log(' Year:', yearResponse?.code === 0 ? `${yearResponse.totalEnergy} kWh` : 'Not available');
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
console.log('Power: Error retrieving data');
|
|
119
|
-
console.log('Voltage: Error retrieving data');
|
|
120
|
-
console.log('Energy Usage:');
|
|
121
|
-
console.log(' Week: Error retrieving data');
|
|
122
|
-
console.log(' Month: Error retrieving data');
|
|
123
|
-
console.log(' Year: Error retrieving data');
|
|
124
|
-
console.log('Error details:', error);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Print fan-specific details if available
|
|
128
|
-
if (device.deviceType.toLowerCase().includes('core')) {
|
|
129
|
-
try {
|
|
130
|
-
console.log('Fan Details:');
|
|
131
|
-
console.log(' Mode:', device.details?.mode || 'Not available');
|
|
132
|
-
console.log(' Fan Speed:', device.details?.speed || 'Not available');
|
|
133
|
-
console.log(' Filter Life:', device.details?.filterLife ? `${device.details.filterLife}%` : 'Not available');
|
|
134
|
-
console.log(' Screen Status:', device.details?.screenStatus !== undefined ? device.details.screenStatus : 'Not available');
|
|
135
|
-
console.log(' Child Lock:', device.details?.childLock !== undefined ? device.details.childLock : 'Not available');
|
|
136
|
-
if (device.deviceType === 'Core300S') {
|
|
137
|
-
console.log(' Air Quality:', device.details?.airQuality !== undefined ? device.details.airQuality : 'Not available');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
console.log(' Error getting fan details');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async function runTest() {
|
|
146
|
-
// Get credentials from .env
|
|
147
|
-
const username = process.env.VESYNC_USERNAME;
|
|
148
|
-
const password = process.env.VESYNC_PASSWORD;
|
|
149
|
-
const apiUrl = process.env.VESYNC_API_URL || 'https://smartapi.vesync.com';
|
|
150
|
-
if (!username || !password) {
|
|
151
|
-
console.error('Error: VESYNC_USERNAME and VESYNC_PASSWORD must be set in .env file');
|
|
152
|
-
process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
console.log('Using credentials from .env');
|
|
155
|
-
console.log(`Username: ${username}`);
|
|
156
|
-
console.log(`Password: ${password.replace(/./g, '*')}`);
|
|
157
|
-
// Set API URL
|
|
158
|
-
(0, helpers_1.setApiBaseUrl)(apiUrl);
|
|
159
|
-
console.log(`Using API URL: ${apiUrl}`);
|
|
160
|
-
// Create VeSync manager
|
|
161
|
-
const manager = new vesync_1.VeSync(username, password);
|
|
162
|
-
// Attempt login
|
|
163
|
-
console.log('\nAttempting login...');
|
|
164
|
-
if (!await manager.login()) {
|
|
165
|
-
console.error('Login failed');
|
|
166
|
-
process.exit(1);
|
|
167
|
-
}
|
|
168
|
-
console.log('Login successful');
|
|
169
|
-
// Get devices
|
|
170
|
-
console.log('\nGetting device list...');
|
|
171
|
-
await manager.getDevices();
|
|
172
|
-
if (!manager.devices || manager.devices.length === 0) {
|
|
173
|
-
console.log('No devices found');
|
|
174
|
-
process.exit(0);
|
|
175
|
-
}
|
|
176
|
-
// Print device discovery summary
|
|
177
|
-
console.log('\n=== Device Discovery Summary ===');
|
|
178
|
-
console.log('Total devices processed:', manager.devices.length);
|
|
179
|
-
// Get unique device types
|
|
180
|
-
const deviceTypes = [...new Set(manager.devices.map(d => d.deviceType))];
|
|
181
|
-
console.log('\nDevice types found:', JSON.stringify(deviceTypes, null, 2));
|
|
182
|
-
// Group devices by category
|
|
183
|
-
console.log('\nDevices by Category:');
|
|
184
|
-
console.log('---------------------\n');
|
|
185
|
-
// Fans
|
|
186
|
-
const fans = manager.devices.filter(d => d.deviceType.toLowerCase().includes('core'));
|
|
187
|
-
if (fans.length > 0) {
|
|
188
|
-
console.log('FANS (' + fans.length + ' devices):');
|
|
189
|
-
fans.forEach(d => {
|
|
190
|
-
console.log(` • ${d.deviceName}`);
|
|
191
|
-
console.log(` Type: ${d.deviceType}`);
|
|
192
|
-
console.log(` Status: ${d.deviceStatus}`);
|
|
193
|
-
console.log(` ID: ${d.cid}`);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
// Outlets
|
|
197
|
-
const outlets = manager.devices.filter(d => ['ESO15-TB', 'ESW03-USA', 'wifi-switch-1.3'].includes(d.deviceType));
|
|
198
|
-
if (outlets.length > 0) {
|
|
199
|
-
console.log('\nOUTLETS (' + outlets.length + ' devices):');
|
|
200
|
-
outlets.forEach(d => {
|
|
201
|
-
console.log(` • ${d.deviceName}`);
|
|
202
|
-
console.log(` Type: ${d.deviceType}`);
|
|
203
|
-
console.log(` Status: ${d.deviceStatus}`);
|
|
204
|
-
console.log(` ID: ${d.cid}`);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// Print summary statistics
|
|
208
|
-
console.log('\nSummary Statistics:');
|
|
209
|
-
console.log('-------------------');
|
|
210
|
-
console.log('Total Devices:', manager.devices.length);
|
|
211
|
-
console.log('fans:', fans.length, 'devices');
|
|
212
|
-
console.log('outlets:', outlets.length, 'devices');
|
|
213
|
-
console.log('switches:', manager.devices.filter(d => d.deviceType.toLowerCase().includes('switch')).length, 'devices');
|
|
214
|
-
console.log('bulbs:', manager.devices.filter(d => d.deviceType.toLowerCase().includes('bulb')).length, 'devices');
|
|
215
|
-
console.log('\n=== End of Device Discovery ===\n');
|
|
216
|
-
// Print detailed status for all devices
|
|
217
|
-
console.log('\n=== Device Status Summary ===');
|
|
218
|
-
for (const device of manager.devices) {
|
|
219
|
-
await printDeviceStatus(device);
|
|
220
|
-
}
|
|
221
|
-
console.log('\nTest complete');
|
|
222
|
-
}
|
|
223
|
-
// Run the test
|
|
224
|
-
runTest().catch(error => {
|
|
225
|
-
console.error('Test failed:', error);
|
|
226
|
-
process.exit(1);
|
|
227
|
-
});
|