tsvesync 1.0.11 → 1.0.13
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/index.d.ts +7 -0
- package/dist/index.js +25 -0
- package/dist/lib/helpers.d.ts +52 -51
- package/dist/lib/helpers.js +135 -112
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.js +54 -0
- package/dist/lib/vesync.d.ts +57 -15
- package/dist/lib/vesync.js +341 -217
- package/dist/lib/vesyncBaseDevice.d.ts +25 -50
- package/dist/lib/vesyncBaseDevice.js +63 -90
- package/dist/lib/vesyncBulb.d.ts +88 -0
- package/dist/lib/vesyncBulb.js +295 -1
- package/dist/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/lib/vesyncBulbImpl.js +230 -0
- package/dist/lib/vesyncFan.d.ts +55 -67
- package/dist/lib/vesyncFan.js +366 -213
- package/dist/lib/vesyncFanImpl.d.ts +173 -0
- package/dist/lib/vesyncFanImpl.js +909 -0
- package/dist/lib/vesyncOutlet.d.ts +70 -0
- package/dist/lib/vesyncOutlet.js +213 -1
- package/dist/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/lib/vesyncOutletImpl.js +245 -0
- package/dist/lib/vesyncSwitch.d.ts +45 -0
- package/dist/lib/vesyncSwitch.js +77 -1
- package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/lib/vesyncSwitchImpl.js +344 -0
- package/package.json +1 -1
- package/src/index.ts +14 -0
- 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/vesyncSwitch.js
CHANGED
|
@@ -1,2 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* VeSync Switch Classes
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VeSyncSwitch = exports.switchConfig = void 0;
|
|
7
|
+
const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
// Switch configuration
|
|
10
|
+
exports.switchConfig = {
|
|
11
|
+
'ESWL01': {
|
|
12
|
+
module: 'VeSyncWallSwitch',
|
|
13
|
+
features: []
|
|
14
|
+
},
|
|
15
|
+
'ESWD16': {
|
|
16
|
+
module: 'VeSyncDimmerSwitch',
|
|
17
|
+
features: ['dimmable']
|
|
18
|
+
},
|
|
19
|
+
'ESWL03': {
|
|
20
|
+
module: 'VeSyncWallSwitch',
|
|
21
|
+
features: []
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Base class for VeSync Switches
|
|
26
|
+
*/
|
|
27
|
+
class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
|
|
28
|
+
constructor(details, manager) {
|
|
29
|
+
var _a;
|
|
30
|
+
super(details, manager);
|
|
31
|
+
this.details = {};
|
|
32
|
+
this.features = [];
|
|
33
|
+
this.details = details;
|
|
34
|
+
this.features = ((_a = exports.switchConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get active time of switch
|
|
38
|
+
*/
|
|
39
|
+
get activeTime() {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = this.details.active_time) !== null && _a !== void 0 ? _a : 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Return true if switch is dimmable
|
|
45
|
+
*/
|
|
46
|
+
isDimmable() {
|
|
47
|
+
return this.features.includes('dimmable');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Return formatted device info to stdout
|
|
51
|
+
*/
|
|
52
|
+
display() {
|
|
53
|
+
super.display();
|
|
54
|
+
const info = [
|
|
55
|
+
['Active Time:', this.activeTime]
|
|
56
|
+
];
|
|
57
|
+
for (const [key, value] of info) {
|
|
58
|
+
logger_1.logger.info(`${key.toString().padEnd(30, '.')} ${value}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Return JSON details for switch
|
|
63
|
+
*/
|
|
64
|
+
displayJSON() {
|
|
65
|
+
const baseInfo = JSON.parse(super.displayJSON());
|
|
66
|
+
return JSON.stringify({
|
|
67
|
+
...baseInfo,
|
|
68
|
+
'Active Time': this.activeTime
|
|
69
|
+
}, null, 4);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Update device details
|
|
73
|
+
*/
|
|
74
|
+
async update() {
|
|
75
|
+
await this.getDetails();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.VeSyncSwitch = VeSyncSwitch;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeSync Switch Implementations
|
|
3
|
+
*/
|
|
4
|
+
import { VeSyncSwitch } from './vesyncSwitch';
|
|
5
|
+
import { VeSync } from './vesync';
|
|
6
|
+
/**
|
|
7
|
+
* Basic Wall Switch Implementation (ESWL01, ESWL03)
|
|
8
|
+
*/
|
|
9
|
+
export declare class VeSyncWallSwitch extends VeSyncSwitch {
|
|
10
|
+
constructor(details: Record<string, any>, manager: VeSync);
|
|
11
|
+
/**
|
|
12
|
+
* Get wall switch details
|
|
13
|
+
*/
|
|
14
|
+
getDetails(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Get switch device configuration info
|
|
17
|
+
*/
|
|
18
|
+
getConfig(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Turn off wall switch
|
|
21
|
+
*/
|
|
22
|
+
turnOff(): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Turn on wall switch
|
|
25
|
+
*/
|
|
26
|
+
turnOn(): Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Dimmer Switch Implementation (ESWD16)
|
|
30
|
+
*/
|
|
31
|
+
export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
|
|
32
|
+
private _brightness;
|
|
33
|
+
private _rgbValue;
|
|
34
|
+
private _rgbStatus;
|
|
35
|
+
private _indicatorLight;
|
|
36
|
+
constructor(details: Record<string, any>, manager: VeSync);
|
|
37
|
+
/**
|
|
38
|
+
* Get dimmer switch details
|
|
39
|
+
*/
|
|
40
|
+
getDetails(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Get dimmer switch configuration info
|
|
43
|
+
*/
|
|
44
|
+
getConfig(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Turn off dimmer switch
|
|
47
|
+
*/
|
|
48
|
+
turnOff(): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Turn on dimmer switch
|
|
51
|
+
*/
|
|
52
|
+
turnOn(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Set brightness level
|
|
55
|
+
*/
|
|
56
|
+
setBrightness(brightness: number): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Set RGB indicator color
|
|
59
|
+
*/
|
|
60
|
+
rgbColorSet(red: number, green: number, blue: number): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Turn on RGB indicator
|
|
63
|
+
*/
|
|
64
|
+
rgbColorOff(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Turn RGB Color On
|
|
67
|
+
*/
|
|
68
|
+
rgbColorOn(): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Turn indicator light on
|
|
71
|
+
*/
|
|
72
|
+
indicatorLightOn(): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Turn indicator light off
|
|
75
|
+
*/
|
|
76
|
+
indicatorLightOff(): Promise<boolean>;
|
|
77
|
+
get brightness(): number;
|
|
78
|
+
get indicatorLightStatus(): string;
|
|
79
|
+
get rgbLightStatus(): string;
|
|
80
|
+
get rgbLightValue(): Record<string, number>;
|
|
81
|
+
}
|
|
82
|
+
export declare const switchModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncSwitch>;
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* VeSync Switch Implementations
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.switchModules = exports.VeSyncDimmerSwitch = exports.VeSyncWallSwitch = void 0;
|
|
7
|
+
const vesyncSwitch_1 = require("./vesyncSwitch");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
/**
|
|
11
|
+
* Basic Wall Switch Implementation (ESWL01, ESWL03)
|
|
12
|
+
*/
|
|
13
|
+
class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
14
|
+
constructor(details, manager) {
|
|
15
|
+
super(details, manager);
|
|
16
|
+
logger_1.logger.debug(`Initialized VeSyncWallSwitch device: ${this.deviceName}`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get wall switch details
|
|
20
|
+
*/
|
|
21
|
+
async getDetails() {
|
|
22
|
+
logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
23
|
+
const body = {
|
|
24
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
25
|
+
uuid: this.cid,
|
|
26
|
+
method: 'devicedetail'
|
|
27
|
+
};
|
|
28
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
29
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
30
|
+
const result = response.result;
|
|
31
|
+
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
32
|
+
this.details.active_time = result.activeTime || 0;
|
|
33
|
+
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
34
|
+
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get switch device configuration info
|
|
42
|
+
*/
|
|
43
|
+
async getConfig() {
|
|
44
|
+
logger_1.logger.debug(`Getting configuration for device: ${this.deviceName}`);
|
|
45
|
+
const body = {
|
|
46
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
47
|
+
method: 'configurations',
|
|
48
|
+
uuid: this.cid
|
|
49
|
+
};
|
|
50
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
51
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
52
|
+
this.config = helpers_1.Helpers.buildConfigDict(response);
|
|
53
|
+
logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logger_1.logger.error(`Failed to get configuration for device: ${this.deviceName}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Turn off wall switch
|
|
61
|
+
*/
|
|
62
|
+
async turnOff() {
|
|
63
|
+
logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
|
|
64
|
+
const body = {
|
|
65
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
66
|
+
status: 'off',
|
|
67
|
+
uuid: this.cid
|
|
68
|
+
};
|
|
69
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
70
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
71
|
+
this.deviceStatus = 'off';
|
|
72
|
+
logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Turn on wall switch
|
|
80
|
+
*/
|
|
81
|
+
async turnOn() {
|
|
82
|
+
logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
|
|
83
|
+
const body = {
|
|
84
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
85
|
+
status: 'on',
|
|
86
|
+
uuid: this.cid
|
|
87
|
+
};
|
|
88
|
+
const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
89
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
90
|
+
this.deviceStatus = 'on';
|
|
91
|
+
logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.VeSyncWallSwitch = VeSyncWallSwitch;
|
|
99
|
+
/**
|
|
100
|
+
* Dimmer Switch Implementation (ESWD16)
|
|
101
|
+
*/
|
|
102
|
+
class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
|
|
103
|
+
constructor(details, manager) {
|
|
104
|
+
super(details, manager);
|
|
105
|
+
this._brightness = 0;
|
|
106
|
+
this._rgbValue = { red: 0, blue: 0, green: 0 };
|
|
107
|
+
this._rgbStatus = 'unknown';
|
|
108
|
+
this._indicatorLight = 'unknown';
|
|
109
|
+
logger_1.logger.debug(`Initialized VeSyncDimmerSwitch device: ${this.deviceName}`);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get dimmer switch details
|
|
113
|
+
*/
|
|
114
|
+
async getDetails() {
|
|
115
|
+
logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
|
|
116
|
+
const body = {
|
|
117
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
118
|
+
uuid: this.cid,
|
|
119
|
+
method: 'devicedetail'
|
|
120
|
+
};
|
|
121
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
122
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
|
|
123
|
+
const result = response.result;
|
|
124
|
+
this.deviceStatus = result.deviceStatus || this.deviceStatus;
|
|
125
|
+
this.details.active_time = result.activeTime || 0;
|
|
126
|
+
this.connectionStatus = result.connectionStatus || this.connectionStatus;
|
|
127
|
+
this._brightness = result.brightness || this._brightness;
|
|
128
|
+
this._rgbStatus = result.rgbStatus || this._rgbStatus;
|
|
129
|
+
this._indicatorLight = result.indicatorlightStatus || this._indicatorLight;
|
|
130
|
+
if (result.rgbValue) {
|
|
131
|
+
this._rgbValue = {
|
|
132
|
+
red: result.rgbValue.red || 0,
|
|
133
|
+
green: result.rgbValue.green || 0,
|
|
134
|
+
blue: result.rgbValue.blue || 0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get dimmer switch configuration info
|
|
145
|
+
*/
|
|
146
|
+
async getConfig() {
|
|
147
|
+
logger_1.logger.debug(`Getting configuration for device: ${this.deviceName}`);
|
|
148
|
+
const body = {
|
|
149
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
|
|
150
|
+
method: 'configurations',
|
|
151
|
+
uuid: this.cid
|
|
152
|
+
};
|
|
153
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
154
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
155
|
+
this.config = helpers_1.Helpers.buildConfigDict(response);
|
|
156
|
+
logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
logger_1.logger.error(`Failed to get configuration for device: ${this.deviceName}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Turn off dimmer switch
|
|
164
|
+
*/
|
|
165
|
+
async turnOff() {
|
|
166
|
+
logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
|
|
167
|
+
const body = {
|
|
168
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
169
|
+
status: 'off',
|
|
170
|
+
uuid: this.cid
|
|
171
|
+
};
|
|
172
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
173
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
174
|
+
this.deviceStatus = 'off';
|
|
175
|
+
logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Turn on dimmer switch
|
|
183
|
+
*/
|
|
184
|
+
async turnOn() {
|
|
185
|
+
logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
|
|
186
|
+
const body = {
|
|
187
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
188
|
+
status: 'on',
|
|
189
|
+
uuid: this.cid
|
|
190
|
+
};
|
|
191
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
192
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
193
|
+
this.deviceStatus = 'on';
|
|
194
|
+
logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Set brightness level
|
|
202
|
+
*/
|
|
203
|
+
async setBrightness(brightness) {
|
|
204
|
+
if (!this.isDimmable()) {
|
|
205
|
+
logger_1.logger.error(`Device ${this.deviceName} does not support dimming`);
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
logger_1.logger.debug(`Setting brightness to ${brightness} for device: ${this.deviceName}`);
|
|
209
|
+
const body = {
|
|
210
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
211
|
+
brightness: brightness.toString(),
|
|
212
|
+
uuid: this.cid
|
|
213
|
+
};
|
|
214
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
215
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
216
|
+
this._brightness = brightness;
|
|
217
|
+
logger_1.logger.debug(`Successfully set brightness to ${brightness} for device: ${this.deviceName}`);
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
logger_1.logger.error(`Failed to set brightness to ${brightness} for device: ${this.deviceName}`);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Set RGB indicator color
|
|
225
|
+
*/
|
|
226
|
+
async rgbColorSet(red, green, blue) {
|
|
227
|
+
logger_1.logger.debug(`Setting RGB color to (${red}, ${green}, ${blue}) for device: ${this.deviceName}`);
|
|
228
|
+
const body = {
|
|
229
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
230
|
+
rgbValue: {
|
|
231
|
+
red: Math.round(red),
|
|
232
|
+
green: Math.round(green),
|
|
233
|
+
blue: Math.round(blue)
|
|
234
|
+
},
|
|
235
|
+
status: 'on',
|
|
236
|
+
uuid: this.cid
|
|
237
|
+
};
|
|
238
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
239
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
240
|
+
this._rgbValue = { red, green, blue };
|
|
241
|
+
this._rgbStatus = 'on';
|
|
242
|
+
logger_1.logger.debug(`Successfully set RGB color for device: ${this.deviceName}`);
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
logger_1.logger.error(`Failed to set RGB color for device: ${this.deviceName}`);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Turn on RGB indicator
|
|
250
|
+
*/
|
|
251
|
+
async rgbColorOff() {
|
|
252
|
+
logger_1.logger.debug(`Turning off RGB color for device: ${this.deviceName}`);
|
|
253
|
+
const body = {
|
|
254
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
255
|
+
status: 'off',
|
|
256
|
+
uuid: this.cid
|
|
257
|
+
};
|
|
258
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
259
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
260
|
+
this._rgbStatus = 'off';
|
|
261
|
+
logger_1.logger.debug(`Successfully turned off RGB color for device: ${this.deviceName}`);
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
logger_1.logger.error(`Failed to turn off RGB color for device: ${this.deviceName}`);
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Turn RGB Color On
|
|
269
|
+
*/
|
|
270
|
+
async rgbColorOn() {
|
|
271
|
+
logger_1.logger.debug(`Turning on RGB color for device: ${this.deviceName}`);
|
|
272
|
+
const body = {
|
|
273
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
274
|
+
uuid: this.cid,
|
|
275
|
+
status: 'on'
|
|
276
|
+
};
|
|
277
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
278
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
279
|
+
this._rgbStatus = 'on';
|
|
280
|
+
logger_1.logger.debug(`Successfully turned on RGB color for device: ${this.deviceName}`);
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
logger_1.logger.error(`Failed to turn on RGB color for device: ${this.deviceName}`);
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Turn indicator light on
|
|
288
|
+
*/
|
|
289
|
+
async indicatorLightOn() {
|
|
290
|
+
logger_1.logger.debug(`Turning on indicator light for device: ${this.deviceName}`);
|
|
291
|
+
const body = {
|
|
292
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
293
|
+
uuid: this.cid,
|
|
294
|
+
status: 'on'
|
|
295
|
+
};
|
|
296
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
297
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
298
|
+
this._indicatorLight = 'on';
|
|
299
|
+
logger_1.logger.debug(`Successfully turned on indicator light for device: ${this.deviceName}`);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
logger_1.logger.error(`Failed to turn on indicator light for device: ${this.deviceName}`);
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Turn indicator light off
|
|
307
|
+
*/
|
|
308
|
+
async indicatorLightOff() {
|
|
309
|
+
logger_1.logger.debug(`Turning off indicator light for device: ${this.deviceName}`);
|
|
310
|
+
const body = {
|
|
311
|
+
...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
|
|
312
|
+
uuid: this.cid,
|
|
313
|
+
status: 'off'
|
|
314
|
+
};
|
|
315
|
+
const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
|
|
316
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
|
|
317
|
+
this._indicatorLight = 'off';
|
|
318
|
+
logger_1.logger.debug(`Successfully turned off indicator light for device: ${this.deviceName}`);
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
logger_1.logger.error(`Failed to turn off indicator light for device: ${this.deviceName}`);
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
// Getters
|
|
325
|
+
get brightness() {
|
|
326
|
+
return this._brightness;
|
|
327
|
+
}
|
|
328
|
+
get indicatorLightStatus() {
|
|
329
|
+
return this._indicatorLight;
|
|
330
|
+
}
|
|
331
|
+
get rgbLightStatus() {
|
|
332
|
+
return this._rgbStatus;
|
|
333
|
+
}
|
|
334
|
+
get rgbLightValue() {
|
|
335
|
+
return { ...this._rgbValue };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.VeSyncDimmerSwitch = VeSyncDimmerSwitch;
|
|
339
|
+
// Export switch modules dictionary
|
|
340
|
+
exports.switchModules = {
|
|
341
|
+
'ESWL01': VeSyncWallSwitch,
|
|
342
|
+
'ESWL03': VeSyncWallSwitch,
|
|
343
|
+
'ESWD16': VeSyncDimmerSwitch
|
|
344
|
+
};
|
package/package.json
CHANGED
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Export main VeSync manager class
|
|
2
|
+
export { VeSync } from './lib/vesync';
|
|
3
|
+
|
|
4
|
+
// Export device classes
|
|
5
|
+
export { VeSyncAirBypass } from './lib/vesyncFanImpl';
|
|
6
|
+
export { VeSyncOutlet7A, VeSyncOutlet10A, VeSyncOutlet15A, VeSyncOutdoorPlug } from './lib/vesyncOutletImpl';
|
|
7
|
+
export { VeSyncBulb } from './lib/vesyncBulb';
|
|
8
|
+
export { VeSyncWallSwitch } from './lib/vesyncSwitchImpl';
|
|
9
|
+
|
|
10
|
+
// Export base device class
|
|
11
|
+
export { VeSyncBaseDevice } from './lib/vesyncBaseDevice';
|
|
12
|
+
|
|
13
|
+
// Export helper functions
|
|
14
|
+
export { Helpers, setApiBaseUrl } from './lib/helpers';
|
package/src/lib/helpers.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
7
|
import { VeSync } from './vesync';
|
|
8
|
+
import { logger } from './logger';
|
|
8
9
|
|
|
9
10
|
// API configuration
|
|
10
11
|
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
@@ -216,7 +217,7 @@ export class Helpers {
|
|
|
216
217
|
if (error.response) {
|
|
217
218
|
return [error.response.data, error.response.status];
|
|
218
219
|
}
|
|
219
|
-
|
|
220
|
+
logger.error('API call failed:', error.message);
|
|
220
221
|
return [null, 0];
|
|
221
222
|
}
|
|
222
223
|
}
|
|
@@ -238,7 +239,7 @@ export class Helpers {
|
|
|
238
239
|
const decoded = Buffer.from(value, 'hex');
|
|
239
240
|
return decoded.readFloatBE(0).toString();
|
|
240
241
|
} catch (error) {
|
|
241
|
-
|
|
242
|
+
logger.debug('Error decoding hex value:', error);
|
|
242
243
|
return '0';
|
|
243
244
|
}
|
|
244
245
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility for TSVeSync
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export enum LogLevel {
|
|
6
|
+
DEBUG = 0,
|
|
7
|
+
INFO = 1,
|
|
8
|
+
WARN = 2,
|
|
9
|
+
ERROR = 3,
|
|
10
|
+
NONE = 4
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class Logger {
|
|
14
|
+
private static instance: Logger;
|
|
15
|
+
private currentLevel: LogLevel = LogLevel.INFO;
|
|
16
|
+
|
|
17
|
+
private constructor() {}
|
|
18
|
+
|
|
19
|
+
static getInstance(): Logger {
|
|
20
|
+
if (!Logger.instance) {
|
|
21
|
+
Logger.instance = new Logger();
|
|
22
|
+
}
|
|
23
|
+
return Logger.instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setLevel(level: LogLevel): void {
|
|
27
|
+
this.currentLevel = level;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getLevel(): LogLevel {
|
|
31
|
+
return this.currentLevel;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
debug(message: string, ...args: any[]): void {
|
|
35
|
+
if (this.currentLevel <= LogLevel.DEBUG) {
|
|
36
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
info(message: string, ...args: any[]): void {
|
|
41
|
+
if (this.currentLevel <= LogLevel.INFO) {
|
|
42
|
+
console.log(`[INFO] ${message}`, ...args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
warn(message: string, ...args: any[]): void {
|
|
47
|
+
if (this.currentLevel <= LogLevel.WARN) {
|
|
48
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
error(message: string, ...args: any[]): void {
|
|
53
|
+
if (this.currentLevel <= LogLevel.ERROR) {
|
|
54
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Export singleton instance
|
|
60
|
+
export const logger = Logger.getInstance();
|