tsvesync 1.0.11 → 1.0.12

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.
@@ -0,0 +1,161 @@
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
+ /**
10
+ * ESL100 Bulb Implementation
11
+ */
12
+ class VeSyncBulbESL100 extends vesyncBulb_1.VeSyncBulb {
13
+ constructor(details, manager) {
14
+ super(details, manager);
15
+ }
16
+ async setColorTemp(colorTemp) {
17
+ return false;
18
+ }
19
+ }
20
+ exports.VeSyncBulbESL100 = VeSyncBulbESL100;
21
+ /**
22
+ * ESL100CW Bulb Implementation
23
+ */
24
+ class VeSyncBulbESL100CW extends vesyncBulb_1.VeSyncBulb {
25
+ constructor(details, manager) {
26
+ super(details, manager);
27
+ }
28
+ async setColorTemp(colorTemp) {
29
+ if (!this.features.includes('color_temp')) {
30
+ return false;
31
+ }
32
+ const body = {
33
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
34
+ uuid: this.cid,
35
+ status: 'on',
36
+ colorTemp: colorTemp.toString()
37
+ };
38
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColorTemperature', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
39
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
40
+ this.colorTemp = colorTemp;
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ }
46
+ exports.VeSyncBulbESL100CW = VeSyncBulbESL100CW;
47
+ /**
48
+ * XYD0001 Bulb Implementation
49
+ */
50
+ class VeSyncBulbXYD0001 extends vesyncBulb_1.VeSyncBulb {
51
+ constructor(details, manager) {
52
+ super(details, manager);
53
+ }
54
+ async setColorTemp(colorTemp) {
55
+ if (!this.features.includes('color_temp')) {
56
+ return false;
57
+ }
58
+ const body = {
59
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
60
+ uuid: this.cid,
61
+ status: 'on',
62
+ colorTemp: colorTemp.toString()
63
+ };
64
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColorTemperature', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
65
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
66
+ this.colorTemp = colorTemp;
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ async setHsv(hue, saturation, value) {
72
+ if (!this.features.includes('rgb_shift')) {
73
+ return false;
74
+ }
75
+ const body = {
76
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
77
+ uuid: this.cid,
78
+ status: 'on',
79
+ mode: 'color',
80
+ hue: Math.round(hue).toString(),
81
+ saturation: Math.round(saturation).toString(),
82
+ brightness: Math.round(value).toString()
83
+ };
84
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColor', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
85
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
86
+ this.colorHue = hue;
87
+ this.colorSaturation = saturation;
88
+ this.colorValue = value;
89
+ return true;
90
+ }
91
+ return false;
92
+ }
93
+ async enableWhiteMode() {
94
+ const body = {
95
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
96
+ uuid: this.cid,
97
+ status: 'on',
98
+ colorMode: 'white'
99
+ };
100
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColorMode', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
101
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
102
+ this.colorMode = 'white';
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
+ }
108
+ exports.VeSyncBulbXYD0001 = VeSyncBulbXYD0001;
109
+ /**
110
+ * ESL100MC Bulb Implementation
111
+ */
112
+ class VeSyncBulbESL100MC extends vesyncBulb_1.VeSyncBulb {
113
+ constructor(details, manager) {
114
+ super(details, manager);
115
+ }
116
+ async setColorTemp(colorTemp) {
117
+ return false;
118
+ }
119
+ async setRgb(red, green, blue) {
120
+ if (!this.features.includes('rgb_shift')) {
121
+ return false;
122
+ }
123
+ const body = {
124
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
125
+ uuid: this.cid,
126
+ status: 'on',
127
+ mode: 'color',
128
+ red: Math.round(red).toString(),
129
+ green: Math.round(green).toString(),
130
+ blue: Math.round(blue).toString()
131
+ };
132
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColor', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
133
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
134
+ this.rgbValues = { red, green, blue };
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+ async enableWhiteMode() {
140
+ const body = {
141
+ ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
142
+ uuid: this.cid,
143
+ status: 'on',
144
+ colorMode: 'white'
145
+ };
146
+ const [response] = await helpers_1.Helpers.callApi('/SmartBulb/v1/device/updateColorMode', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
147
+ if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
148
+ this.colorMode = 'white';
149
+ return true;
150
+ }
151
+ return false;
152
+ }
153
+ }
154
+ exports.VeSyncBulbESL100MC = VeSyncBulbESL100MC;
155
+ // Export the bulb modules dictionary
156
+ exports.bulbModules = {
157
+ 'ESL100': VeSyncBulbESL100,
158
+ 'ESL100CW': VeSyncBulbESL100CW,
159
+ 'XYD0001': VeSyncBulbXYD0001,
160
+ 'ESL100MC': VeSyncBulbESL100MC
161
+ };
@@ -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 {};