tsvesync 1.0.17 → 1.0.19
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 +2 -0
- package/dist/lib/logger.d.ts +31 -12
- package/dist/lib/logger.js +61 -14
- package/dist/lib/vesync.d.ts +9 -1
- package/dist/lib/vesync.js +16 -1
- package/dist/lib/vesyncBulb.js +5 -5
- package/dist/lib/vesyncBulbImpl.js +6 -6
- package/dist/lib/vesyncOutlet.js +8 -8
- package/dist/lib/vesyncOutletImpl.js +16 -16
- package/package.json +1 -1
- package/src/lib/helpers.ts +2 -0
- package/src/lib/logger.ts +72 -17
- package/src/lib/vesync.ts +22 -3
- package/src/lib/vesyncBulb.ts +5 -5
- package/src/lib/vesyncBulbImpl.ts +6 -6
- package/src/lib/vesyncOutlet.ts +8 -8
- package/src/lib/vesyncOutletImpl.ts +18 -18
package/dist/lib/helpers.js
CHANGED
|
@@ -45,6 +45,8 @@ class Helpers {
|
|
|
45
45
|
throw new Error('Manager accountId and token must be set');
|
|
46
46
|
}
|
|
47
47
|
return {
|
|
48
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
|
49
|
+
'User-Agent': exports.BYPASS_HEADER_UA,
|
|
48
50
|
'accept-language': 'en',
|
|
49
51
|
'accountId': manager.accountId,
|
|
50
52
|
'appVersion': exports.APP_VERSION,
|
package/dist/lib/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Logger
|
|
2
|
+
* Logger module for VeSync library
|
|
3
3
|
*/
|
|
4
4
|
export declare enum LogLevel {
|
|
5
5
|
DEBUG = 0,
|
|
@@ -8,16 +8,35 @@ export declare enum LogLevel {
|
|
|
8
8
|
ERROR = 3,
|
|
9
9
|
NONE = 4
|
|
10
10
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setLevel(level: LogLevel)
|
|
17
|
-
getLevel()
|
|
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;
|
|
11
|
+
export interface Logger {
|
|
12
|
+
debug: (message: string, ...args: any[]) => void;
|
|
13
|
+
info: (message: string, ...args: any[]) => void;
|
|
14
|
+
warn: (message: string, ...args: any[]) => void;
|
|
15
|
+
error: (message: string, ...args: any[]) => void;
|
|
16
|
+
setLevel?: (level: LogLevel) => void;
|
|
17
|
+
getLevel?: () => LogLevel | undefined;
|
|
22
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Set a custom logger implementation
|
|
21
|
+
* @param customLogger - Custom logger implementation
|
|
22
|
+
*/
|
|
23
|
+
export declare function setLogger(customLogger: Logger): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reset to default logger
|
|
26
|
+
*/
|
|
27
|
+
export declare function resetLogger(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current logger instance
|
|
30
|
+
*/
|
|
31
|
+
export declare function getLogger(): Logger;
|
|
32
|
+
/**
|
|
33
|
+
* Set the log level (only works with default logger)
|
|
34
|
+
* @param level - The log level to set
|
|
35
|
+
*/
|
|
36
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current log level (only works with default logger)
|
|
39
|
+
* @returns The current log level or undefined if using custom logger
|
|
40
|
+
*/
|
|
41
|
+
export declare function getLogLevel(): LogLevel | undefined;
|
|
23
42
|
export declare const logger: Logger;
|
package/dist/lib/logger.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Logger
|
|
3
|
+
* Logger module for VeSync library
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger = exports.
|
|
6
|
+
exports.logger = exports.LogLevel = void 0;
|
|
7
|
+
exports.setLogger = setLogger;
|
|
8
|
+
exports.resetLogger = resetLogger;
|
|
9
|
+
exports.getLogger = getLogger;
|
|
10
|
+
exports.setLogLevel = setLogLevel;
|
|
11
|
+
exports.getLogLevel = getLogLevel;
|
|
7
12
|
var LogLevel;
|
|
8
13
|
(function (LogLevel) {
|
|
9
14
|
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
@@ -12,16 +17,10 @@ var LogLevel;
|
|
|
12
17
|
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
13
18
|
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
14
19
|
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
15
|
-
class
|
|
20
|
+
class DefaultLogger {
|
|
16
21
|
constructor() {
|
|
17
22
|
this.currentLevel = LogLevel.INFO;
|
|
18
23
|
}
|
|
19
|
-
static getInstance() {
|
|
20
|
-
if (!Logger.instance) {
|
|
21
|
-
Logger.instance = new Logger();
|
|
22
|
-
}
|
|
23
|
-
return Logger.instance;
|
|
24
|
-
}
|
|
25
24
|
setLevel(level) {
|
|
26
25
|
this.currentLevel = level;
|
|
27
26
|
}
|
|
@@ -30,12 +29,12 @@ class Logger {
|
|
|
30
29
|
}
|
|
31
30
|
debug(message, ...args) {
|
|
32
31
|
if (this.currentLevel <= LogLevel.DEBUG) {
|
|
33
|
-
console.
|
|
32
|
+
console.debug(`[DEBUG] ${message}`, ...args);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
info(message, ...args) {
|
|
37
36
|
if (this.currentLevel <= LogLevel.INFO) {
|
|
38
|
-
console.
|
|
37
|
+
console.info(`[INFO] ${message}`, ...args);
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
warn(message, ...args) {
|
|
@@ -49,6 +48,54 @@ class Logger {
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
// Default logger implementation
|
|
52
|
+
const defaultLogger = new DefaultLogger();
|
|
53
|
+
// Current logger instance
|
|
54
|
+
let currentLogger = defaultLogger;
|
|
55
|
+
/**
|
|
56
|
+
* Set a custom logger implementation
|
|
57
|
+
* @param customLogger - Custom logger implementation
|
|
58
|
+
*/
|
|
59
|
+
function setLogger(customLogger) {
|
|
60
|
+
currentLogger = customLogger;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reset to default logger
|
|
64
|
+
*/
|
|
65
|
+
function resetLogger() {
|
|
66
|
+
currentLogger = defaultLogger;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the current logger instance
|
|
70
|
+
*/
|
|
71
|
+
function getLogger() {
|
|
72
|
+
return currentLogger;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set the log level (only works with default logger)
|
|
76
|
+
* @param level - The log level to set
|
|
77
|
+
*/
|
|
78
|
+
function setLogLevel(level) {
|
|
79
|
+
if (currentLogger === defaultLogger) {
|
|
80
|
+
currentLogger.setLevel(level);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the current log level (only works with default logger)
|
|
85
|
+
* @returns The current log level or undefined if using custom logger
|
|
86
|
+
*/
|
|
87
|
+
function getLogLevel() {
|
|
88
|
+
if (currentLogger === defaultLogger) {
|
|
89
|
+
return currentLogger.getLevel();
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
// Export the logger interface for use throughout the application
|
|
94
|
+
exports.logger = {
|
|
95
|
+
debug: (message, ...args) => currentLogger.debug(message, ...args),
|
|
96
|
+
info: (message, ...args) => currentLogger.info(message, ...args),
|
|
97
|
+
warn: (message, ...args) => currentLogger.warn(message, ...args),
|
|
98
|
+
error: (message, ...args) => currentLogger.error(message, ...args),
|
|
99
|
+
setLevel: (level) => setLogLevel(level),
|
|
100
|
+
getLevel: () => getLogLevel()
|
|
101
|
+
};
|
package/dist/lib/vesync.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* VeSync API Device Library
|
|
3
3
|
*/
|
|
4
4
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
|
+
import { Logger } from './logger';
|
|
5
6
|
/**
|
|
6
7
|
* VeSync Manager Class
|
|
7
8
|
*/
|
|
@@ -29,8 +30,15 @@ export declare class VeSync {
|
|
|
29
30
|
scales: VeSyncBaseDevice[];
|
|
30
31
|
/**
|
|
31
32
|
* Initialize VeSync Manager
|
|
33
|
+
* @param username - VeSync account username
|
|
34
|
+
* @param password - VeSync account password
|
|
35
|
+
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
36
|
+
* @param debug - Optional debug mode flag
|
|
37
|
+
* @param redact - Optional redact mode flag
|
|
38
|
+
* @param apiUrl - Optional API base URL override
|
|
39
|
+
* @param customLogger - Optional custom logger implementation
|
|
32
40
|
*/
|
|
33
|
-
constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean);
|
|
41
|
+
constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean, apiUrl?: string, customLogger?: Logger);
|
|
34
42
|
/**
|
|
35
43
|
* Get/Set debug mode
|
|
36
44
|
*/
|
package/dist/lib/vesync.js
CHANGED
|
@@ -103,8 +103,15 @@ function objectFactory(details, manager) {
|
|
|
103
103
|
class VeSync {
|
|
104
104
|
/**
|
|
105
105
|
* Initialize VeSync Manager
|
|
106
|
+
* @param username - VeSync account username
|
|
107
|
+
* @param password - VeSync account password
|
|
108
|
+
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
109
|
+
* @param debug - Optional debug mode flag
|
|
110
|
+
* @param redact - Optional redact mode flag
|
|
111
|
+
* @param apiUrl - Optional API base URL override
|
|
112
|
+
* @param customLogger - Optional custom logger implementation
|
|
106
113
|
*/
|
|
107
|
-
constructor(username, password, timeZone = helpers_1.DEFAULT_TZ, debug = false, redact = true) {
|
|
114
|
+
constructor(username, password, timeZone = helpers_1.DEFAULT_TZ, debug = false, redact = true, apiUrl, customLogger) {
|
|
108
115
|
this._debug = debug;
|
|
109
116
|
this._redact = redact;
|
|
110
117
|
this._energyUpdateInterval = DEFAULT_ENERGY_UPDATE_INTERVAL;
|
|
@@ -130,6 +137,14 @@ class VeSync {
|
|
|
130
137
|
switches: this.switches,
|
|
131
138
|
bulbs: this.bulbs
|
|
132
139
|
};
|
|
140
|
+
// Set custom API URL if provided
|
|
141
|
+
if (apiUrl) {
|
|
142
|
+
(0, helpers_1.setApiBaseUrl)(apiUrl);
|
|
143
|
+
}
|
|
144
|
+
// Set custom logger if provided
|
|
145
|
+
if (customLogger) {
|
|
146
|
+
(0, logger_1.setLogger)(customLogger);
|
|
147
|
+
}
|
|
133
148
|
if (typeof timeZone === 'string' && timeZone) {
|
|
134
149
|
const regTest = /[^a-zA-Z/_]/;
|
|
135
150
|
if (regTest.test(timeZone)) {
|
package/dist/lib/vesyncBulb.js
CHANGED
|
@@ -95,7 +95,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
95
95
|
this.colorValue = response.result.value || this.colorValue;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
logger_1.logger.
|
|
98
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
@@ -107,7 +107,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
107
107
|
async update() {
|
|
108
108
|
logger_1.logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
109
109
|
await this.getDetails();
|
|
110
|
-
logger_1.logger.
|
|
110
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully updated bulb information`);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* Turn bulb on
|
|
@@ -141,7 +141,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
141
141
|
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
142
142
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
143
143
|
this.deviceStatus = 'on';
|
|
144
|
-
logger_1.logger.
|
|
144
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned bulb on`);
|
|
145
145
|
return true;
|
|
146
146
|
}
|
|
147
147
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb on: ${JSON.stringify(response)}`);
|
|
@@ -179,7 +179,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
179
179
|
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
180
180
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
181
181
|
this.deviceStatus = 'off';
|
|
182
|
-
logger_1.logger.
|
|
182
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned bulb off`);
|
|
183
183
|
return true;
|
|
184
184
|
}
|
|
185
185
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb off: ${JSON.stringify(response)}`);
|
|
@@ -226,7 +226,7 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
226
226
|
const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
227
227
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
228
228
|
this.brightness = brightness;
|
|
229
|
-
logger_1.logger.
|
|
229
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
|
|
230
230
|
return true;
|
|
231
231
|
}
|
|
232
232
|
logger_1.logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
|
|
@@ -46,7 +46,7 @@ class VeSyncBulbESL100CW extends vesyncBulb_1.VeSyncBulb {
|
|
|
46
46
|
const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
47
47
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
48
48
|
this.colorTemp = colorTemp;
|
|
49
|
-
logger_1.logger.
|
|
49
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
logger_1.logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
@@ -88,7 +88,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
88
88
|
const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
89
89
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
90
90
|
this.colorTemp = colorTemp;
|
|
91
|
-
logger_1.logger.
|
|
91
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
94
94
|
logger_1.logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
@@ -123,7 +123,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
123
123
|
this.colorHue = hue;
|
|
124
124
|
this.colorSaturation = saturation;
|
|
125
125
|
this.colorValue = value;
|
|
126
|
-
logger_1.logger.
|
|
126
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully set HSV color`);
|
|
127
127
|
return true;
|
|
128
128
|
}
|
|
129
129
|
logger_1.logger.error(`[${this.deviceName}] Failed to set HSV color: ${JSON.stringify(response)}`);
|
|
@@ -152,7 +152,7 @@ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
|
|
|
152
152
|
const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
153
153
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
154
154
|
this.colorMode = 'white';
|
|
155
|
-
logger_1.logger.
|
|
155
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
156
156
|
return true;
|
|
157
157
|
}
|
|
158
158
|
logger_1.logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
|
@@ -192,7 +192,7 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
|
|
|
192
192
|
const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
193
193
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
194
194
|
this.rgbValues = { red, green, blue };
|
|
195
|
-
logger_1.logger.
|
|
195
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully set RGB color`);
|
|
196
196
|
return true;
|
|
197
197
|
}
|
|
198
198
|
logger_1.logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
|
|
@@ -213,7 +213,7 @@ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
|
|
|
213
213
|
const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
214
214
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
215
215
|
this.colorMode = 'white';
|
|
216
|
-
logger_1.logger.
|
|
216
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
217
217
|
return true;
|
|
218
218
|
}
|
|
219
219
|
logger_1.logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
package/dist/lib/vesyncOutlet.js
CHANGED
|
@@ -84,7 +84,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
84
84
|
const subDevice = response.subDevices.find((dev) => dev.subDeviceName === this.deviceName);
|
|
85
85
|
if (subDevice) {
|
|
86
86
|
this.deviceStatus = subDevice.subDeviceStatus;
|
|
87
|
-
logger_1.logger.
|
|
87
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved subdevice status: ${this.deviceStatus}`);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -102,7 +102,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
102
102
|
logger_1.logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
logger_1.logger.
|
|
105
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
@@ -142,7 +142,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
142
142
|
// Handle different response formats
|
|
143
143
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && response.result) {
|
|
144
144
|
this.energy = response.result;
|
|
145
|
-
logger_1.logger.
|
|
145
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully updated energy data`);
|
|
146
146
|
}
|
|
147
147
|
else if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
148
148
|
// Some devices return data directly in response
|
|
@@ -155,7 +155,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
155
155
|
energyMonth: response.energy || '0',
|
|
156
156
|
energyYear: response.energy || '0'
|
|
157
157
|
};
|
|
158
|
-
logger_1.logger.
|
|
158
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully updated energy data`);
|
|
159
159
|
}
|
|
160
160
|
else {
|
|
161
161
|
// For error responses, set defaults but don't log as error
|
|
@@ -236,7 +236,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
236
236
|
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/week` : `/${this.getApiPrefix()}/energyweek`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
237
237
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
238
238
|
this.energy.week = response.result || response.energyWeek || '0';
|
|
239
|
-
logger_1.logger.
|
|
239
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved weekly energy data`);
|
|
240
240
|
}
|
|
241
241
|
else {
|
|
242
242
|
this.energy.week = '0';
|
|
@@ -260,7 +260,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
260
260
|
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/month` : `/${this.getApiPrefix()}/energymonth`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
261
261
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
262
262
|
this.energy.month = response.result || response.energyMonth || '0';
|
|
263
|
-
logger_1.logger.
|
|
263
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved monthly energy data`);
|
|
264
264
|
}
|
|
265
265
|
else {
|
|
266
266
|
this.energy.month = '0';
|
|
@@ -284,7 +284,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
284
284
|
const [response] = await helpers_1.Helpers.callApi(isLegacyDevice ? `/${this.getApiPrefix()}/energy/year` : `/${this.getApiPrefix()}/energyyear`, isLegacyDevice ? 'get' : 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
285
285
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
286
286
|
this.energy.year = response.result || response.energyYear || '0';
|
|
287
|
-
logger_1.logger.
|
|
287
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully retrieved yearly energy data`);
|
|
288
288
|
}
|
|
289
289
|
else {
|
|
290
290
|
this.energy.year = '0';
|
|
@@ -300,7 +300,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
|
300
300
|
if (this.features.includes('energy')) {
|
|
301
301
|
await this.updateEnergy();
|
|
302
302
|
}
|
|
303
|
-
logger_1.logger.
|
|
303
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully updated outlet information`);
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
306
|
* Check if outlet has nightlight feature
|
|
@@ -19,11 +19,11 @@ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
19
19
|
*/
|
|
20
20
|
async turnOn() {
|
|
21
21
|
logger_1.logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
22
|
-
const url = `/v1/wifi-switch-1.3
|
|
23
|
-
const [response] = await helpers_1.Helpers.callApi(url, 'put',
|
|
24
|
-
if (
|
|
22
|
+
const url = `/v1/wifi-switch-1.3/${this.cid}/status/on`;
|
|
23
|
+
const [response, statusCode] = await helpers_1.Helpers.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
|
|
24
|
+
if (statusCode === 200) {
|
|
25
25
|
this.deviceStatus = 'on';
|
|
26
|
-
logger_1.logger.
|
|
26
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
29
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -34,11 +34,11 @@ class VeSyncOutlet7A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
34
34
|
*/
|
|
35
35
|
async turnOff() {
|
|
36
36
|
logger_1.logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
37
|
-
const url = `/v1/wifi-switch-1.3
|
|
38
|
-
const [response] = await helpers_1.Helpers.callApi(url, 'put',
|
|
39
|
-
if (
|
|
37
|
+
const url = `/v1/wifi-switch-1.3/${this.cid}/status/off`;
|
|
38
|
+
const [response, statusCode] = await helpers_1.Helpers.callApi(url, 'put', {}, helpers_1.Helpers.reqHeaders(this.manager));
|
|
39
|
+
if (statusCode === 200) {
|
|
40
40
|
this.deviceStatus = 'off';
|
|
41
|
-
logger_1.logger.
|
|
41
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -66,7 +66,7 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
66
66
|
const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
67
67
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
68
68
|
this.deviceStatus = 'on';
|
|
69
|
-
logger_1.logger.
|
|
69
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
72
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -85,7 +85,7 @@ class VeSyncOutlet10A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
85
85
|
const [response] = await helpers_1.Helpers.callApi('/10a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
86
86
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
87
87
|
this.deviceStatus = 'off';
|
|
88
|
-
logger_1.logger.
|
|
88
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -113,7 +113,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
113
113
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
114
114
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
115
115
|
this.deviceStatus = 'on';
|
|
116
|
-
logger_1.logger.
|
|
116
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
117
117
|
return true;
|
|
118
118
|
}
|
|
119
119
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -132,7 +132,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
132
132
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
133
133
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
134
134
|
this.deviceStatus = 'off';
|
|
135
|
-
logger_1.logger.
|
|
135
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
136
136
|
return true;
|
|
137
137
|
}
|
|
138
138
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -155,7 +155,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
155
155
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
156
156
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
157
157
|
this.details.nightLightStatus = 'on';
|
|
158
|
-
logger_1.logger.
|
|
158
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned nightlight on`);
|
|
159
159
|
return true;
|
|
160
160
|
}
|
|
161
161
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight on: ${JSON.stringify(response)}`);
|
|
@@ -178,7 +178,7 @@ class VeSyncOutlet15A extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
178
178
|
const [response] = await helpers_1.Helpers.callApi('/15a/v1/device/nightlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
179
179
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
180
180
|
this.details.nightLightStatus = 'off';
|
|
181
|
-
logger_1.logger.
|
|
181
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned nightlight off`);
|
|
182
182
|
return true;
|
|
183
183
|
}
|
|
184
184
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn nightlight off: ${JSON.stringify(response)}`);
|
|
@@ -207,7 +207,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
207
207
|
const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
208
208
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
209
209
|
this.deviceStatus = 'on';
|
|
210
|
-
logger_1.logger.
|
|
210
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
211
211
|
return true;
|
|
212
212
|
}
|
|
213
213
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -227,7 +227,7 @@ class VeSyncOutdoorPlug extends vesyncOutlet_1.VeSyncOutlet {
|
|
|
227
227
|
const [response] = await helpers_1.Helpers.callApi('/outdoorsocket15a/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
228
228
|
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
229
229
|
this.deviceStatus = 'off';
|
|
230
|
-
logger_1.logger.
|
|
230
|
+
logger_1.logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
231
231
|
return true;
|
|
232
232
|
}
|
|
233
233
|
logger_1.logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
package/package.json
CHANGED
package/src/lib/helpers.ts
CHANGED
|
@@ -70,6 +70,8 @@ export class Helpers {
|
|
|
70
70
|
throw new Error('Manager accountId and token must be set');
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
|
74
|
+
'User-Agent': BYPASS_HEADER_UA,
|
|
73
75
|
'accept-language': 'en',
|
|
74
76
|
'accountId': manager.accountId,
|
|
75
77
|
'appVersion': APP_VERSION,
|
package/src/lib/logger.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Logger
|
|
2
|
+
* Logger module for VeSync library
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export enum LogLevel {
|
|
@@ -10,36 +10,35 @@ export enum LogLevel {
|
|
|
10
10
|
NONE = 4
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
export interface Logger {
|
|
14
|
+
debug: (message: string, ...args: any[]) => void;
|
|
15
|
+
info: (message: string, ...args: any[]) => void;
|
|
16
|
+
warn: (message: string, ...args: any[]) => void;
|
|
17
|
+
error: (message: string, ...args: any[]) => void;
|
|
18
|
+
setLevel?: (level: LogLevel) => void;
|
|
19
|
+
getLevel?: () => LogLevel | undefined;
|
|
20
|
+
}
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Logger.instance = new Logger();
|
|
22
|
-
}
|
|
23
|
-
return Logger.instance;
|
|
24
|
-
}
|
|
22
|
+
class DefaultLogger implements Logger {
|
|
23
|
+
private currentLevel: LogLevel = LogLevel.INFO;
|
|
25
24
|
|
|
26
25
|
setLevel(level: LogLevel): void {
|
|
27
26
|
this.currentLevel = level;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
getLevel(): LogLevel {
|
|
29
|
+
getLevel(): LogLevel | undefined {
|
|
31
30
|
return this.currentLevel;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
debug(message: string, ...args: any[]): void {
|
|
35
34
|
if (this.currentLevel <= LogLevel.DEBUG) {
|
|
36
|
-
console.
|
|
35
|
+
console.debug(`[DEBUG] ${message}`, ...args);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
info(message: string, ...args: any[]): void {
|
|
41
40
|
if (this.currentLevel <= LogLevel.INFO) {
|
|
42
|
-
console.
|
|
41
|
+
console.info(`[INFO] ${message}`, ...args);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
|
|
@@ -56,5 +55,61 @@ export class Logger {
|
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
//
|
|
60
|
-
|
|
58
|
+
// Default logger implementation
|
|
59
|
+
const defaultLogger: Logger = new DefaultLogger();
|
|
60
|
+
|
|
61
|
+
// Current logger instance
|
|
62
|
+
let currentLogger: Logger = defaultLogger;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Set a custom logger implementation
|
|
66
|
+
* @param customLogger - Custom logger implementation
|
|
67
|
+
*/
|
|
68
|
+
export function setLogger(customLogger: Logger): void {
|
|
69
|
+
currentLogger = customLogger;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Reset to default logger
|
|
74
|
+
*/
|
|
75
|
+
export function resetLogger(): void {
|
|
76
|
+
currentLogger = defaultLogger;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the current logger instance
|
|
81
|
+
*/
|
|
82
|
+
export function getLogger(): Logger {
|
|
83
|
+
return currentLogger;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Set the log level (only works with default logger)
|
|
88
|
+
* @param level - The log level to set
|
|
89
|
+
*/
|
|
90
|
+
export function setLogLevel(level: LogLevel): void {
|
|
91
|
+
if (currentLogger === defaultLogger) {
|
|
92
|
+
(currentLogger as DefaultLogger).setLevel(level);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get the current log level (only works with default logger)
|
|
98
|
+
* @returns The current log level or undefined if using custom logger
|
|
99
|
+
*/
|
|
100
|
+
export function getLogLevel(): LogLevel | undefined {
|
|
101
|
+
if (currentLogger === defaultLogger) {
|
|
102
|
+
return (currentLogger as DefaultLogger).getLevel();
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Export the logger interface for use throughout the application
|
|
108
|
+
export const logger: Logger = {
|
|
109
|
+
debug: (message: string, ...args: any[]) => currentLogger.debug(message, ...args),
|
|
110
|
+
info: (message: string, ...args: any[]) => currentLogger.info(message, ...args),
|
|
111
|
+
warn: (message: string, ...args: any[]) => currentLogger.warn(message, ...args),
|
|
112
|
+
error: (message: string, ...args: any[]) => currentLogger.error(message, ...args),
|
|
113
|
+
setLevel: (level: LogLevel) => setLogLevel(level),
|
|
114
|
+
getLevel: () => getLogLevel()
|
|
115
|
+
};
|
package/src/lib/vesync.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* VeSync API Device Library
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { Helpers, API_RATE_LIMIT, DEFAULT_TZ } from './helpers';
|
|
5
|
+
import { Helpers, API_RATE_LIMIT, DEFAULT_TZ, setApiBaseUrl } from './helpers';
|
|
6
6
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
7
7
|
import { fanModules } from './vesyncFanImpl';
|
|
8
8
|
import { outletModules } from './vesyncOutletImpl';
|
|
9
9
|
import { switchModules } from './vesyncSwitchImpl';
|
|
10
10
|
import { bulbModules } from './vesyncBulbImpl';
|
|
11
11
|
import { VeSyncBulb } from './vesyncBulb';
|
|
12
|
-
import { logger } from './logger';
|
|
12
|
+
import { logger, setLogger, Logger } from './logger';
|
|
13
13
|
|
|
14
14
|
const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
|
|
15
15
|
|
|
@@ -145,13 +145,22 @@ export class VeSync {
|
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
147
|
* Initialize VeSync Manager
|
|
148
|
+
* @param username - VeSync account username
|
|
149
|
+
* @param password - VeSync account password
|
|
150
|
+
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
151
|
+
* @param debug - Optional debug mode flag
|
|
152
|
+
* @param redact - Optional redact mode flag
|
|
153
|
+
* @param apiUrl - Optional API base URL override
|
|
154
|
+
* @param customLogger - Optional custom logger implementation
|
|
148
155
|
*/
|
|
149
156
|
constructor(
|
|
150
157
|
username: string,
|
|
151
158
|
password: string,
|
|
152
159
|
timeZone: string = DEFAULT_TZ,
|
|
153
160
|
debug = false,
|
|
154
|
-
redact = true
|
|
161
|
+
redact = true,
|
|
162
|
+
apiUrl?: string,
|
|
163
|
+
customLogger?: Logger
|
|
155
164
|
) {
|
|
156
165
|
this._debug = debug;
|
|
157
166
|
this._redact = redact;
|
|
@@ -182,6 +191,16 @@ export class VeSync {
|
|
|
182
191
|
bulbs: this.bulbs
|
|
183
192
|
};
|
|
184
193
|
|
|
194
|
+
// Set custom API URL if provided
|
|
195
|
+
if (apiUrl) {
|
|
196
|
+
setApiBaseUrl(apiUrl);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Set custom logger if provided
|
|
200
|
+
if (customLogger) {
|
|
201
|
+
setLogger(customLogger);
|
|
202
|
+
}
|
|
203
|
+
|
|
185
204
|
if (typeof timeZone === 'string' && timeZone) {
|
|
186
205
|
const regTest = /[^a-zA-Z/_]/;
|
|
187
206
|
if (regTest.test(timeZone)) {
|
package/src/lib/vesyncBulb.ts
CHANGED
|
@@ -120,7 +120,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
120
120
|
this.colorValue = response.result.value || this.colorValue;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
logger.
|
|
123
|
+
logger.info(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
124
124
|
} else {
|
|
125
125
|
logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
126
126
|
}
|
|
@@ -132,7 +132,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
132
132
|
async update(): Promise<void> {
|
|
133
133
|
logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
134
134
|
await this.getDetails();
|
|
135
|
-
logger.
|
|
135
|
+
logger.info(`[${this.deviceName}] Successfully updated bulb information`);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -175,7 +175,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
175
175
|
|
|
176
176
|
if (response?.code === 0) {
|
|
177
177
|
this.deviceStatus = 'on';
|
|
178
|
-
logger.
|
|
178
|
+
logger.info(`[${this.deviceName}] Successfully turned bulb on`);
|
|
179
179
|
return true;
|
|
180
180
|
}
|
|
181
181
|
logger.error(`[${this.deviceName}] Failed to turn bulb on: ${JSON.stringify(response)}`);
|
|
@@ -222,7 +222,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
222
222
|
|
|
223
223
|
if (response?.code === 0) {
|
|
224
224
|
this.deviceStatus = 'off';
|
|
225
|
-
logger.
|
|
225
|
+
logger.info(`[${this.deviceName}] Successfully turned bulb off`);
|
|
226
226
|
return true;
|
|
227
227
|
}
|
|
228
228
|
logger.error(`[${this.deviceName}] Failed to turn bulb off: ${JSON.stringify(response)}`);
|
|
@@ -279,7 +279,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
279
279
|
|
|
280
280
|
if (response?.code === 0) {
|
|
281
281
|
this.brightness = brightness;
|
|
282
|
-
logger.
|
|
282
|
+
logger.info(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
|
|
283
283
|
return true;
|
|
284
284
|
}
|
|
285
285
|
logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
|
|
@@ -56,7 +56,7 @@ export class VeSyncBulbESL100CW extends VeSyncBulb {
|
|
|
56
56
|
|
|
57
57
|
if (response?.code === 0) {
|
|
58
58
|
this.colorTemp = colorTemp;
|
|
59
|
-
logger.
|
|
59
|
+
logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
62
|
logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
@@ -107,7 +107,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
|
|
|
107
107
|
|
|
108
108
|
if (response?.code === 0) {
|
|
109
109
|
this.colorTemp = colorTemp;
|
|
110
|
-
logger.
|
|
110
|
+
logger.info(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
113
|
logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
@@ -151,7 +151,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
|
|
|
151
151
|
this.colorHue = hue;
|
|
152
152
|
this.colorSaturation = saturation;
|
|
153
153
|
this.colorValue = value;
|
|
154
|
-
logger.
|
|
154
|
+
logger.info(`[${this.deviceName}] Successfully set HSV color`);
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
157
|
logger.error(`[${this.deviceName}] Failed to set HSV color: ${JSON.stringify(response)}`);
|
|
@@ -188,7 +188,7 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
|
|
|
188
188
|
|
|
189
189
|
if (response?.code === 0) {
|
|
190
190
|
this.colorMode = 'white';
|
|
191
|
-
logger.
|
|
191
|
+
logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
192
192
|
return true;
|
|
193
193
|
}
|
|
194
194
|
logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
|
@@ -238,7 +238,7 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
|
|
|
238
238
|
|
|
239
239
|
if (response?.code === 0) {
|
|
240
240
|
this.rgbValues = { red, green, blue };
|
|
241
|
-
logger.
|
|
241
|
+
logger.info(`[${this.deviceName}] Successfully set RGB color`);
|
|
242
242
|
return true;
|
|
243
243
|
}
|
|
244
244
|
logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
|
|
@@ -267,7 +267,7 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
|
|
|
267
267
|
|
|
268
268
|
if (response?.code === 0) {
|
|
269
269
|
this.colorMode = 'white';
|
|
270
|
-
logger.
|
|
270
|
+
logger.info(`[${this.deviceName}] Successfully enabled white mode`);
|
|
271
271
|
return true;
|
|
272
272
|
}
|
|
273
273
|
logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
package/src/lib/vesyncOutlet.ts
CHANGED
|
@@ -106,7 +106,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
106
106
|
);
|
|
107
107
|
if (subDevice) {
|
|
108
108
|
this.deviceStatus = subDevice.subDeviceStatus;
|
|
109
|
-
logger.
|
|
109
|
+
logger.info(`[${this.deviceName}] Successfully retrieved subdevice status: ${this.deviceStatus}`);
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -122,7 +122,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
122
122
|
logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
-
logger.
|
|
125
|
+
logger.info(`[${this.deviceName}] Successfully retrieved outlet details`);
|
|
126
126
|
} else {
|
|
127
127
|
logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
|
|
128
128
|
}
|
|
@@ -168,7 +168,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
168
168
|
// Handle different response formats
|
|
169
169
|
if (response?.code === 0 && response.result) {
|
|
170
170
|
this.energy = response.result;
|
|
171
|
-
logger.
|
|
171
|
+
logger.info(`[${this.deviceName}] Successfully updated energy data`);
|
|
172
172
|
} else if (response?.code === 0) {
|
|
173
173
|
// Some devices return data directly in response
|
|
174
174
|
this.energy = {
|
|
@@ -180,7 +180,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
180
180
|
energyMonth: response.energy || '0',
|
|
181
181
|
energyYear: response.energy || '0'
|
|
182
182
|
};
|
|
183
|
-
logger.
|
|
183
|
+
logger.info(`[${this.deviceName}] Successfully updated energy data`);
|
|
184
184
|
} else {
|
|
185
185
|
// For error responses, set defaults but don't log as error
|
|
186
186
|
this.energy = {
|
|
@@ -271,7 +271,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
271
271
|
|
|
272
272
|
if (response?.code === 0) {
|
|
273
273
|
this.energy.week = response.result || response.energyWeek || '0';
|
|
274
|
-
logger.
|
|
274
|
+
logger.info(`[${this.deviceName}] Successfully retrieved weekly energy data`);
|
|
275
275
|
} else {
|
|
276
276
|
this.energy.week = '0';
|
|
277
277
|
logger.debug(`[${this.deviceName}] Failed to get weekly energy data: ${JSON.stringify(response)}`);
|
|
@@ -303,7 +303,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
303
303
|
|
|
304
304
|
if (response?.code === 0) {
|
|
305
305
|
this.energy.month = response.result || response.energyMonth || '0';
|
|
306
|
-
logger.
|
|
306
|
+
logger.info(`[${this.deviceName}] Successfully retrieved monthly energy data`);
|
|
307
307
|
} else {
|
|
308
308
|
this.energy.month = '0';
|
|
309
309
|
logger.debug(`[${this.deviceName}] Failed to get monthly energy data: ${JSON.stringify(response)}`);
|
|
@@ -335,7 +335,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
335
335
|
|
|
336
336
|
if (response?.code === 0) {
|
|
337
337
|
this.energy.year = response.result || response.energyYear || '0';
|
|
338
|
-
logger.
|
|
338
|
+
logger.info(`[${this.deviceName}] Successfully retrieved yearly energy data`);
|
|
339
339
|
} else {
|
|
340
340
|
this.energy.year = '0';
|
|
341
341
|
logger.debug(`[${this.deviceName}] Failed to get yearly energy data: ${JSON.stringify(response)}`);
|
|
@@ -351,7 +351,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
|
|
|
351
351
|
if (this.features.includes('energy')) {
|
|
352
352
|
await this.updateEnergy();
|
|
353
353
|
}
|
|
354
|
-
logger.
|
|
354
|
+
logger.info(`[${this.deviceName}] Successfully updated outlet information`);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
/**
|
|
@@ -20,17 +20,17 @@ export class VeSyncOutlet7A extends VeSyncOutlet {
|
|
|
20
20
|
*/
|
|
21
21
|
async turnOn(): Promise<boolean> {
|
|
22
22
|
logger.debug(`[${this.deviceName}] Turning outlet on`);
|
|
23
|
-
const url = `/v1/wifi-switch-1.3
|
|
24
|
-
const [response] = await Helpers.callApi(
|
|
23
|
+
const url = `/v1/wifi-switch-1.3/${this.cid}/status/on`;
|
|
24
|
+
const [response, statusCode] = await Helpers.callApi(
|
|
25
25
|
url,
|
|
26
26
|
'put',
|
|
27
|
-
|
|
27
|
+
{},
|
|
28
28
|
Helpers.reqHeaders(this.manager)
|
|
29
29
|
);
|
|
30
30
|
|
|
31
|
-
if (
|
|
31
|
+
if (statusCode === 200) {
|
|
32
32
|
this.deviceStatus = 'on';
|
|
33
|
-
logger.
|
|
33
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
36
|
logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -42,17 +42,17 @@ export class VeSyncOutlet7A extends VeSyncOutlet {
|
|
|
42
42
|
*/
|
|
43
43
|
async turnOff(): Promise<boolean> {
|
|
44
44
|
logger.debug(`[${this.deviceName}] Turning outlet off`);
|
|
45
|
-
const url = `/v1/wifi-switch-1.3
|
|
46
|
-
const [response] = await Helpers.callApi(
|
|
45
|
+
const url = `/v1/wifi-switch-1.3/${this.cid}/status/off`;
|
|
46
|
+
const [response, statusCode] = await Helpers.callApi(
|
|
47
47
|
url,
|
|
48
48
|
'put',
|
|
49
|
-
|
|
49
|
+
{},
|
|
50
50
|
Helpers.reqHeaders(this.manager)
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
if (
|
|
53
|
+
if (statusCode === 200) {
|
|
54
54
|
this.deviceStatus = 'off';
|
|
55
|
-
logger.
|
|
55
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -88,7 +88,7 @@ export class VeSyncOutlet10A extends VeSyncOutlet {
|
|
|
88
88
|
|
|
89
89
|
if (response?.code === 0) {
|
|
90
90
|
this.deviceStatus = 'on';
|
|
91
|
-
logger.
|
|
91
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
94
94
|
logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -115,7 +115,7 @@ export class VeSyncOutlet10A extends VeSyncOutlet {
|
|
|
115
115
|
|
|
116
116
|
if (response?.code === 0) {
|
|
117
117
|
this.deviceStatus = 'off';
|
|
118
|
-
logger.
|
|
118
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
121
|
logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -151,7 +151,7 @@ export class VeSyncOutlet15A extends VeSyncOutlet {
|
|
|
151
151
|
|
|
152
152
|
if (response?.code === 0) {
|
|
153
153
|
this.deviceStatus = 'on';
|
|
154
|
-
logger.
|
|
154
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
157
|
logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -178,7 +178,7 @@ export class VeSyncOutlet15A extends VeSyncOutlet {
|
|
|
178
178
|
|
|
179
179
|
if (response?.code === 0) {
|
|
180
180
|
this.deviceStatus = 'off';
|
|
181
|
-
logger.
|
|
181
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
182
182
|
return true;
|
|
183
183
|
}
|
|
184
184
|
logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|
|
@@ -210,7 +210,7 @@ export class VeSyncOutlet15A extends VeSyncOutlet {
|
|
|
210
210
|
|
|
211
211
|
if (response?.code === 0) {
|
|
212
212
|
this.details.nightLightStatus = 'on';
|
|
213
|
-
logger.
|
|
213
|
+
logger.info(`[${this.deviceName}] Successfully turned nightlight on`);
|
|
214
214
|
return true;
|
|
215
215
|
}
|
|
216
216
|
logger.error(`[${this.deviceName}] Failed to turn nightlight on: ${JSON.stringify(response)}`);
|
|
@@ -242,7 +242,7 @@ export class VeSyncOutlet15A extends VeSyncOutlet {
|
|
|
242
242
|
|
|
243
243
|
if (response?.code === 0) {
|
|
244
244
|
this.details.nightLightStatus = 'off';
|
|
245
|
-
logger.
|
|
245
|
+
logger.info(`[${this.deviceName}] Successfully turned nightlight off`);
|
|
246
246
|
return true;
|
|
247
247
|
}
|
|
248
248
|
logger.error(`[${this.deviceName}] Failed to turn nightlight off: ${JSON.stringify(response)}`);
|
|
@@ -279,7 +279,7 @@ export class VeSyncOutdoorPlug extends VeSyncOutlet {
|
|
|
279
279
|
|
|
280
280
|
if (response?.code === 0) {
|
|
281
281
|
this.deviceStatus = 'on';
|
|
282
|
-
logger.
|
|
282
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet on`);
|
|
283
283
|
return true;
|
|
284
284
|
}
|
|
285
285
|
logger.error(`[${this.deviceName}] Failed to turn outlet on: ${JSON.stringify(response)}`);
|
|
@@ -307,7 +307,7 @@ export class VeSyncOutdoorPlug extends VeSyncOutlet {
|
|
|
307
307
|
|
|
308
308
|
if (response?.code === 0) {
|
|
309
309
|
this.deviceStatus = 'off';
|
|
310
|
-
logger.
|
|
310
|
+
logger.info(`[${this.deviceName}] Successfully turned outlet off`);
|
|
311
311
|
return true;
|
|
312
312
|
}
|
|
313
313
|
logger.error(`[${this.deviceName}] Failed to turn outlet off: ${JSON.stringify(response)}`);
|