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.
Files changed (40) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.js +25 -0
  3. package/dist/lib/helpers.d.ts +52 -51
  4. package/dist/lib/helpers.js +135 -112
  5. package/dist/lib/logger.d.ts +23 -0
  6. package/dist/lib/logger.js +54 -0
  7. package/dist/lib/vesync.d.ts +57 -15
  8. package/dist/lib/vesync.js +341 -217
  9. package/dist/lib/vesyncBaseDevice.d.ts +25 -50
  10. package/dist/lib/vesyncBaseDevice.js +63 -90
  11. package/dist/lib/vesyncBulb.d.ts +88 -0
  12. package/dist/lib/vesyncBulb.js +295 -1
  13. package/dist/lib/vesyncBulbImpl.d.ts +38 -0
  14. package/dist/lib/vesyncBulbImpl.js +230 -0
  15. package/dist/lib/vesyncFan.d.ts +55 -67
  16. package/dist/lib/vesyncFan.js +366 -213
  17. package/dist/lib/vesyncFanImpl.d.ts +173 -0
  18. package/dist/lib/vesyncFanImpl.js +909 -0
  19. package/dist/lib/vesyncOutlet.d.ts +70 -0
  20. package/dist/lib/vesyncOutlet.js +213 -1
  21. package/dist/lib/vesyncOutletImpl.d.ts +70 -0
  22. package/dist/lib/vesyncOutletImpl.js +245 -0
  23. package/dist/lib/vesyncSwitch.d.ts +45 -0
  24. package/dist/lib/vesyncSwitch.js +77 -1
  25. package/dist/lib/vesyncSwitchImpl.d.ts +82 -0
  26. package/dist/lib/vesyncSwitchImpl.js +344 -0
  27. package/package.json +1 -1
  28. package/src/index.ts +14 -0
  29. package/src/lib/helpers.ts +3 -2
  30. package/src/lib/logger.ts +60 -0
  31. package/src/lib/vesync.ts +42 -43
  32. package/src/lib/vesyncBaseDevice.ts +8 -7
  33. package/src/lib/vesyncBulb.ts +138 -30
  34. package/src/lib/vesyncBulbImpl.ts +113 -44
  35. package/src/lib/vesyncFan.ts +2 -4
  36. package/src/lib/vesyncFanImpl.ts +314 -42
  37. package/src/lib/vesyncOutlet.ts +140 -13
  38. package/src/lib/vesyncOutletImpl.ts +41 -0
  39. package/src/lib/vesyncSwitch.ts +3 -454
  40. package/src/lib/vesyncSwitchImpl.ts +66 -16
@@ -1,68 +1,43 @@
1
1
  /**
2
- * Base class for all VeSync devices
2
+ * Base class for VeSync devices
3
3
  */
4
4
  import { VeSync } from './vesync';
5
- export interface DeviceDetails {
6
- deviceName: string;
7
- deviceImg?: string;
8
- cid: string;
9
- connectionStatus: string;
10
- connectionType?: string;
11
- deviceType: string;
12
- type?: string;
13
- uuid?: string;
14
- configModule: string;
15
- macID?: string;
16
- mode?: string;
17
- speed?: number | string;
18
- extension?: any;
19
- currentFirmVersion?: string;
20
- deviceRegion?: string;
21
- deviceStatus?: string;
22
- subDeviceNo?: number;
23
- }
24
- export declare class VeSyncBaseDevice {
5
+ export declare abstract class VeSyncBaseDevice {
25
6
  protected manager: VeSync;
26
- deviceName: string;
27
- deviceImage: string | null;
7
+ protected config: Record<string, any>;
28
8
  cid: string;
29
- connectionStatus: string;
30
- connectionType: string | null;
9
+ deviceName: string;
10
+ deviceStatus: string;
31
11
  deviceType: string;
32
- type: string | null;
33
- uuid: string | null;
12
+ deviceRegion: string;
13
+ uuid: string;
34
14
  configModule: string;
35
- macId: string | null;
36
- mode: string | null;
37
- speed: number | null;
38
- extension: any;
39
- currentFirmVersion: string | null;
40
- deviceRegion: string | null;
41
- pid: string | null;
42
- subDeviceNo: number;
43
- config: {
44
- [key: string]: any;
45
- };
46
- deviceStatus: string | null;
47
- constructor(details: DeviceDetails, manager: VeSync);
15
+ macId: string;
16
+ deviceCategory: string;
17
+ connectionStatus: string;
18
+ constructor(details: Record<string, any>, manager: VeSync);
19
+ /**
20
+ * Return formatted device info to stdout
21
+ */
22
+ display(): void;
48
23
  /**
49
- * Return true if device is on
24
+ * Return JSON details for device
50
25
  */
51
- get isOn(): boolean;
26
+ displayJSON(): string;
52
27
  /**
53
- * Return true if firmware update available
28
+ * Check API response for errors
54
29
  */
55
- get firmwareUpdate(): boolean;
30
+ protected checkResponse(response: [any, number], method: string): boolean;
56
31
  /**
57
- * Get managed device configuration
32
+ * Log error with context
58
33
  */
59
- getPid(): Promise<void>;
34
+ protected logError(method: string, error: any): void;
60
35
  /**
61
- * Display device details
36
+ * Get device details
62
37
  */
63
- display(): void;
38
+ abstract getDetails(): Promise<void>;
64
39
  /**
65
- * Return device details as JSON string
40
+ * Update device details
66
41
  */
67
- displayJSON(): string;
42
+ update(): Promise<void>;
68
43
  }
@@ -1,116 +1,89 @@
1
1
  "use strict";
2
+ /**
3
+ * Base class for VeSync devices
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.VeSyncBaseDevice = void 0;
4
- const helpers_1 = require("./helpers");
7
+ const logger_1 = require("./logger");
5
8
  class VeSyncBaseDevice {
6
9
  constructor(details, manager) {
10
+ this.config = {};
7
11
  this.manager = manager;
8
- if (details.cid) {
9
- this.deviceName = details.deviceName;
10
- this.deviceImage = details.deviceImg || null;
11
- this.cid = details.cid;
12
- this.connectionStatus = details.connectionStatus;
13
- this.connectionType = details.connectionType || null;
14
- this.deviceType = details.deviceType;
15
- this.type = details.type || null;
16
- this.uuid = details.uuid || null;
17
- this.configModule = details.configModule;
18
- this.macId = details.macID || null;
19
- this.mode = details.mode || null;
20
- this.speed = typeof details.speed === 'string' && details.speed !== ''
21
- ? parseInt(details.speed)
22
- : (typeof details.speed === 'number' ? details.speed : null);
23
- this.extension = details.extension;
24
- this.currentFirmVersion = details.currentFirmVersion || null;
25
- this.deviceRegion = details.deviceRegion || null;
26
- this.pid = null;
27
- this.subDeviceNo = details.subDeviceNo || 0;
28
- this.config = {};
29
- if (typeof details.extension === 'object' && details.extension !== null) {
30
- const ext = details.extension;
31
- this.speed = ext.fanSpeedLevel;
32
- this.mode = ext.mode;
33
- }
34
- if (this.connectionStatus !== 'online') {
35
- this.deviceStatus = 'off';
36
- }
37
- else {
38
- this.deviceStatus = details.deviceStatus || null;
39
- }
40
- }
41
- else {
42
- throw new Error(`No cid found for ${this.constructor.name}`);
43
- }
12
+ this.cid = details.cid || '';
13
+ this.deviceName = details.deviceName || '';
14
+ this.deviceStatus = details.deviceStatus || 'off';
15
+ this.deviceType = details.deviceType || '';
16
+ this.deviceRegion = details.deviceRegion || '';
17
+ this.uuid = details.uuid || '';
18
+ this.configModule = details.configModule || '';
19
+ this.macId = details.macId || '';
20
+ this.deviceCategory = details.deviceCategory || '';
21
+ this.connectionStatus = details.connectionStatus || 'offline';
44
22
  }
45
23
  /**
46
- * Return true if device is on
24
+ * Return formatted device info to stdout
47
25
  */
48
- get isOn() {
49
- return this.deviceStatus === 'on';
26
+ display() {
27
+ logger_1.logger.info(`Device Name: ${this.deviceName}`);
28
+ logger_1.logger.info(`Status: ${this.deviceStatus}`);
29
+ logger_1.logger.info(`Device Type: ${this.deviceType}`);
30
+ logger_1.logger.info(`Connection: ${this.connectionStatus}`);
31
+ logger_1.logger.info(`Version: ${this.config.current_firmware_version || 'Unknown'}`);
50
32
  }
51
33
  /**
52
- * Return true if firmware update available
34
+ * Return JSON details for device
53
35
  */
54
- get firmwareUpdate() {
55
- const cfv = this.config?.current_firmware_version;
56
- const lfv = this.config?.latest_firmware_version;
57
- if (cfv !== undefined && lfv !== undefined) {
58
- return cfv !== lfv;
59
- }
60
- console.debug('Call device.getConfig() to get firmware versions');
61
- return false;
36
+ displayJSON() {
37
+ return JSON.stringify({
38
+ 'Device Name': this.deviceName,
39
+ 'Status': this.deviceStatus,
40
+ 'Device Type': this.deviceType,
41
+ 'Connection': this.connectionStatus,
42
+ 'Version': this.config.current_firmware_version || 'Unknown'
43
+ }, null, 4);
62
44
  }
63
45
  /**
64
- * Get managed device configuration
46
+ * Check API response for errors
65
47
  */
66
- async getPid() {
67
- const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
68
- body.configModule = this.configModule;
69
- body.region = this.deviceRegion;
70
- body.method = 'configInfo';
71
- const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/configInfo', 'post', body);
72
- if (typeof response !== 'object' ||
73
- response.code !== 0 ||
74
- !response.result) {
75
- console.error(`Error getting config info for ${this.deviceName}`);
76
- return;
48
+ checkResponse(response, method) {
49
+ const [data, status] = response;
50
+ // Check HTTP status
51
+ if (status !== 200) {
52
+ this.logError(method, `Invalid HTTP status: ${status}`);
53
+ return false;
77
54
  }
78
- this.pid = response.result?.pid;
55
+ // Check API response
56
+ if (!data) {
57
+ this.logError(method, 'No response data');
58
+ return false;
59
+ }
60
+ // Check error code - code 0 indicates success
61
+ if (data.code === 0) {
62
+ return true;
63
+ }
64
+ const msg = data.msg || 'Unknown error';
65
+ this.logError(method, `Error code ${data.code}: ${msg}`);
66
+ return false;
79
67
  }
80
68
  /**
81
- * Display device details
69
+ * Log error with context
82
70
  */
83
- display() {
84
- const disp = [
85
- ['Device Name:', this.deviceName],
86
- ['Model:', this.deviceType],
87
- ['Subdevice No:', this.subDeviceNo.toString()],
88
- ['Status:', this.deviceStatus],
89
- ['Online:', this.connectionStatus],
90
- ['Type:', this.type],
91
- ['CID:', this.cid],
92
- ];
93
- if (this.uuid) {
94
- disp.push(['UUID:', this.uuid]);
95
- }
96
- for (const line of disp) {
97
- console.log(`${line[0].padEnd(30, '.')} ${line[1]}`);
71
+ logError(method, error) {
72
+ var _a;
73
+ const errorMsg = (error === null || error === void 0 ? void 0 : error.message) || error;
74
+ logger_1.logger.error(`[${this.deviceName}] ${method}: ${errorMsg}`);
75
+ // Log additional error details if available
76
+ if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) {
77
+ const responseData = error.response.data;
78
+ const msg = responseData.msg || responseData.message || JSON.stringify(responseData);
79
+ logger_1.logger.error(`Response: ${msg}`);
98
80
  }
99
81
  }
100
82
  /**
101
- * Return device details as JSON string
83
+ * Update device details
102
84
  */
103
- displayJSON() {
104
- return JSON.stringify({
105
- 'Device Name': this.deviceName,
106
- 'Model': this.deviceType,
107
- 'Subdevice No': this.subDeviceNo.toString(),
108
- 'Status': this.deviceStatus,
109
- 'Online': this.connectionStatus,
110
- 'Type': this.type,
111
- 'CID': this.cid,
112
- }, null, 4);
85
+ async update() {
86
+ await this.getDetails();
113
87
  }
114
88
  }
115
89
  exports.VeSyncBaseDevice = VeSyncBaseDevice;
116
- //# sourceMappingURL=vesyncBaseDevice.js.map
@@ -0,0 +1,88 @@
1
+ /**
2
+ * VeSync Bulb Base Class
3
+ */
4
+ import { VeSyncBaseDevice } from './vesyncBaseDevice';
5
+ import { VeSync } from './vesync';
6
+ interface BulbConfig {
7
+ [key: string]: {
8
+ module: string;
9
+ features: string[];
10
+ colorModel: string;
11
+ };
12
+ }
13
+ export declare const bulbConfig: BulbConfig;
14
+ /**
15
+ * VeSync Bulb Base Class
16
+ */
17
+ export declare abstract class VeSyncBulb extends VeSyncBaseDevice {
18
+ protected brightness: number;
19
+ protected colorTemp: number;
20
+ protected colorValue: number;
21
+ protected colorHue: number;
22
+ protected colorSaturation: number;
23
+ protected colorMode: string;
24
+ protected features: string[];
25
+ protected rgbValues: {
26
+ red: number;
27
+ green: number;
28
+ blue: number;
29
+ };
30
+ constructor(details: Record<string, any>, manager: VeSync);
31
+ /**
32
+ * Get bulb details
33
+ */
34
+ getDetails(): Promise<void>;
35
+ /**
36
+ * Update bulb status
37
+ */
38
+ update(): Promise<void>;
39
+ /**
40
+ * Turn bulb on
41
+ */
42
+ turnOn(): Promise<boolean>;
43
+ /**
44
+ * Turn bulb off
45
+ */
46
+ turnOff(): Promise<boolean>;
47
+ /**
48
+ * Set bulb brightness
49
+ */
50
+ setBrightness(brightness: number): Promise<boolean>;
51
+ /**
52
+ * Get bulb brightness
53
+ */
54
+ getBrightness(): number;
55
+ /**
56
+ * Get color temperature in Kelvin
57
+ */
58
+ getColorTempKelvin(): number;
59
+ /**
60
+ * Get color temperature in percent
61
+ */
62
+ getColorTempPercent(): number;
63
+ /**
64
+ * Get color hue
65
+ */
66
+ getColorHue(): number;
67
+ /**
68
+ * Get color saturation
69
+ */
70
+ getColorSaturation(): number;
71
+ /**
72
+ * Get color value
73
+ */
74
+ getColorValue(): number;
75
+ /**
76
+ * Get RGB values
77
+ */
78
+ getRGBValues(): {
79
+ red: number;
80
+ green: number;
81
+ blue: number;
82
+ };
83
+ /**
84
+ * Set color temperature - Abstract method to be implemented by subclasses
85
+ */
86
+ abstract setColorTemp(colorTemp: number): Promise<boolean>;
87
+ }
88
+ export {};
@@ -1,2 +1,296 @@
1
1
  "use strict";
2
- //# sourceMappingURL=vesyncBulb.js.map
2
+ /**
3
+ * VeSync Bulb Base Class
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VeSyncBulb = exports.bulbConfig = void 0;
7
+ const vesyncBaseDevice_1 = require("./vesyncBaseDevice");
8
+ const helpers_1 = require("./helpers");
9
+ const logger_1 = require("./logger");
10
+ // Bulb configuration
11
+ exports.bulbConfig = {
12
+ 'ESL100': {
13
+ module: 'VeSyncBulbESL100',
14
+ features: ['dimmable'],
15
+ colorModel: 'none'
16
+ },
17
+ 'ESL100CW': {
18
+ module: 'VeSyncBulbESL100CW',
19
+ features: ['dimmable', 'color_temp'],
20
+ colorModel: 'none'
21
+ },
22
+ 'XYD0001': {
23
+ module: 'VeSyncBulbXYD0001',
24
+ features: ['dimmable', 'color_temp', 'rgb_shift'],
25
+ colorModel: 'hsv'
26
+ },
27
+ 'ESL100MC': {
28
+ module: 'VeSyncBulbESL100MC',
29
+ features: ['dimmable', 'rgb_shift'],
30
+ colorModel: 'rgb'
31
+ }
32
+ };
33
+ /**
34
+ * VeSync Bulb Base Class
35
+ */
36
+ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
37
+ constructor(details, manager) {
38
+ var _a;
39
+ super(details, manager);
40
+ this.brightness = 0;
41
+ this.colorTemp = 0;
42
+ this.colorValue = 0;
43
+ this.colorHue = 0;
44
+ this.colorSaturation = 0;
45
+ this.colorMode = '';
46
+ this.features = ((_a = exports.bulbConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || [];
47
+ this.rgbValues = {
48
+ red: 0,
49
+ green: 0,
50
+ blue: 0
51
+ };
52
+ }
53
+ /**
54
+ * Get bulb details
55
+ */
56
+ async getDetails() {
57
+ logger_1.logger.debug(`[${this.deviceName}] Getting bulb details`);
58
+ const isV2Device = this.deviceType === 'XYD0001';
59
+ const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
60
+ const body = isV2Device ? {
61
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
62
+ cid: this.cid,
63
+ configModule: this.configModule,
64
+ payload: {
65
+ data: {},
66
+ method: 'getLightStatusV2',
67
+ source: 'APP'
68
+ }
69
+ } : {
70
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
71
+ cid: this.cid,
72
+ configModule: this.configModule,
73
+ jsonCmd: {
74
+ getLightStatus: 'get'
75
+ }
76
+ };
77
+ const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
78
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
79
+ this.deviceStatus = response.result.enabled ? 'on' : 'off';
80
+ this.brightness = response.result.brightness || this.brightness;
81
+ if (this.features.includes('color_temp')) {
82
+ this.colorTemp = response.result.colorTemp || this.colorTemp;
83
+ }
84
+ if (this.features.includes('rgb_shift')) {
85
+ if (exports.bulbConfig[this.deviceType].colorModel === 'rgb') {
86
+ this.rgbValues = {
87
+ red: response.result.red || this.rgbValues.red,
88
+ green: response.result.green || this.rgbValues.green,
89
+ blue: response.result.blue || this.rgbValues.blue
90
+ };
91
+ }
92
+ else {
93
+ this.colorHue = response.result.hue || this.colorHue;
94
+ this.colorSaturation = response.result.saturation || this.colorSaturation;
95
+ this.colorValue = response.result.value || this.colorValue;
96
+ }
97
+ }
98
+ logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
99
+ }
100
+ else {
101
+ logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
102
+ }
103
+ }
104
+ /**
105
+ * Update bulb status
106
+ */
107
+ async update() {
108
+ logger_1.logger.debug(`[${this.deviceName}] Updating bulb information`);
109
+ await this.getDetails();
110
+ logger_1.logger.debug(`[${this.deviceName}] Successfully updated bulb information`);
111
+ }
112
+ /**
113
+ * Turn bulb on
114
+ */
115
+ async turnOn() {
116
+ logger_1.logger.debug(`[${this.deviceName}] Turning bulb on`);
117
+ const isV2Device = this.deviceType === 'XYD0001';
118
+ const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
119
+ const body = isV2Device ? {
120
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
121
+ cid: this.cid,
122
+ configModule: this.configModule,
123
+ payload: {
124
+ data: {
125
+ enabled: true,
126
+ id: 0
127
+ },
128
+ method: 'setSwitch',
129
+ source: 'APP'
130
+ }
131
+ } : {
132
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
133
+ cid: this.cid,
134
+ configModule: this.configModule,
135
+ jsonCmd: {
136
+ light: {
137
+ action: 'on'
138
+ }
139
+ }
140
+ };
141
+ const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
142
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
143
+ this.deviceStatus = 'on';
144
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned bulb on`);
145
+ return true;
146
+ }
147
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb on: ${JSON.stringify(response)}`);
148
+ return false;
149
+ }
150
+ /**
151
+ * Turn bulb off
152
+ */
153
+ async turnOff() {
154
+ logger_1.logger.debug(`[${this.deviceName}] Turning bulb off`);
155
+ const isV2Device = this.deviceType === 'XYD0001';
156
+ const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
157
+ const body = isV2Device ? {
158
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
159
+ cid: this.cid,
160
+ configModule: this.configModule,
161
+ payload: {
162
+ data: {
163
+ enabled: false,
164
+ id: 0
165
+ },
166
+ method: 'setSwitch',
167
+ source: 'APP'
168
+ }
169
+ } : {
170
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
171
+ cid: this.cid,
172
+ configModule: this.configModule,
173
+ jsonCmd: {
174
+ light: {
175
+ action: 'off'
176
+ }
177
+ }
178
+ };
179
+ const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
180
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
181
+ this.deviceStatus = 'off';
182
+ logger_1.logger.debug(`[${this.deviceName}] Successfully turned bulb off`);
183
+ return true;
184
+ }
185
+ logger_1.logger.error(`[${this.deviceName}] Failed to turn bulb off: ${JSON.stringify(response)}`);
186
+ return false;
187
+ }
188
+ /**
189
+ * Set bulb brightness
190
+ */
191
+ async setBrightness(brightness) {
192
+ if (!this.features.includes('dimmable')) {
193
+ logger_1.logger.error(`[${this.deviceName}] Dimming not supported`);
194
+ return false;
195
+ }
196
+ logger_1.logger.debug(`[${this.deviceName}] Setting brightness to ${brightness}`);
197
+ const isV2Device = this.deviceType === 'XYD0001';
198
+ const endpoint = isV2Device ? '/cloud/v2/deviceManaged/bypassV2' : '/cloud/v1/deviceManaged/bypass';
199
+ const body = isV2Device ? {
200
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
201
+ cid: this.cid,
202
+ configModule: this.configModule,
203
+ payload: {
204
+ data: {
205
+ brightness: brightness,
206
+ colorMode: '',
207
+ colorTemp: '',
208
+ force: 0,
209
+ hue: '',
210
+ saturation: '',
211
+ value: ''
212
+ },
213
+ method: 'setLightStatusV2',
214
+ source: 'APP'
215
+ }
216
+ } : {
217
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
218
+ cid: this.cid,
219
+ configModule: this.configModule,
220
+ jsonCmd: {
221
+ light: {
222
+ brightness: brightness
223
+ }
224
+ }
225
+ };
226
+ const [response] = await helpers_1.Helpers.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
227
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
228
+ this.brightness = brightness;
229
+ logger_1.logger.debug(`[${this.deviceName}] Successfully set brightness to ${brightness}`);
230
+ return true;
231
+ }
232
+ logger_1.logger.error(`[${this.deviceName}] Failed to set brightness: ${JSON.stringify(response)}`);
233
+ return false;
234
+ }
235
+ /**
236
+ * Get bulb brightness
237
+ */
238
+ getBrightness() {
239
+ return this.brightness;
240
+ }
241
+ /**
242
+ * Get color temperature in Kelvin
243
+ */
244
+ getColorTempKelvin() {
245
+ if (!this.features.includes('color_temp')) {
246
+ return 0;
247
+ }
248
+ return ((6500 - 2700) * this.colorTemp / 100) + 2700;
249
+ }
250
+ /**
251
+ * Get color temperature in percent
252
+ */
253
+ getColorTempPercent() {
254
+ if (!this.features.includes('color_temp')) {
255
+ return 0;
256
+ }
257
+ return this.colorTemp;
258
+ }
259
+ /**
260
+ * Get color hue
261
+ */
262
+ getColorHue() {
263
+ if (!this.features.includes('rgb_shift')) {
264
+ return 0;
265
+ }
266
+ return this.colorHue;
267
+ }
268
+ /**
269
+ * Get color saturation
270
+ */
271
+ getColorSaturation() {
272
+ if (!this.features.includes('rgb_shift')) {
273
+ return 0;
274
+ }
275
+ return this.colorSaturation;
276
+ }
277
+ /**
278
+ * Get color value
279
+ */
280
+ getColorValue() {
281
+ if (!this.features.includes('rgb_shift')) {
282
+ return 0;
283
+ }
284
+ return this.colorValue;
285
+ }
286
+ /**
287
+ * Get RGB values
288
+ */
289
+ getRGBValues() {
290
+ if (!this.features.includes('rgb_shift') || exports.bulbConfig[this.deviceType].colorModel !== 'rgb') {
291
+ return { red: 0, green: 0, blue: 0 };
292
+ }
293
+ return this.rgbValues;
294
+ }
295
+ }
296
+ exports.VeSyncBulb = VeSyncBulb;