tsvesync 1.0.17 → 1.0.18
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/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/package.json +1 -1
- package/src/lib/logger.ts +72 -17
- package/src/lib/vesync.ts +22 -3
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/package.json
CHANGED
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)) {
|