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
@@ -0,0 +1,38 @@
1
+ /**
2
+ * VeSync Bulb Implementations
3
+ */
4
+ import { VeSyncBulb } from './vesyncBulb';
5
+ import { VeSync } from './vesync';
6
+ /**
7
+ * ESL100 Bulb Implementation
8
+ */
9
+ export declare class VeSyncBulbESL100 extends VeSyncBulb {
10
+ constructor(details: Record<string, any>, manager: VeSync);
11
+ setColorTemp(colorTemp: number): Promise<boolean>;
12
+ }
13
+ /**
14
+ * ESL100CW Bulb Implementation
15
+ */
16
+ export declare class VeSyncBulbESL100CW extends VeSyncBulb {
17
+ constructor(details: Record<string, any>, manager: VeSync);
18
+ setColorTemp(colorTemp: number): Promise<boolean>;
19
+ }
20
+ /**
21
+ * XYD0001 Bulb Implementation
22
+ */
23
+ export declare class VeSyncBulbXYD0001 extends VeSyncBulb {
24
+ constructor(details: Record<string, any>, manager: VeSync);
25
+ setColorTemp(colorTemp: number): Promise<boolean>;
26
+ setHsv(hue: number, saturation: number, value: number): Promise<boolean>;
27
+ enableWhiteMode(): Promise<boolean>;
28
+ }
29
+ /**
30
+ * ESL100MC Bulb Implementation
31
+ */
32
+ export declare class VeSyncBulbESL100MC extends VeSyncBulb {
33
+ constructor(details: Record<string, any>, manager: VeSync);
34
+ setColorTemp(colorTemp: number): Promise<boolean>;
35
+ setRgb(red: number, green: number, blue: number): Promise<boolean>;
36
+ enableWhiteMode(): Promise<boolean>;
37
+ }
38
+ export declare const bulbModules: Record<string, new (details: Record<string, any>, manager: VeSync) => VeSyncBulb>;
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * VeSync Bulb Implementations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.bulbModules = exports.VeSyncBulbESL100MC = exports.VeSyncBulbXYD0001 = exports.VeSyncBulbESL100CW = exports.VeSyncBulbESL100 = void 0;
7
+ const vesyncBulb_1 = require("./vesyncBulb");
8
+ const helpers_1 = require("./helpers");
9
+ const logger_1 = require("./logger");
10
+ /**
11
+ * ESL100 Bulb Implementation
12
+ */
13
+ class VeSyncBulbESL100 extends vesyncBulb_1.VeSyncBulb {
14
+ constructor(details, manager) {
15
+ super(details, manager);
16
+ }
17
+ async setColorTemp(colorTemp) {
18
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
19
+ return false;
20
+ }
21
+ }
22
+ exports.VeSyncBulbESL100 = VeSyncBulbESL100;
23
+ /**
24
+ * ESL100CW Bulb Implementation
25
+ */
26
+ class VeSyncBulbESL100CW extends vesyncBulb_1.VeSyncBulb {
27
+ constructor(details, manager) {
28
+ super(details, manager);
29
+ }
30
+ async setColorTemp(colorTemp) {
31
+ if (!this.features.includes('color_temp')) {
32
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
33
+ return false;
34
+ }
35
+ logger_1.logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
36
+ const body = {
37
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
38
+ cid: this.cid,
39
+ configModule: this.configModule,
40
+ jsonCmd: {
41
+ light: {
42
+ colorTempe: colorTemp
43
+ }
44
+ }
45
+ };
46
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
47
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
48
+ this.colorTemp = colorTemp;
49
+ logger_1.logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
50
+ return true;
51
+ }
52
+ logger_1.logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
53
+ return false;
54
+ }
55
+ }
56
+ exports.VeSyncBulbESL100CW = VeSyncBulbESL100CW;
57
+ /**
58
+ * XYD0001 Bulb Implementation
59
+ */
60
+ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
61
+ constructor(details, manager) {
62
+ super(details, manager);
63
+ }
64
+ async setColorTemp(colorTemp) {
65
+ if (!this.features.includes('color_temp')) {
66
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
67
+ return false;
68
+ }
69
+ logger_1.logger.debug(`[${this.deviceName}] Setting color temperature to ${colorTemp}`);
70
+ const body = {
71
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
72
+ cid: this.cid,
73
+ configModule: this.configModule,
74
+ payload: {
75
+ data: {
76
+ brightness: '',
77
+ colorMode: 'white',
78
+ colorTemp: colorTemp,
79
+ force: 1,
80
+ hue: '',
81
+ saturation: '',
82
+ value: ''
83
+ },
84
+ method: 'setLightStatusV2',
85
+ source: 'APP'
86
+ }
87
+ };
88
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
89
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
90
+ this.colorTemp = colorTemp;
91
+ logger_1.logger.debug(`[${this.deviceName}] Successfully set color temperature to ${colorTemp}`);
92
+ return true;
93
+ }
94
+ logger_1.logger.error(`[${this.deviceName}] Failed to set color temperature: ${JSON.stringify(response)}`);
95
+ return false;
96
+ }
97
+ async setHsv(hue, saturation, value) {
98
+ if (!this.features.includes('rgb_shift')) {
99
+ logger_1.logger.error(`[${this.deviceName}] Color control not supported`);
100
+ return false;
101
+ }
102
+ logger_1.logger.debug(`[${this.deviceName}] Setting HSV color to H:${hue} S:${saturation} V:${value}`);
103
+ const body = {
104
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
105
+ cid: this.cid,
106
+ configModule: this.configModule,
107
+ payload: {
108
+ data: {
109
+ brightness: value,
110
+ colorMode: 'hsv',
111
+ colorTemp: '',
112
+ force: 1,
113
+ hue: hue,
114
+ saturation: saturation,
115
+ value: value
116
+ },
117
+ method: 'setLightStatusV2',
118
+ source: 'APP'
119
+ }
120
+ };
121
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
122
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
123
+ this.colorHue = hue;
124
+ this.colorSaturation = saturation;
125
+ this.colorValue = value;
126
+ logger_1.logger.debug(`[${this.deviceName}] Successfully set HSV color`);
127
+ return true;
128
+ }
129
+ logger_1.logger.error(`[${this.deviceName}] Failed to set HSV color: ${JSON.stringify(response)}`);
130
+ return false;
131
+ }
132
+ async enableWhiteMode() {
133
+ logger_1.logger.debug(`[${this.deviceName}] Enabling white mode`);
134
+ const body = {
135
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
136
+ cid: this.cid,
137
+ configModule: this.configModule,
138
+ payload: {
139
+ data: {
140
+ brightness: '',
141
+ colorMode: 'white',
142
+ colorTemp: '',
143
+ force: 1,
144
+ red: '',
145
+ green: '',
146
+ blue: ''
147
+ },
148
+ method: 'setLightStatusV2',
149
+ source: 'APP'
150
+ }
151
+ };
152
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
153
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
154
+ this.colorMode = 'white';
155
+ logger_1.logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
156
+ return true;
157
+ }
158
+ logger_1.logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
159
+ return false;
160
+ }
161
+ }
162
+ exports.VeSyncBulbXYD0001 = VeSyncBulbXYD0001;
163
+ /**
164
+ * ESL100MC Bulb Implementation
165
+ */
166
+ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
167
+ constructor(details, manager) {
168
+ super(details, manager);
169
+ }
170
+ async setColorTemp(colorTemp) {
171
+ logger_1.logger.error(`[${this.deviceName}] Color temperature control not supported`);
172
+ return false;
173
+ }
174
+ async setRgb(red, green, blue) {
175
+ if (!this.features.includes('rgb_shift')) {
176
+ logger_1.logger.error(`[${this.deviceName}] Color control not supported`);
177
+ return false;
178
+ }
179
+ logger_1.logger.debug(`[${this.deviceName}] Setting RGB color to R:${red} G:${green} B:${blue}`);
180
+ const body = {
181
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
182
+ cid: this.cid,
183
+ configModule: this.configModule,
184
+ jsonCmd: {
185
+ light: {
186
+ red: Math.round(red),
187
+ green: Math.round(green),
188
+ blue: Math.round(blue)
189
+ }
190
+ }
191
+ };
192
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
193
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
194
+ this.rgbValues = { red, green, blue };
195
+ logger_1.logger.debug(`[${this.deviceName}] Successfully set RGB color`);
196
+ return true;
197
+ }
198
+ logger_1.logger.error(`[${this.deviceName}] Failed to set RGB color: ${JSON.stringify(response)}`);
199
+ return false;
200
+ }
201
+ async enableWhiteMode() {
202
+ logger_1.logger.debug(`[${this.deviceName}] Enabling white mode`);
203
+ const body = {
204
+ ...helpers_1.Helpers.reqBody(this.manager, 'bypass'),
205
+ cid: this.cid,
206
+ configModule: this.configModule,
207
+ jsonCmd: {
208
+ light: {
209
+ mode: 'white'
210
+ }
211
+ }
212
+ };
213
+ const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/bypass', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
214
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
215
+ this.colorMode = 'white';
216
+ logger_1.logger.debug(`[${this.deviceName}] Successfully enabled white mode`);
217
+ return true;
218
+ }
219
+ logger_1.logger.error(`[${this.deviceName}] Failed to enable white mode: ${JSON.stringify(response)}`);
220
+ return false;
221
+ }
222
+ }
223
+ exports.VeSyncBulbESL100MC = VeSyncBulbESL100MC;
224
+ // Export the bulb modules dictionary
225
+ exports.bulbModules = {
226
+ 'ESL100': VeSyncBulbESL100,
227
+ 'ESL100CW': VeSyncBulbESL100CW,
228
+ 'XYD0001': VeSyncBulbXYD0001,
229
+ 'ESL100MC': VeSyncBulbESL100MC
230
+ };
@@ -1,92 +1,80 @@
1
1
  /**
2
- * VeSync API for controlling fans and purifiers
2
+ * VeSync Fan Classes
3
3
  */
4
4
  import { VeSyncBaseDevice } from './vesyncBaseDevice';
5
- import { Timer } from './helpers';
6
- interface HumidFeatures {
7
- module: string;
8
- models: string[];
9
- features: string[];
10
- mist_modes: string[];
11
- mist_levels: number[];
12
- warm_mist_levels?: number[];
5
+ import { VeSync } from './vesync';
6
+ interface FanConfig {
7
+ [key: string]: {
8
+ module: 'VeSyncAirBypass' | 'VeSyncHumidifier' | 'VeSyncWarmHumidifier';
9
+ features: string[];
10
+ };
13
11
  }
14
- interface AirFeatures {
15
- module: string;
16
- models: string[];
17
- modes?: string[];
18
- features: string[];
19
- levels?: number[];
20
- set_mode_method?: string;
21
- }
22
- export declare const humidFeatures: {
23
- [key: string]: HumidFeatures;
24
- };
25
- export declare const airFeatures: {
26
- [key: string]: AirFeatures;
27
- };
28
- export declare function modelDict(): {
29
- [key: string]: string;
30
- };
31
- export declare function modelFeatures(devType: string): AirFeatures | HumidFeatures;
32
- export declare const fanClasses: Set<string>;
33
- export declare const fanModules: {
34
- [key: string]: string;
35
- };
36
- interface AirDetails {
37
- filter_life: number;
38
- mode: string;
39
- level: number;
40
- display: boolean;
41
- child_lock: boolean;
42
- night_light: string;
43
- air_quality?: number;
44
- air_quality_value?: number;
45
- display_forever?: boolean;
46
- }
47
- export declare class VeSyncAirBypass extends VeSyncBaseDevice {
48
- private _configDict;
49
- private _features;
50
- details: AirDetails;
51
- timer: Timer | null;
52
- enabled: boolean;
53
- constructor(details: any, manager: any);
12
+ export declare const fanConfig: FanConfig;
13
+ /**
14
+ * Base class for VeSync Fans
15
+ */
16
+ export declare abstract class VeSyncFan extends VeSyncBaseDevice {
17
+ protected details: Record<string, any>;
18
+ protected mode_dict: Record<string, any>;
19
+ protected speed_dict: Record<string, any>;
20
+ protected features: string[];
21
+ constructor(details: Record<string, any>, manager: VeSync);
22
+ /**
23
+ * Check if feature is supported
24
+ */
25
+ hasFeature(feature: string): boolean;
54
26
  /**
55
- * Get configuration and details for air purifier
27
+ * Get current mode
56
28
  */
57
- getConfig(): Promise<void>;
29
+ get mode(): string;
58
30
  /**
59
- * Build bypass body for air purifier
31
+ * Get current speed
60
32
  */
61
- buildBypassBody(method: string): any;
33
+ get speed(): number;
62
34
  /**
63
- * Turn air purifier on/off
35
+ * Get filter life percentage
64
36
  */
65
- turnOn(toggle?: boolean): Promise<boolean>;
66
- turnOff(): Promise<boolean>;
37
+ get filterLife(): number;
67
38
  /**
68
- * Set mode for air purifier
39
+ * Get screen status
69
40
  */
70
- setMode(mode: string): Promise<boolean>;
41
+ get screenStatus(): string;
71
42
  /**
72
- * Set fan speed for air purifier
43
+ * Get child lock status
73
44
  */
74
- setLevel(level: number): Promise<boolean>;
45
+ get childLock(): string;
75
46
  /**
76
- * Set child lock for air purifier
47
+ * Get air quality (if supported)
77
48
  */
78
- setChildLock(toggle?: boolean): Promise<boolean>;
49
+ get airQuality(): string;
79
50
  /**
80
- * Set display for air purifier
51
+ * Get humidity level (if supported)
81
52
  */
82
- setDisplay(toggle?: boolean): Promise<boolean>;
53
+ get humidity(): number;
83
54
  /**
84
- * Update air purifier details
55
+ * Get mist level (if supported)
85
56
  */
86
- update(): Promise<void>;
57
+ get mistLevel(): number;
87
58
  /**
88
- * Display air purifier details
59
+ * Get warm level (if supported)
60
+ */
61
+ get warmLevel(): number;
62
+ /**
63
+ * Get timer status
64
+ */
65
+ get timer(): number;
66
+ /**
67
+ * Return formatted device info to stdout
89
68
  */
90
69
  display(): void;
70
+ /**
71
+ * Return JSON details for fan
72
+ */
73
+ displayJSON(): string;
74
+ abstract getDetails(): Promise<void>;
75
+ abstract turnOn(): Promise<boolean>;
76
+ abstract turnOff(): Promise<boolean>;
77
+ abstract changeFanSpeed(speed: number): Promise<boolean>;
78
+ abstract setMode(mode: string): Promise<boolean>;
91
79
  }
92
80
  export {};