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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { VeSync } from './vesync';
|
|
6
|
+
import { logger } from './logger';
|
|
6
7
|
|
|
7
8
|
export abstract class VeSyncBaseDevice {
|
|
8
9
|
protected manager: VeSync;
|
|
@@ -37,11 +38,11 @@ export abstract class VeSyncBaseDevice {
|
|
|
37
38
|
* Return formatted device info to stdout
|
|
38
39
|
*/
|
|
39
40
|
display(): void {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
logger.info(`Device Name: ${this.deviceName}`);
|
|
42
|
+
logger.info(`Status: ${this.deviceStatus}`);
|
|
43
|
+
logger.info(`Device Type: ${this.deviceType}`);
|
|
44
|
+
logger.info(`Connection: ${this.connectionStatus}`);
|
|
45
|
+
logger.info(`Version: ${this.config.current_firmware_version || 'Unknown'}`);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/**
|
|
@@ -90,13 +91,13 @@ export abstract class VeSyncBaseDevice {
|
|
|
90
91
|
*/
|
|
91
92
|
protected logError(method: string, error: any): void {
|
|
92
93
|
const errorMsg = error?.message || error;
|
|
93
|
-
|
|
94
|
+
logger.error(`[${this.deviceName}] ${method}: ${errorMsg}`);
|
|
94
95
|
|
|
95
96
|
// Log additional error details if available
|
|
96
97
|
if (error?.response?.data) {
|
|
97
98
|
const responseData = error.response.data;
|
|
98
99
|
const msg = responseData.msg || responseData.message || JSON.stringify(responseData);
|
|
99
|
-
|
|
100
|
+
logger.error(`Response: ${msg}`);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
package/src/lib/vesyncBulb.ts
CHANGED
|
@@ -5,22 +5,35 @@
|
|
|
5
5
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
6
6
|
import { VeSync } from './vesync';
|
|
7
7
|
import { Helpers } from './helpers';
|
|
8
|
+
import { logger } from './logger';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
interface BulbConfig {
|
|
11
|
+
[key: string]: {
|
|
12
|
+
module: string;
|
|
13
|
+
features: string[];
|
|
14
|
+
colorModel: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Bulb configuration
|
|
19
|
+
export const bulbConfig: BulbConfig = {
|
|
11
20
|
'ESL100': {
|
|
21
|
+
module: 'VeSyncBulbESL100',
|
|
12
22
|
features: ['dimmable'],
|
|
13
23
|
colorModel: 'none'
|
|
14
24
|
},
|
|
15
25
|
'ESL100CW': {
|
|
26
|
+
module: 'VeSyncBulbESL100CW',
|
|
16
27
|
features: ['dimmable', 'color_temp'],
|
|
17
28
|
colorModel: 'none'
|
|
18
29
|
},
|
|
19
30
|
'XYD0001': {
|
|
31
|
+
module: 'VeSyncBulbXYD0001',
|
|
20
32
|
features: ['dimmable', 'color_temp', 'rgb_shift'],
|
|
21
33
|
colorModel: 'hsv'
|
|
22
34
|
},
|
|
23
35
|
'ESL100MC': {
|
|
36
|
+
module: 'VeSyncBulbESL100MC',
|
|
24
37
|
features: ['dimmable', 'rgb_shift'],
|
|
25
38
|
colorModel: 'rgb'
|
|
26
39
|
}
|
|
@@ -47,7 +60,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
47
60
|
this.colorHue = 0;
|
|
48
61
|
this.colorSaturation = 0;
|
|
49
62
|
this.colorMode = '';
|
|
50
|
-
this.features =
|
|
63
|
+
this.features = bulbConfig[this.deviceType]?.features || [];
|
|
51
64
|
this.rgbValues = {
|
|
52
65
|
red: 0,
|
|
53
66
|
green: 0,
|
|
@@ -59,27 +72,43 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
59
72
|
* Get bulb details
|
|
60
73
|
*/
|
|
61
74
|
async getDetails(): Promise<void> {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
logger.debug(`[${this.deviceName}] Getting bulb details`);
|
|
76
|
+
|
|
77
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
78
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
79
|
+
const body = isV2Device ? {
|
|
80
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
81
|
+
cid: this.cid,
|
|
82
|
+
configModule: this.configModule,
|
|
83
|
+
payload: {
|
|
84
|
+
data: {},
|
|
85
|
+
method: 'getLightStatusV2',
|
|
86
|
+
source: 'APP'
|
|
87
|
+
}
|
|
88
|
+
} : {
|
|
89
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
90
|
+
cid: this.cid,
|
|
91
|
+
configModule: this.configModule,
|
|
92
|
+
jsonCmd: {
|
|
93
|
+
getLightStatus: 'get'
|
|
94
|
+
}
|
|
66
95
|
};
|
|
67
96
|
|
|
68
97
|
const [response] = await Helpers.callApi(
|
|
69
|
-
|
|
98
|
+
endpoint,
|
|
70
99
|
'post',
|
|
71
100
|
body,
|
|
72
101
|
Helpers.reqHeaders(this.manager)
|
|
73
102
|
);
|
|
74
103
|
|
|
75
104
|
if (response?.code === 0 && response?.result) {
|
|
76
|
-
this.deviceStatus = response.result.
|
|
105
|
+
this.deviceStatus = response.result.enabled ? 'on' : 'off';
|
|
77
106
|
this.brightness = response.result.brightness || this.brightness;
|
|
78
107
|
if (this.features.includes('color_temp')) {
|
|
79
108
|
this.colorTemp = response.result.colorTemp || this.colorTemp;
|
|
80
109
|
}
|
|
81
110
|
if (this.features.includes('rgb_shift')) {
|
|
82
|
-
if (
|
|
111
|
+
if (bulbConfig[this.deviceType].colorModel === 'rgb') {
|
|
83
112
|
this.rgbValues = {
|
|
84
113
|
red: response.result.red || this.rgbValues.red,
|
|
85
114
|
green: response.result.green || this.rgbValues.green,
|
|
@@ -91,6 +120,9 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
91
120
|
this.colorValue = response.result.value || this.colorValue;
|
|
92
121
|
}
|
|
93
122
|
}
|
|
123
|
+
logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
|
|
124
|
+
} else {
|
|
125
|
+
logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
|
|
94
126
|
}
|
|
95
127
|
}
|
|
96
128
|
|
|
@@ -98,30 +130,55 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
98
130
|
* Update bulb status
|
|
99
131
|
*/
|
|
100
132
|
async update(): Promise<void> {
|
|
133
|
+
logger.debug(`[${this.deviceName}] Updating bulb information`);
|
|
101
134
|
await this.getDetails();
|
|
135
|
+
logger.debug(`[${this.deviceName}] Successfully updated bulb information`);
|
|
102
136
|
}
|
|
103
137
|
|
|
104
138
|
/**
|
|
105
139
|
* Turn bulb on
|
|
106
140
|
*/
|
|
107
141
|
async turnOn(): Promise<boolean> {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
142
|
+
logger.debug(`[${this.deviceName}] Turning bulb on`);
|
|
143
|
+
|
|
144
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
145
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
146
|
+
const body = isV2Device ? {
|
|
147
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
148
|
+
cid: this.cid,
|
|
149
|
+
configModule: this.configModule,
|
|
150
|
+
payload: {
|
|
151
|
+
data: {
|
|
152
|
+
enabled: true,
|
|
153
|
+
id: 0
|
|
154
|
+
},
|
|
155
|
+
method: 'setSwitch',
|
|
156
|
+
source: 'APP'
|
|
157
|
+
}
|
|
158
|
+
} : {
|
|
159
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
160
|
+
cid: this.cid,
|
|
161
|
+
configModule: this.configModule,
|
|
162
|
+
jsonCmd: {
|
|
163
|
+
light: {
|
|
164
|
+
action: 'on'
|
|
165
|
+
}
|
|
166
|
+
}
|
|
112
167
|
};
|
|
113
168
|
|
|
114
169
|
const [response] = await Helpers.callApi(
|
|
115
|
-
|
|
116
|
-
'
|
|
170
|
+
endpoint,
|
|
171
|
+
'post',
|
|
117
172
|
body,
|
|
118
173
|
Helpers.reqHeaders(this.manager)
|
|
119
174
|
);
|
|
120
175
|
|
|
121
176
|
if (response?.code === 0) {
|
|
122
177
|
this.deviceStatus = 'on';
|
|
178
|
+
logger.debug(`[${this.deviceName}] Successfully turned bulb on`);
|
|
123
179
|
return true;
|
|
124
180
|
}
|
|
181
|
+
logger.error(`[${this.deviceName}] Failed to turn bulb on: ${JSON.stringify(response)}`);
|
|
125
182
|
return false;
|
|
126
183
|
}
|
|
127
184
|
|
|
@@ -129,23 +186,46 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
129
186
|
* Turn bulb off
|
|
130
187
|
*/
|
|
131
188
|
async turnOff(): Promise<boolean> {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
189
|
+
logger.debug(`[${this.deviceName}] Turning bulb off`);
|
|
190
|
+
|
|
191
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
192
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
193
|
+
const body = isV2Device ? {
|
|
194
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
195
|
+
cid: this.cid,
|
|
196
|
+
configModule: this.configModule,
|
|
197
|
+
payload: {
|
|
198
|
+
data: {
|
|
199
|
+
enabled: false,
|
|
200
|
+
id: 0
|
|
201
|
+
},
|
|
202
|
+
method: 'setSwitch',
|
|
203
|
+
source: 'APP'
|
|
204
|
+
}
|
|
205
|
+
} : {
|
|
206
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
207
|
+
cid: this.cid,
|
|
208
|
+
configModule: this.configModule,
|
|
209
|
+
jsonCmd: {
|
|
210
|
+
light: {
|
|
211
|
+
action: 'off'
|
|
212
|
+
}
|
|
213
|
+
}
|
|
136
214
|
};
|
|
137
215
|
|
|
138
216
|
const [response] = await Helpers.callApi(
|
|
139
|
-
|
|
140
|
-
'
|
|
217
|
+
endpoint,
|
|
218
|
+
'post',
|
|
141
219
|
body,
|
|
142
220
|
Helpers.reqHeaders(this.manager)
|
|
143
221
|
);
|
|
144
222
|
|
|
145
223
|
if (response?.code === 0) {
|
|
146
224
|
this.deviceStatus = 'off';
|
|
225
|
+
logger.debug(`[${this.deviceName}] Successfully turned bulb off`);
|
|
147
226
|
return true;
|
|
148
227
|
}
|
|
228
|
+
logger.error(`[${this.deviceName}] Failed to turn bulb off: ${JSON.stringify(response)}`);
|
|
149
229
|
return false;
|
|
150
230
|
}
|
|
151
231
|
|
|
@@ -154,27 +234,55 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
154
234
|
*/
|
|
155
235
|
async setBrightness(brightness: number): Promise<boolean> {
|
|
156
236
|
if (!this.features.includes('dimmable')) {
|
|
237
|
+
logger.error(`[${this.deviceName}] Dimming not supported`);
|
|
157
238
|
return false;
|
|
158
239
|
}
|
|
159
240
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
241
|
+
logger.debug(`[${this.deviceName}] Setting brightness to ${brightness}`);
|
|
242
|
+
|
|
243
|
+
const isV2Device = this.deviceType === 'XYD0001';
|
|
244
|
+
const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
|
|
245
|
+
const body = isV2Device ? {
|
|
246
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
247
|
+
cid: this.cid,
|
|
248
|
+
configModule: this.configModule,
|
|
249
|
+
payload: {
|
|
250
|
+
data: {
|
|
251
|
+
brightness: brightness,
|
|
252
|
+
colorMode: '',
|
|
253
|
+
colorTemp: '',
|
|
254
|
+
force: 0,
|
|
255
|
+
hue: '',
|
|
256
|
+
saturation: '',
|
|
257
|
+
value: ''
|
|
258
|
+
},
|
|
259
|
+
method: 'setLightStatusV2',
|
|
260
|
+
source: 'APP'
|
|
261
|
+
}
|
|
262
|
+
} : {
|
|
263
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
264
|
+
cid: this.cid,
|
|
265
|
+
configModule: this.configModule,
|
|
266
|
+
jsonCmd: {
|
|
267
|
+
light: {
|
|
268
|
+
brightness: brightness
|
|
269
|
+
}
|
|
270
|
+
}
|
|
165
271
|
};
|
|
166
272
|
|
|
167
273
|
const [response] = await Helpers.callApi(
|
|
168
|
-
|
|
169
|
-
'
|
|
274
|
+
endpoint,
|
|
275
|
+
'post',
|
|
170
276
|
body,
|
|
171
277
|
Helpers.reqHeaders(this.manager)
|
|
172
278
|
);
|
|
173
279
|
|
|
174
280
|
if (response?.code === 0) {
|
|
175
281
|
this.brightness = brightness;
|
|
282
|
+
logger.debug(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
|
|
176
283
|
return true;
|
|
177
284
|
}
|
|
285
|
+
logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
|
|
178
286
|
return false;
|
|
179
287
|
}
|
|
180
288
|
|
|
@@ -239,7 +347,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
|
|
|
239
347
|
* Get RGB values
|
|
240
348
|
*/
|
|
241
349
|
getRGBValues(): { red: number, green: number, blue: number } {
|
|
242
|
-
if (!this.features.includes('rgb_shift') ||
|
|
350
|
+
if (!this.features.includes('rgb_shift') || bulbConfig[this.deviceType].colorModel !== 'rgb') {
|
|
243
351
|
return { red: 0, green: 0, blue: 0 };
|
|
244
352
|
}
|
|
245
353
|
return this.rgbValues;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* VeSync Bulb Implementations
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { VeSyncBulb } from './vesyncBulb';
|
|
5
|
+
import { VeSyncBulb, bulbConfig } from './vesyncBulb';
|
|
6
6
|
import { VeSync } from './vesync';
|
|
7
7
|
import { Helpers } from './helpers';
|
|
8
|
+
import { logger } from './logger';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* ESL100 Bulb Implementation
|
|
@@ -15,6 +16,7 @@ export class VeSyncBulbESL100 extends VeSyncBulb {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
async setColorTemp(colorTemp: number): Promise<boolean> {
|
|
19
|
+
logger.error(`[${this.deviceName}] Color temperature control not supported`);
|
|
18
20
|
return false;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -29,27 +31,35 @@ export class VeSyncBulbESL100CW extends VeSyncBulb {
|
|
|
29
31
|
|
|
30
32
|
async setColorTemp(colorTemp: number): Promise<boolean> {
|
|
31
33
|
if (!this.features.includes('color_temp')) {
|
|
34
|
+
logger.error(`[${this.deviceName}] Color temperature control not supported`);
|
|
32
35
|
return false;
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
|
|
35
39
|
const body = {
|
|
36
|
-
...Helpers.reqBody(this.manager, '
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
41
|
+
cid: this.cid,
|
|
42
|
+
configModule: this.configModule,
|
|
43
|
+
jsonCmd: {
|
|
44
|
+
light: {
|
|
45
|
+
colorTempe: colorTemp
|
|
46
|
+
}
|
|
47
|
+
}
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
const [response] = await Helpers.callApi(
|
|
43
|
-
'/
|
|
44
|
-
'
|
|
51
|
+
'/cloud/v1/deviceManaged/bypass',
|
|
52
|
+
'post',
|
|
45
53
|
body,
|
|
46
54
|
Helpers.reqHeaders(this.manager)
|
|
47
55
|
);
|
|
48
56
|
|
|
49
57
|
if (response?.code === 0) {
|
|
50
58
|
this.colorTemp = colorTemp;
|
|
59
|
+
logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
51
60
|
return true;
|
|
52
61
|
}
|
|
62
|
+
logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
53
63
|
return false;
|
|
54
64
|
}
|
|
55
65
|
}
|
|
@@ -64,48 +74,75 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
|
|
|
64
74
|
|
|
65
75
|
async setColorTemp(colorTemp: number): Promise<boolean> {
|
|
66
76
|
if (!this.features.includes('color_temp')) {
|
|
77
|
+
logger.error(`[${this.deviceName}] Color temperature control not supported`);
|
|
67
78
|
return false;
|
|
68
79
|
}
|
|
69
80
|
|
|
81
|
+
logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
|
|
70
82
|
const body = {
|
|
71
|
-
...Helpers.reqBody(this.manager, '
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
84
|
+
cid: this.cid,
|
|
85
|
+
configModule: this.configModule,
|
|
86
|
+
payload: {
|
|
87
|
+
data: {
|
|
88
|
+
brightness: '',
|
|
89
|
+
colorMode: 'white',
|
|
90
|
+
colorTemp: colorTemp,
|
|
91
|
+
force: 1,
|
|
92
|
+
hue: '',
|
|
93
|
+
saturation: '',
|
|
94
|
+
value: ''
|
|
95
|
+
},
|
|
96
|
+
method: 'setLightStatusV2',
|
|
97
|
+
source: 'APP'
|
|
98
|
+
}
|
|
75
99
|
};
|
|
76
100
|
|
|
77
101
|
const [response] = await Helpers.callApi(
|
|
78
|
-
'/
|
|
79
|
-
'
|
|
102
|
+
'/cloud/v2/deviceManaged/bypassV2',
|
|
103
|
+
'post',
|
|
80
104
|
body,
|
|
81
105
|
Helpers.reqHeaders(this.manager)
|
|
82
106
|
);
|
|
83
107
|
|
|
84
108
|
if (response?.code === 0) {
|
|
85
109
|
this.colorTemp = colorTemp;
|
|
110
|
+
logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
|
|
86
111
|
return true;
|
|
87
112
|
}
|
|
113
|
+
logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
|
|
88
114
|
return false;
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
async setHsv(hue: number, saturation: number, value: number): Promise<boolean> {
|
|
92
118
|
if (!this.features.includes('rgb_shift')) {
|
|
119
|
+
logger.error(`[${this.deviceName}] Color control not supported`);
|
|
93
120
|
return false;
|
|
94
121
|
}
|
|
95
122
|
|
|
123
|
+
logger.debug(`[${this.deviceName}] Setting HSV color to H:${hue} S:${saturation} V:${value}`);
|
|
96
124
|
const body = {
|
|
97
|
-
...Helpers.reqBody(this.manager, '
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
126
|
+
cid: this.cid,
|
|
127
|
+
configModule: this.configModule,
|
|
128
|
+
payload: {
|
|
129
|
+
data: {
|
|
130
|
+
brightness: value,
|
|
131
|
+
colorMode: 'hsv',
|
|
132
|
+
colorTemp: '',
|
|
133
|
+
force: 1,
|
|
134
|
+
hue: hue,
|
|
135
|
+
saturation: saturation,
|
|
136
|
+
value: value
|
|
137
|
+
},
|
|
138
|
+
method: 'setLightStatusV2',
|
|
139
|
+
source: 'APP'
|
|
140
|
+
}
|
|
104
141
|
};
|
|
105
142
|
|
|
106
143
|
const [response] = await Helpers.callApi(
|
|
107
|
-
'/
|
|
108
|
-
'
|
|
144
|
+
'/cloud/v2/deviceManaged/bypassV2',
|
|
145
|
+
'post',
|
|
109
146
|
body,
|
|
110
147
|
Helpers.reqHeaders(this.manager)
|
|
111
148
|
);
|
|
@@ -114,30 +151,47 @@ export class VeSyncBulbXYD0001 extends VeSyncBulb {
|
|
|
114
151
|
this.colorHue = hue;
|
|
115
152
|
this.colorSaturation = saturation;
|
|
116
153
|
this.colorValue = value;
|
|
154
|
+
logger.debug(`[${this.deviceName}] Successfully set HSV color`);
|
|
117
155
|
return true;
|
|
118
156
|
}
|
|
157
|
+
logger.error(`[${this.deviceName}] Failed to set HSV color: ${JSON.stringify(response)}`);
|
|
119
158
|
return false;
|
|
120
159
|
}
|
|
121
160
|
|
|
122
161
|
async enableWhiteMode(): Promise<boolean> {
|
|
162
|
+
logger.debug(`[${this.deviceName}] Enabling white mode`);
|
|
123
163
|
const body = {
|
|
124
|
-
...Helpers.reqBody(this.manager, '
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
164
|
+
...Helpers.reqBody(this.manager, 'bypassV2'),
|
|
165
|
+
cid: this.cid,
|
|
166
|
+
configModule: this.configModule,
|
|
167
|
+
payload: {
|
|
168
|
+
data: {
|
|
169
|
+
brightness: '',
|
|
170
|
+
colorMode: 'white',
|
|
171
|
+
colorTemp: '',
|
|
172
|
+
force: 1,
|
|
173
|
+
red: '',
|
|
174
|
+
green: '',
|
|
175
|
+
blue: ''
|
|
176
|
+
},
|
|
177
|
+
method: 'setLightStatusV2',
|
|
178
|
+
source: 'APP'
|
|
179
|
+
}
|
|
128
180
|
};
|
|
129
181
|
|
|
130
182
|
const [response] = await Helpers.callApi(
|
|
131
|
-
'/
|
|
132
|
-
'
|
|
183
|
+
'/cloud/v2/deviceManaged/bypassV2',
|
|
184
|
+
'post',
|
|
133
185
|
body,
|
|
134
186
|
Helpers.reqHeaders(this.manager)
|
|
135
187
|
);
|
|
136
188
|
|
|
137
189
|
if (response?.code === 0) {
|
|
138
190
|
this.colorMode = 'white';
|
|
191
|
+
logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
|
|
139
192
|
return true;
|
|
140
193
|
}
|
|
194
|
+
logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
|
141
195
|
return false;
|
|
142
196
|
}
|
|
143
197
|
}
|
|
@@ -151,63 +205,78 @@ export class VeSyncBulbESL100MC extends VeSyncBulb {
|
|
|
151
205
|
}
|
|
152
206
|
|
|
153
207
|
async setColorTemp(colorTemp: number): Promise<boolean> {
|
|
208
|
+
logger.error(`[${this.deviceName}] Color temperature control not supported`);
|
|
154
209
|
return false;
|
|
155
210
|
}
|
|
156
211
|
|
|
157
212
|
async setRgb(red: number, green: number, blue: number): Promise<boolean> {
|
|
158
213
|
if (!this.features.includes('rgb_shift')) {
|
|
214
|
+
logger.error(`[${this.deviceName}] Color control not supported`);
|
|
159
215
|
return false;
|
|
160
216
|
}
|
|
161
217
|
|
|
218
|
+
logger.debug(`[${this.deviceName}] Setting RGB color to R:${red} G:${green} B:${blue}`);
|
|
162
219
|
const body = {
|
|
163
|
-
...Helpers.reqBody(this.manager, '
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
220
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
221
|
+
cid: this.cid,
|
|
222
|
+
configModule: this.configModule,
|
|
223
|
+
jsonCmd: {
|
|
224
|
+
light: {
|
|
225
|
+
red: Math.round(red),
|
|
226
|
+
green: Math.round(green),
|
|
227
|
+
blue: Math.round(blue)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
170
230
|
};
|
|
171
231
|
|
|
172
232
|
const [response] = await Helpers.callApi(
|
|
173
|
-
'/
|
|
174
|
-
'
|
|
233
|
+
'/cloud/v1/deviceManaged/bypass',
|
|
234
|
+
'post',
|
|
175
235
|
body,
|
|
176
236
|
Helpers.reqHeaders(this.manager)
|
|
177
237
|
);
|
|
178
238
|
|
|
179
239
|
if (response?.code === 0) {
|
|
180
240
|
this.rgbValues = { red, green, blue };
|
|
241
|
+
logger.debug(`[${this.deviceName}] Successfully set RGB color`);
|
|
181
242
|
return true;
|
|
182
243
|
}
|
|
244
|
+
logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
|
|
183
245
|
return false;
|
|
184
246
|
}
|
|
185
247
|
|
|
186
248
|
async enableWhiteMode(): Promise<boolean> {
|
|
249
|
+
logger.debug(`[${this.deviceName}] Enabling white mode`);
|
|
187
250
|
const body = {
|
|
188
|
-
...Helpers.reqBody(this.manager, '
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
251
|
+
...Helpers.reqBody(this.manager, 'bypass'),
|
|
252
|
+
cid: this.cid,
|
|
253
|
+
configModule: this.configModule,
|
|
254
|
+
jsonCmd: {
|
|
255
|
+
light: {
|
|
256
|
+
mode: 'white'
|
|
257
|
+
}
|
|
258
|
+
}
|
|
192
259
|
};
|
|
193
260
|
|
|
194
261
|
const [response] = await Helpers.callApi(
|
|
195
|
-
'/
|
|
196
|
-
'
|
|
262
|
+
'/cloud/v1/deviceManaged/bypass',
|
|
263
|
+
'post',
|
|
197
264
|
body,
|
|
198
265
|
Helpers.reqHeaders(this.manager)
|
|
199
266
|
);
|
|
200
267
|
|
|
201
268
|
if (response?.code === 0) {
|
|
202
269
|
this.colorMode = 'white';
|
|
270
|
+
logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
|
|
203
271
|
return true;
|
|
204
272
|
}
|
|
273
|
+
logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
|
|
205
274
|
return false;
|
|
206
275
|
}
|
|
207
276
|
}
|
|
208
277
|
|
|
209
278
|
// Export the bulb modules dictionary
|
|
210
|
-
export const bulbModules: Record<string, any> = {
|
|
279
|
+
export const bulbModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncBulb> = {
|
|
211
280
|
'ESL100': VeSyncBulbESL100,
|
|
212
281
|
'ESL100CW': VeSyncBulbESL100CW,
|
|
213
282
|
'XYD0001': VeSyncBulbXYD0001,
|
package/src/lib/vesyncFan.ts
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
6
6
|
import { VeSync } from './vesync';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
type DeviceConstructor = new (config: Record<string, any>, manager: VeSync) => VeSyncBaseDevice;
|
|
7
|
+
import { logger } from './logger';
|
|
10
8
|
|
|
11
9
|
interface FanConfig {
|
|
12
10
|
[key: string]: {
|
|
@@ -396,7 +394,7 @@ export abstract class VeSyncFan extends VeSyncBaseDevice {
|
|
|
396
394
|
}
|
|
397
395
|
|
|
398
396
|
for (const [key, value, unit = ''] of info) {
|
|
399
|
-
|
|
397
|
+
logger.info(`${key.toString().padEnd(30, '.')} ${value}${unit}`);
|
|
400
398
|
}
|
|
401
399
|
}
|
|
402
400
|
|