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.
- package/dist/lib/helpers.js +3 -2
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.js +54 -0
- package/dist/lib/vesync.js +42 -41
- package/dist/lib/vesyncBaseDevice.js +8 -7
- package/dist/lib/vesyncBulb.d.ts +9 -0
- package/dist/lib/vesyncBulb.js +125 -28
- package/dist/lib/vesyncBulbImpl.d.ts +1 -1
- package/dist/lib/vesyncBulbImpl.js +105 -36
- package/dist/lib/vesyncFan.js +2 -1
- package/dist/lib/vesyncFanImpl.d.ts +36 -0
- package/dist/lib/vesyncFanImpl.js +307 -42
- package/dist/lib/vesyncOutlet.d.ts +17 -0
- package/dist/lib/vesyncOutlet.js +124 -8
- package/dist/lib/vesyncOutletImpl.js +39 -0
- package/dist/lib/vesyncSwitch.d.ts +0 -124
- package/dist/lib/vesyncSwitch.js +3 -343
- package/dist/lib/vesyncSwitchImpl.d.ts +6 -6
- package/dist/lib/vesyncSwitchImpl.js +69 -15
- package/package.json +1 -1
- 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/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/lib/helpers.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.getApiBaseUrl = getApiBaseUrl;
|
|
|
11
11
|
exports.setApiBaseUrl = setApiBaseUrl;
|
|
12
12
|
const axios_1 = __importDefault(require("axios"));
|
|
13
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
+
const logger_1 = require("./logger");
|
|
14
15
|
// API configuration
|
|
15
16
|
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
16
17
|
function getApiBaseUrl() {
|
|
@@ -175,7 +176,7 @@ class Helpers {
|
|
|
175
176
|
if (error.response) {
|
|
176
177
|
return [error.response.data, error.response.status];
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
logger_1.logger.error('API call failed:', error.message);
|
|
179
180
|
return [null, 0];
|
|
180
181
|
}
|
|
181
182
|
}
|
|
@@ -195,7 +196,7 @@ class Helpers {
|
|
|
195
196
|
return decoded.readFloatBE(0).toString();
|
|
196
197
|
}
|
|
197
198
|
catch (error) {
|
|
198
|
-
|
|
199
|
+
logger_1.logger.debug('Error decoding hex value:', error);
|
|
199
200
|
return '0';
|
|
200
201
|
}
|
|
201
202
|
}
|
|
@@ -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();
|
package/dist/lib/vesync.js
CHANGED
|
@@ -9,6 +9,7 @@ const vesyncFanImpl_1 = require("./vesyncFanImpl");
|
|
|
9
9
|
const vesyncOutletImpl_1 = require("./vesyncOutletImpl");
|
|
10
10
|
const vesyncSwitchImpl_1 = require("./vesyncSwitchImpl");
|
|
11
11
|
const vesyncBulbImpl_1 = require("./vesyncBulbImpl");
|
|
12
|
+
const logger_1 = require("./logger");
|
|
12
13
|
const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
|
|
13
14
|
/**
|
|
14
15
|
* Create device instance based on type
|
|
@@ -29,7 +30,7 @@ function objectFactory(details, manager) {
|
|
|
29
30
|
if (deviceType in modules) {
|
|
30
31
|
DeviceClass = modules[deviceType];
|
|
31
32
|
category = cat;
|
|
32
|
-
|
|
33
|
+
logger_1.logger.debug(`Found exact match for ${deviceType} in ${cat} modules`);
|
|
33
34
|
break;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -64,14 +65,14 @@ function objectFactory(details, manager) {
|
|
|
64
65
|
for (const [prefix, cat] of Object.entries(prefixMap)) {
|
|
65
66
|
if (deviceType.startsWith(prefix)) {
|
|
66
67
|
category = cat;
|
|
67
|
-
|
|
68
|
+
logger_1.logger.debug(`Device type ${deviceType} matched prefix ${prefix} -> category ${cat}`);
|
|
68
69
|
// Try to find a base class in this category's modules
|
|
69
70
|
const modules = allModules[cat];
|
|
70
71
|
for (const [moduleType, ModuleClass] of Object.entries(modules)) {
|
|
71
72
|
const baseType = moduleType.split('-')[0]; // e.g., ESL100 from ESL100-USA
|
|
72
73
|
if (deviceType.startsWith(baseType)) {
|
|
73
74
|
DeviceClass = ModuleClass;
|
|
74
|
-
|
|
75
|
+
logger_1.logger.debug(`Found base type match: ${deviceType} -> ${baseType}`);
|
|
75
76
|
break;
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -87,12 +88,12 @@ function objectFactory(details, manager) {
|
|
|
87
88
|
return [category, device];
|
|
88
89
|
}
|
|
89
90
|
catch (error) {
|
|
90
|
-
|
|
91
|
+
logger_1.logger.error(`Error creating device instance for ${deviceType}:`, error);
|
|
91
92
|
return [category, null];
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
|
-
|
|
96
|
+
logger_1.logger.warn(`No device class found for type: ${deviceType}`);
|
|
96
97
|
return [category, null];
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -133,7 +134,7 @@ class VeSync {
|
|
|
133
134
|
const regTest = /[^a-zA-Z/_]/;
|
|
134
135
|
if (regTest.test(timeZone)) {
|
|
135
136
|
this.timeZone = helpers_1.DEFAULT_TZ;
|
|
136
|
-
|
|
137
|
+
logger_1.logger.debug('Invalid characters in time zone - ', timeZone);
|
|
137
138
|
}
|
|
138
139
|
else {
|
|
139
140
|
this.timeZone = timeZone;
|
|
@@ -141,7 +142,7 @@ class VeSync {
|
|
|
141
142
|
}
|
|
142
143
|
else {
|
|
143
144
|
this.timeZone = helpers_1.DEFAULT_TZ;
|
|
144
|
-
|
|
145
|
+
logger_1.logger.debug('Time zone is not a string');
|
|
145
146
|
}
|
|
146
147
|
if (debug) {
|
|
147
148
|
this.debug = true;
|
|
@@ -190,7 +191,7 @@ class VeSync {
|
|
|
190
191
|
return true;
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
|
-
|
|
194
|
+
logger_1.logger.debug(`Device removed - ${device.deviceName} - ${device.deviceType}`);
|
|
194
195
|
return false;
|
|
195
196
|
}
|
|
196
197
|
return true;
|
|
@@ -219,7 +220,7 @@ class VeSync {
|
|
|
219
220
|
this._devList[key] = deviceList.filter(device => VeSync.removeDevTest(device, devices));
|
|
220
221
|
const after = this._devList[key].length;
|
|
221
222
|
if (before !== after) {
|
|
222
|
-
|
|
223
|
+
logger_1.logger.debug(`${before - after} ${key} removed`);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
return true;
|
|
@@ -239,7 +240,7 @@ class VeSync {
|
|
|
239
240
|
}
|
|
240
241
|
else {
|
|
241
242
|
devRem.push(index);
|
|
242
|
-
|
|
243
|
+
logger_1.logger.warn(`Device with no ID - ${dev.deviceName || ''}`);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
});
|
|
@@ -260,12 +261,12 @@ class VeSync {
|
|
|
260
261
|
numDevices += deviceList.length;
|
|
261
262
|
}
|
|
262
263
|
if (!devices || devices.length === 0) {
|
|
263
|
-
|
|
264
|
+
logger_1.logger.warn('No devices found in api return');
|
|
264
265
|
return false;
|
|
265
266
|
}
|
|
266
267
|
// Initialize new device list or remove old devices
|
|
267
268
|
if (numDevices === 0) {
|
|
268
|
-
|
|
269
|
+
logger_1.logger.debug('New device list initialized');
|
|
269
270
|
}
|
|
270
271
|
else {
|
|
271
272
|
this.removeOldDevices(devices);
|
|
@@ -278,7 +279,7 @@ class VeSync {
|
|
|
278
279
|
for (const dev of newDevices) {
|
|
279
280
|
// Verify required device properties
|
|
280
281
|
if (!requiredKeys.every(key => key in dev)) {
|
|
281
|
-
|
|
282
|
+
logger_1.logger.debug(`Error adding device - missing required properties: ${dev.deviceName || 'Unknown'}`);
|
|
282
283
|
continue;
|
|
283
284
|
}
|
|
284
285
|
const devType = dev.deviceType;
|
|
@@ -288,14 +289,14 @@ class VeSync {
|
|
|
288
289
|
// Add device to appropriate category if valid
|
|
289
290
|
if (deviceObj && category in this._devList) {
|
|
290
291
|
this._devList[category].push(deviceObj);
|
|
291
|
-
|
|
292
|
+
logger_1.logger.debug(`Added ${devType} device to ${category} category`);
|
|
292
293
|
}
|
|
293
294
|
else if (category === 'unknown') {
|
|
294
|
-
|
|
295
|
+
logger_1.logger.debug(`Unknown device type: ${devType}`);
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
298
|
catch (err) {
|
|
298
|
-
|
|
299
|
+
logger_1.logger.error(`Error creating device ${devType}:`, err);
|
|
299
300
|
continue;
|
|
300
301
|
}
|
|
301
302
|
}
|
|
@@ -307,7 +308,7 @@ class VeSync {
|
|
|
307
308
|
async getDevices() {
|
|
308
309
|
var _a, _b;
|
|
309
310
|
if (!this.enabled) {
|
|
310
|
-
|
|
311
|
+
logger_1.logger.error('Not logged in to VeSync');
|
|
311
312
|
return false;
|
|
312
313
|
}
|
|
313
314
|
this._inProcess = true;
|
|
@@ -320,40 +321,40 @@ class VeSync {
|
|
|
320
321
|
// Update the main devices array with all devices
|
|
321
322
|
this.devices = Object.values(this._devList).flat();
|
|
322
323
|
// Log device discovery results
|
|
323
|
-
|
|
324
|
-
|
|
324
|
+
logger_1.logger.debug('\n=== Device Discovery Summary ===');
|
|
325
|
+
logger_1.logger.debug(`Total devices processed: ${deviceList.length}`);
|
|
325
326
|
// Log device types found
|
|
326
327
|
const deviceTypes = deviceList.map((d) => d.deviceType);
|
|
327
|
-
|
|
328
|
+
logger_1.logger.debug('\nDevice types found:', deviceTypes);
|
|
328
329
|
// Log devices by category with details
|
|
329
|
-
|
|
330
|
-
|
|
330
|
+
logger_1.logger.debug('\nDevices by Category:');
|
|
331
|
+
logger_1.logger.debug('---------------------');
|
|
331
332
|
for (const [category, devices] of Object.entries(this._devList)) {
|
|
332
333
|
if (devices.length > 0) {
|
|
333
|
-
|
|
334
|
+
logger_1.logger.debug(`\n${category.toUpperCase()} (${devices.length} devices):`);
|
|
334
335
|
devices.forEach((d) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
logger_1.logger.debug(` • ${d.deviceName}`);
|
|
337
|
+
logger_1.logger.debug(` Type: ${d.deviceType}`);
|
|
338
|
+
logger_1.logger.debug(` Status: ${d.deviceStatus}`);
|
|
339
|
+
logger_1.logger.debug(` ID: ${d.cid}`);
|
|
339
340
|
});
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
// Log summary statistics
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
logger_1.logger.debug('\nSummary Statistics:');
|
|
345
|
+
logger_1.logger.debug('-------------------');
|
|
346
|
+
logger_1.logger.debug(`Total Devices: ${((_b = this.devices) === null || _b === void 0 ? void 0 : _b.length) || 0}`);
|
|
346
347
|
for (const [category, devices] of Object.entries(this._devList)) {
|
|
347
|
-
|
|
348
|
+
logger_1.logger.debug(`${category}: ${devices.length} devices`);
|
|
348
349
|
}
|
|
349
|
-
|
|
350
|
+
logger_1.logger.debug('\n=== End of Device Discovery ===\n');
|
|
350
351
|
}
|
|
351
352
|
else {
|
|
352
|
-
|
|
353
|
+
logger_1.logger.error('No devices found in response');
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
catch (error) {
|
|
356
|
-
|
|
357
|
+
logger_1.logger.error('Unable to get device list:', error);
|
|
357
358
|
}
|
|
358
359
|
this._inProcess = false;
|
|
359
360
|
return procReturn;
|
|
@@ -364,13 +365,13 @@ class VeSync {
|
|
|
364
365
|
async login() {
|
|
365
366
|
var _a;
|
|
366
367
|
const body = helpers_1.Helpers.reqBody(this, 'login');
|
|
367
|
-
|
|
368
|
+
logger_1.logger.debug('Login request:', {
|
|
368
369
|
url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
|
|
369
370
|
body
|
|
370
371
|
});
|
|
371
372
|
try {
|
|
372
373
|
const [response, status] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body);
|
|
373
|
-
|
|
374
|
+
logger_1.logger.debug('Login response:', { status, response });
|
|
374
375
|
if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.token) {
|
|
375
376
|
this.token = response.result.token;
|
|
376
377
|
this.accountId = response.result.accountID;
|
|
@@ -378,11 +379,11 @@ class VeSync {
|
|
|
378
379
|
this.enabled = true;
|
|
379
380
|
return true;
|
|
380
381
|
}
|
|
381
|
-
|
|
382
|
+
logger_1.logger.error('Unable to login with supplied credentials');
|
|
382
383
|
return false;
|
|
383
384
|
}
|
|
384
385
|
catch (error) {
|
|
385
|
-
|
|
386
|
+
logger_1.logger.error('Login error:', error);
|
|
386
387
|
return false;
|
|
387
388
|
}
|
|
388
389
|
}
|
|
@@ -399,18 +400,18 @@ class VeSync {
|
|
|
399
400
|
async update() {
|
|
400
401
|
if (this.deviceTimeCheck()) {
|
|
401
402
|
if (!this.enabled) {
|
|
402
|
-
|
|
403
|
+
logger_1.logger.error('Not logged in to VeSync');
|
|
403
404
|
return;
|
|
404
405
|
}
|
|
405
406
|
await this.getDevices();
|
|
406
|
-
|
|
407
|
+
logger_1.logger.debug('Start updating the device details one by one');
|
|
407
408
|
for (const deviceList of Object.values(this._devList)) {
|
|
408
409
|
for (const device of deviceList) {
|
|
409
410
|
try {
|
|
410
411
|
await device.getDetails();
|
|
411
412
|
}
|
|
412
413
|
catch (error) {
|
|
413
|
-
|
|
414
|
+
logger_1.logger.error(`Error updating ${device.deviceName}:`, error);
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
417
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VeSyncBaseDevice = void 0;
|
|
7
|
+
const logger_1 = require("./logger");
|
|
7
8
|
class VeSyncBaseDevice {
|
|
8
9
|
constructor(details, manager) {
|
|
9
10
|
this.config = {};
|
|
@@ -23,11 +24,11 @@ class VeSyncBaseDevice {
|
|
|
23
24
|
* Return formatted device info to stdout
|
|
24
25
|
*/
|
|
25
26
|
display() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
logger_1.logger.info(`Device Name: ${this.deviceName}`);
|
|
28
|
+
logger_1.logger.info(`Status: ${this.deviceStatus}`);
|
|
29
|
+
logger_1.logger.info(`Device Type: ${this.deviceType}`);
|
|
30
|
+
logger_1.logger.info(`Connection: ${this.connectionStatus}`);
|
|
31
|
+
logger_1.logger.info(`Version: ${this.config.current_firmware_version || 'Unknown'}`);
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Return JSON details for device
|
|
@@ -70,12 +71,12 @@ class VeSyncBaseDevice {
|
|
|
70
71
|
logError(method, error) {
|
|
71
72
|
var _a;
|
|
72
73
|
const errorMsg = (error === null || error === void 0 ? void 0 : error.message) || error;
|
|
73
|
-
|
|
74
|
+
logger_1.logger.error(`[${this.deviceName}] ${method}: ${errorMsg}`);
|
|
74
75
|
// Log additional error details if available
|
|
75
76
|
if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
76
77
|
const responseData = error.response.data;
|
|
77
78
|
const msg = responseData.msg || responseData.message || JSON.stringify(responseData);
|
|
78
|
-
|
|
79
|
+
logger_1.logger.error(`Response: ${msg}`);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
/**
|
package/dist/lib/vesyncBulb.d.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
5
|
import { VeSync } from './vesync';
|
|
6
|
+
interface BulbConfig {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
module: string;
|
|
9
|
+
features: string[];
|
|
10
|
+
colorModel: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const bulbConfig: BulbConfig;
|
|
6
14
|
/**
|
|
7
15
|
* VeSync Bulb Base Class
|
|
8
16
|
*/
|
|
@@ -77,3 +85,4 @@ export declare abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
77
85
|
*/
|
|
78
86
|
abstract setColorTemp(colorTemp: number): Promise<boolean>;
|
|
79
87
|
}
|
|
88
|
+
export {};
|
package/dist/lib/vesyncBulb.js
CHANGED
|
@@ -3,24 +3,29 @@
|
|
|
3
3
|
* VeSync Bulb Base Class
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.VeSyncBulb = void 0;
|
|
6
|
+
exports.VeSyncBulb = exports.bulbConfig = void 0;
|
|
7
7
|
const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
// Bulb configuration
|
|
11
|
+
exports.bulbConfig = {
|
|
11
12
|
'ESL100': {
|
|
13
|
+
module: 'VeSyncBulbESL100',
|
|
12
14
|
features: ['dimmable'],
|
|
13
15
|
colorModel: 'none'
|
|
14
16
|
},
|
|
15
17
|
'ESL100CW': {
|
|
18
|
+
module: 'VeSyncBulbESL100CW',
|
|
16
19
|
features: ['dimmable', 'color_temp'],
|
|
17
20
|
colorModel: 'none'
|
|
18
21
|
},
|
|
19
22
|
'XYD0001': {
|
|
23
|
+
module: 'VeSyncBulbXYD0001',
|
|
20
24
|
features: ['dimmable', 'color_temp', 'rgb_shift'],
|
|
21
25
|
colorModel: 'hsv'
|
|
22
26
|
},
|
|
23
27
|
'ESL100MC': {
|
|
28
|
+
module: 'VeSyncBulbESL100MC',
|
|
24
29
|
features: ['dimmable', 'rgb_shift'],
|
|
25
30
|
colorModel: 'rgb'
|
|
26
31
|
}
|
|
@@ -38,7 +43,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
38
43
|
this.colorHue = 0;
|
|
39
44
|
this.colorSaturation = 0;
|
|
40
45
|
this.colorMode = '';
|
|
41
|
-
this.features = ((_a =
|
|
46
|
+
this.features = ((_a = exports.bulbConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
|
|
42
47
|
this.rgbValues = {
|
|
43
48
|
red: 0,
|
|
44
49
|
green: 0,
|
|
@@ -49,20 +54,35 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
49
54
|
* Get bulb details
|
|
50
55
|
*/
|
|
51
56
|
async getDetails() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
logger_1.logger.debug(`[${this.deviceName}] Getting bulb details`);
|
|
58
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
59
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
60
|
+
const body = isV2Device ? {
|
|
61
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
62
|
+
cid: this.cid,
|
|
63
|
+
configModule: this.configModule,
|
|
64
|
+
payload: {
|
|
65
|
+
data: {},
|
|
66
|
+
method: 'getLightStatusV2',
|
|
67
|
+
source: 'APP'
|
|
68
|
+
}
|
|
69
|
+
} : {
|
|
70
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
|
|
71
|
+
cid: this.cid,
|
|
72
|
+
configModule: this.configModule,
|
|
73
|
+
jsonCmd: {
|
|
74
|
+
getLightStatus: 'get'
|
|
75
|
+
}
|
|
56
76
|
};
|
|
57
|
-
const [response] = await helpers_1.Helpers.callApi(
|
|
77
|
+
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
58
78
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
59
|
-
this.deviceStatus = response.result.
|
|
79
|
+
this.deviceStatus = response.result.enabled ? 'on' : 'off';
|
|
60
80
|
this.brightness = response.result.brightness || this.brightness;
|
|
61
81
|
if (this.features.includes('color_temp')) {
|
|
62
82
|
this.colorTemp = response.result.colorTemp || this.colorTemp;
|
|
63
83
|
}
|
|
64
84
|
if (this.features.includes('rgb_shift')) {
|
|
65
|
-
if (
|
|
85
|
+
if (exports.bulbConfig[this.deviceType].colorModel === 'rgb') {
|
|
66
86
|
this.rgbValues = {
|
|
67
87
|
red: response.result.red || this.rgbValues.red,
|
|
68
88
|
green: response.result.green || this.rgbValues.green,
|
|
@@ -75,44 +95,94 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
75
95
|
this.colorValue = response.result.value || this.colorValue;
|
|
76
96
|
}
|
|
77
97
|
}
|
|
98
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
78
102
|
}
|
|
79
103
|
}
|
|
80
104
|
/**
|
|
81
105
|
* Update bulb status
|
|
82
106
|
*/
|
|
83
107
|
async update() {
|
|
108
|
+
logger_1.logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
84
109
|
await this.getDetails();
|
|
110
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully updated bulb information`);
|
|
85
111
|
}
|
|
86
112
|
/**
|
|
87
113
|
* Turn bulb on
|
|
88
114
|
*/
|
|
89
115
|
async turnOn() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning bulb on`);
|
|
117
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
118
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
119
|
+
const body = isV2Device ? {
|
|
120
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
121
|
+
cid: this.cid,
|
|
122
|
+
configModule: this.configModule,
|
|
123
|
+
payload: {
|
|
124
|
+
data: {
|
|
125
|
+
enabled: true,
|
|
126
|
+
id: 0
|
|
127
|
+
},
|
|
128
|
+
method: 'setSwitch',
|
|
129
|
+
source: 'APP'
|
|
130
|
+
}
|
|
131
|
+
} : {
|
|
132
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
|
|
133
|
+
cid: this.cid,
|
|
134
|
+
configModule: this.configModule,
|
|
135
|
+
jsonCmd: {
|
|
136
|
+
light: {
|
|
137
|
+
action: 'on'
|
|
138
|
+
}
|
|
139
|
+
}
|
|
94
140
|
};
|
|
95
|
-
const [response] = await helpers_1.Helpers.callApi(
|
|
141
|
+
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
96
142
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
97
143
|
this.deviceStatus = 'on';
|
|
144
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned bulb on`);
|
|
98
145
|
return true;
|
|
99
146
|
}
|
|
147
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb on: ${JSON.stringify(response)}`);
|
|
100
148
|
return false;
|
|
101
149
|
}
|
|
102
150
|
/**
|
|
103
151
|
* Turn bulb off
|
|
104
152
|
*/
|
|
105
153
|
async turnOff() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
logger_1.logger.debug(`[${this.deviceName}] Turning bulb off`);
|
|
155
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
156
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
157
|
+
const body = isV2Device ? {
|
|
158
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
159
|
+
cid: this.cid,
|
|
160
|
+
configModule: this.configModule,
|
|
161
|
+
payload: {
|
|
162
|
+
data: {
|
|
163
|
+
enabled: false,
|
|
164
|
+
id: 0
|
|
165
|
+
},
|
|
166
|
+
method: 'setSwitch',
|
|
167
|
+
source: 'APP'
|
|
168
|
+
}
|
|
169
|
+
} : {
|
|
170
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
|
|
171
|
+
cid: this.cid,
|
|
172
|
+
configModule: this.configModule,
|
|
173
|
+
jsonCmd: {
|
|
174
|
+
light: {
|
|
175
|
+
action: 'off'
|
|
176
|
+
}
|
|
177
|
+
}
|
|
110
178
|
};
|
|
111
|
-
const [response] = await helpers_1.Helpers.callApi(
|
|
179
|
+
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
112
180
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
113
181
|
this.deviceStatus = 'off';
|
|
182
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully turned bulb off`);
|
|
114
183
|
return true;
|
|
115
184
|
}
|
|
185
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb off: ${JSON.stringify(response)}`);
|
|
116
186
|
return false;
|
|
117
187
|
}
|
|
118
188
|
/**
|
|
@@ -120,19 +190,46 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
120
190
|
*/
|
|
121
191
|
async setBrightness(brightness) {
|
|
122
192
|
if (!this.features.includes('dimmable')) {
|
|
193
|
+
logger_1.logger.error(`[${this.deviceName}] Dimming not supported`);
|
|
123
194
|
return false;
|
|
124
195
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
196
|
+
logger_1.logger.debug(`[${this.deviceName}] Setting brightness to ${brightness}`);
|
|
197
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
198
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
199
|
+
const body = isV2Device ? {
|
|
200
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
|
|
201
|
+
cid: this.cid,
|
|
202
|
+
configModule: this.configModule,
|
|
203
|
+
payload: {
|
|
204
|
+
data: {
|
|
205
|
+
brightness: brightness,
|
|
206
|
+
colorMode: '',
|
|
207
|
+
colorTemp: '',
|
|
208
|
+
force: 0,
|
|
209
|
+
hue: '',
|
|
210
|
+
saturation: '',
|
|
211
|
+
value: ''
|
|
212
|
+
},
|
|
213
|
+
method: 'setLightStatusV2',
|
|
214
|
+
source: 'APP'
|
|
215
|
+
}
|
|
216
|
+
} : {
|
|
217
|
+
...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
|
|
218
|
+
cid: this.cid,
|
|
219
|
+
configModule: this.configModule,
|
|
220
|
+
jsonCmd: {
|
|
221
|
+
light: {
|
|
222
|
+
brightness: brightness
|
|
223
|
+
}
|
|
224
|
+
}
|
|
130
225
|
};
|
|
131
|
-
const [response] = await helpers_1.Helpers.callApi(
|
|
226
|
+
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
132
227
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
133
228
|
this.brightness = brightness;
|
|
229
|
+
logger_1.logger.debug(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
|
|
134
230
|
return true;
|
|
135
231
|
}
|
|
232
|
+
logger_1.logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
|
|
136
233
|
return false;
|
|
137
234
|
}
|
|
138
235
|
/**
|
|
@@ -190,7 +287,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
190
287
|
* Get RGB values
|
|
191
288
|
*/
|
|
192
289
|
getRGBValues() {
|
|
193
|
-
if (!this.features.includes('rgb_shift') ||
|
|
290
|
+
if (!this.features.includes('rgb_shift') || exports.bulbConfig[this.deviceType].colorModel !== 'rgb') {
|
|
194
291
|
return { red: 0, green: 0, blue: 0 };
|
|
195
292
|
}
|
|
196
293
|
return this.rgbValues;
|