homebridge-midea-platform 1.1.0-beta.4 → 1.1.0

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 (72) hide show
  1. package/.husky/pre-commit +0 -0
  2. package/CHANGELOG.md +3 -0
  3. package/config.schema.json +8 -1
  4. package/dist/accessory/AccessoryFactory.d.ts +11 -11
  5. package/dist/accessory/AccessoryFactory.js +28 -28
  6. package/dist/accessory/AirConditionerAccessory.d.ts +86 -86
  7. package/dist/accessory/AirConditionerAccessory.d.ts.map +1 -1
  8. package/dist/accessory/AirConditionerAccessory.js +560 -561
  9. package/dist/accessory/AirConditionerAccessory.js.map +1 -1
  10. package/dist/accessory/BaseAccessory.d.ts +11 -11
  11. package/dist/accessory/BaseAccessory.js +21 -21
  12. package/dist/accessory/DehumidifierAccessory.d.ts +45 -45
  13. package/dist/accessory/DehumidifierAccessory.js +343 -343
  14. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -44
  15. package/dist/accessory/ElectricWaterHeaterAccessory.js +176 -176
  16. package/dist/accessory/FanAccessory.d.ts +39 -39
  17. package/dist/accessory/FanAccessory.js +123 -123
  18. package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -51
  19. package/dist/accessory/GasWaterHeaterAccessory.js +216 -216
  20. package/dist/core/MideaCloud.d.ts +35 -35
  21. package/dist/core/MideaCloud.js +350 -350
  22. package/dist/core/MideaConstants.d.ts +48 -48
  23. package/dist/core/MideaConstants.js +56 -56
  24. package/dist/core/MideaDevice.d.ts +76 -76
  25. package/dist/core/MideaDevice.js +409 -409
  26. package/dist/core/MideaDiscover.d.ts +35 -35
  27. package/dist/core/MideaDiscover.js +212 -212
  28. package/dist/core/MideaMessage.d.ts +75 -75
  29. package/dist/core/MideaMessage.js +184 -184
  30. package/dist/core/MideaPacketBuilder.d.ts +10 -10
  31. package/dist/core/MideaPacketBuilder.js +60 -60
  32. package/dist/core/MideaSecurity.d.ts +63 -63
  33. package/dist/core/MideaSecurity.js +242 -242
  34. package/dist/core/MideaUtils.d.ts +32 -32
  35. package/dist/core/MideaUtils.js +181 -181
  36. package/dist/devices/DeviceFactory.d.ts +11 -11
  37. package/dist/devices/DeviceFactory.js +30 -30
  38. package/dist/devices/a1/MideaA1Device.d.ts +76 -76
  39. package/dist/devices/a1/MideaA1Device.js +136 -136
  40. package/dist/devices/a1/MideaA1Message.d.ts +40 -40
  41. package/dist/devices/a1/MideaA1Message.js +198 -198
  42. package/dist/devices/ac/MideaACDevice.d.ts +100 -98
  43. package/dist/devices/ac/MideaACDevice.d.ts.map +1 -1
  44. package/dist/devices/ac/MideaACDevice.js +370 -357
  45. package/dist/devices/ac/MideaACDevice.js.map +1 -1
  46. package/dist/devices/ac/MideaACMessage.d.ts +92 -92
  47. package/dist/devices/ac/MideaACMessage.js +589 -589
  48. package/dist/devices/e2/MideaE2Device.d.ts +44 -44
  49. package/dist/devices/e2/MideaE2Device.js +119 -119
  50. package/dist/devices/e2/MideaE2Message.d.ts +33 -33
  51. package/dist/devices/e2/MideaE2Message.js +132 -132
  52. package/dist/devices/e3/MideaE3Device.d.ts +43 -43
  53. package/dist/devices/e3/MideaE3Device.js +125 -125
  54. package/dist/devices/e3/MideaE3Message.d.ts +51 -51
  55. package/dist/devices/e3/MideaE3Message.js +136 -136
  56. package/dist/devices/fa/MideaFADevice.d.ts +36 -36
  57. package/dist/devices/fa/MideaFADevice.js +92 -92
  58. package/dist/devices/fa/MideaFAMessage.d.ts +38 -38
  59. package/dist/devices/fa/MideaFAMessage.js +98 -98
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +6 -6
  62. package/dist/platform.d.ts +60 -60
  63. package/dist/platform.js +213 -213
  64. package/dist/platformUtils.d.ts +97 -96
  65. package/dist/platformUtils.d.ts.map +1 -1
  66. package/dist/platformUtils.js +95 -94
  67. package/dist/platformUtils.js.map +1 -1
  68. package/dist/settings.d.ts +8 -8
  69. package/dist/settings.js +11 -11
  70. package/docs/ac.md +2 -0
  71. package/docs/fa.md +3 -0
  72. package/package.json +1 -1
@@ -1,358 +1,371 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const MideaDevice_1 = __importDefault(require("../../core/MideaDevice"));
7
- const MideaACMessage_1 = require("./MideaACMessage");
8
- const platformUtils_1 = require("../../platformUtils");
9
- class MideaACDevice extends MideaDevice_1.default {
10
- /*********************************************************************
11
- * Constructor initializes all the attributes. We set some to invalid
12
- * values so that they are detected as "changed" on the first status
13
- * refresh... and passed back to the Homebridge/HomeKit accessory callback
14
- * function to set their initial values.
15
- */
16
- constructor(logger, device_info, config, deviceConfig) {
17
- super(logger, device_info, config, deviceConfig);
18
- this.FRESH_AIR_FAN_SPEEDS = {
19
- 0: 'Off',
20
- 20: 'Silent',
21
- 40: 'Low',
22
- 60: 'Medium',
23
- 80: 'High',
24
- 100: 'Full',
25
- };
26
- this.FRESH_AIR_FAN_SPEEDS_REVERSE = {
27
- 100: 'Full',
28
- 80: 'High',
29
- 60: 'Medium',
30
- 40: 'Low',
31
- 20: 'Silent',
32
- 0: 'Off',
33
- };
34
- this.used_subprotocol = false;
35
- this.bb_sn8_flag = false;
36
- this.bb_timer = false;
37
- this.DEFAULT_POWER_ANALYSIS_METHOD = 2;
38
- this.alternate_switch_display = false;
39
- this.last_fan_speed = 0;
40
- this.attributes = {
41
- PROMPT_TONE: false,
42
- POWER: undefined,
43
- MODE: 0,
44
- TARGET_TEMPERATURE: 0,
45
- FAN_SPEED: 0,
46
- FAN_AUTO: false,
47
- SWING_VERTICAL: undefined,
48
- WIND_SWING_UD_ANGLE: 0,
49
- SWING_HORIZONTAL: undefined,
50
- WIND_SWING_LR_ANGLE: 0,
51
- SMART_EYE: false,
52
- DRY: false,
53
- AUX_HEATING: false,
54
- BOOST_MODE: false,
55
- SLEEP_MODE: false,
56
- FROST_PROTECT: false,
57
- COMFORT_MODE: false,
58
- ECO_MODE: false,
59
- NATURAL_WIND: false,
60
- TEMP_FAHRENHEIT: false,
61
- SCREEN_DISPLAY: undefined,
62
- SCREEN_DISPLAY_NEW: false,
63
- FULL_DUST: false,
64
- INDOOR_TEMPERATURE: undefined,
65
- OUTDOOR_TEMPERATURE: undefined,
66
- INDIRECT_WIND: false,
67
- INDOOR_HUMIDITY: undefined,
68
- BREEZELESS: false,
69
- TOTAL_ENERGY_CONSUMPTION: undefined,
70
- CURRENT_ENERGY_CONSUMPTION: undefined,
71
- REALTIME_POWER: 0,
72
- FRESH_AIR_POWER: false,
73
- FRESH_AIR_FAN_SPEED: 0,
74
- FRESH_AIR_MODE: undefined,
75
- FRESH_AIR_1: false,
76
- FRESH_AIR_2: false,
77
- };
78
- }
79
- build_query() {
80
- if (this.used_subprotocol) {
81
- return [
82
- new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x10),
83
- new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x11),
84
- new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x30),
85
- ];
86
- }
87
- return [
88
- new MideaACMessage_1.MessageQuery(this.device_protocol_version),
89
- new MideaACMessage_1.MessageNewProtocolQuery(this.device_protocol_version, this.alternate_switch_display),
90
- new MideaACMessage_1.MessagePowerQuery(this.device_protocol_version),
91
- ];
92
- }
93
- process_message(msg) {
94
- const message = new MideaACMessage_1.MessageACResponse(msg, this.power_analysis_method);
95
- if (this.verbose) {
96
- this.logger.debug(`[${this.name}] Body:\n${JSON.stringify(message.body)}`);
97
- }
98
- const changed = {};
99
- let has_fresh_air = false;
100
- if (message.used_subprotocol) {
101
- this.used_subprotocol = true;
102
- if (message.get_body_attribute('sn8_flag')) {
103
- this.bb_sn8_flag = message.get_body_attribute('sn8_flag');
104
- }
105
- if (message.get_body_attribute('timer')) {
106
- this.bb_timer = message.get_body_attribute('timer');
107
- }
108
- }
109
- for (const status of Object.keys(this.attributes)) {
110
- const value = message.get_body_attribute(status.toLowerCase());
111
- if (value !== undefined) {
112
- if (this.attributes[status] !== value) {
113
- // Track only those attributes that change value. So when we send to the Homebridge /
114
- // HomeKit accessory we only update values that change. First time through this
115
- // should be most/all attributes having initialized them to invalid values.
116
- this.logger.debug(`[${this.name}] Value for ${status} changed from '${this.attributes[status]}' to '${value}'`);
117
- changed[status] = value;
118
- }
119
- this.attributes[status] = value;
120
- if (status === 'FRESH_AIR_POWER') {
121
- has_fresh_air = true;
122
- }
123
- }
124
- }
125
- // Following attributes do not have equivalents in Homebridge / Homekit accessory so
126
- // there is no need to track whether anything has changed.
127
- if (has_fresh_air) {
128
- if (this.attributes.FRESH_AIR_POWER) {
129
- for (const [k, v] of Object.entries(this.FRESH_AIR_FAN_SPEEDS_REVERSE)) {
130
- if (this.attributes.FRESH_AIR_FAN_SPEED > Number.parseInt(k)) {
131
- break;
132
- }
133
- else {
134
- this.attributes.FRESH_AIR_MODE = v;
135
- }
136
- }
137
- }
138
- else {
139
- this.attributes.FRESH_AIR_MODE = 'Off';
140
- }
141
- }
142
- if (!this.attributes.POWER || this.attributes.SWING_VERTICAL) {
143
- this.attributes.INDIRECT_WIND = false;
144
- }
145
- if (!this.attributes.POWER) {
146
- this.attributes.SCREEN_DISPLAY = false;
147
- }
148
- if (this.attributes.FRESH_AIR_1) {
149
- this.fresh_air_version = 1;
150
- }
151
- else if (this.attributes.FRESH_AIR_2) {
152
- this.fresh_air_version = 2;
153
- }
154
- // Now we update Homebridge / Homekit accessory
155
- if (Object.keys(changed).length > 0) {
156
- this.update(changed);
157
- }
158
- else {
159
- this.logger.debug(`[${this.name}] Status unchanged`);
160
- }
161
- }
162
- make_message_set() {
163
- const message = new MideaACMessage_1.MessageGeneralSet(this.device_protocol_version);
164
- message.power = !!this.attributes.POWER; // force to boolean
165
- message.prompt_tone = this.attributes.PROMPT_TONE;
166
- message.mode = this.attributes.MODE;
167
- message.target_temperature = this.attributes.TARGET_TEMPERATURE;
168
- message.fan_speed = this.attributes.FAN_SPEED;
169
- message.swing_vertical = !!this.attributes.SWING_VERTICAL; // force to boolean
170
- message.swing_horizontal = !!this.attributes.SWING_HORIZONTAL; // force to boolean
171
- message.boost_mode = this.attributes.BOOST_MODE;
172
- message.smart_eye = this.attributes.SMART_EYE;
173
- message.dry = this.attributes.DRY;
174
- message.eco_mode = this.attributes.ECO_MODE;
175
- message.aux_heating = this.attributes.AUX_HEATING;
176
- message.sleep_mode = this.attributes.SLEEP_MODE;
177
- message.frost_protect = this.attributes.FROST_PROTECT;
178
- message.comfort_mode = this.attributes.COMFORT_MODE;
179
- message.natural_wind = this.attributes.NATURAL_WIND;
180
- message.temp_fahrenheit = this.attributes.TEMP_FAHRENHEIT;
181
- return message;
182
- }
183
- make_subprotocol_message_set() {
184
- const message = new MideaACMessage_1.MessageSubProtocolSet(this.device_protocol_version);
185
- message.power = !!this.attributes.POWER; // force to boolean
186
- message.prompt_tone = this.attributes.PROMPT_TONE;
187
- message.aux_heating = this.attributes.AUX_HEATING;
188
- message.mode = this.attributes.MODE;
189
- message.target_temperature = this.attributes.TARGET_TEMPERATURE;
190
- message.fan_speed = this.attributes.FAN_SPEED;
191
- message.boost_mode = this.attributes.BOOST_MODE;
192
- message.dry = this.attributes.DRY;
193
- message.eco_mode = this.attributes.ECO_MODE;
194
- message.sleep_mode = this.attributes.SLEEP_MODE;
195
- message.sn8_flag = this.bb_sn8_flag;
196
- message.timer = this.bb_timer;
197
- return message;
198
- }
199
- make_message_unique_set() {
200
- return this.used_subprotocol ? this.make_subprotocol_message_set() : this.make_message_set();
201
- }
202
- async set_attribute(attributes) {
203
- try {
204
- for (const [k, v] of Object.entries(attributes)) {
205
- let message = undefined;
206
- this.logger.info(`[${this.name}] Set device attribute ${k} to: ${v}`);
207
- // not sensor data
208
- if (![
209
- 'INDOOR_TEMPERATURE',
210
- 'OUTDOOR_TEMPERATURE',
211
- 'INDOOR_HUMIDITY',
212
- 'FULL_DUST',
213
- 'TOTAL_ENERGY_CONSUMPTION',
214
- 'CURRENT_ENERGY_CONSUMPTION',
215
- 'REALTIME_POWER',
216
- ].includes(k)) {
217
- this.attributes[k] = v;
218
- if (k === 'PROMPT_TONE') {
219
- this.attributes.PROMPT_TONE = !!v;
220
- }
221
- else if (k === 'SCREEN_DISPLAY') {
222
- // if (this.attributes.SCREEN_DISPLAY_NEW)
223
- if (this.alternate_switch_display) {
224
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
225
- if (message instanceof MideaACMessage_1.MessageNewProtocolSet) {
226
- message.screen_display = !!v;
227
- message.prompt_tone = this.attributes.PROMPT_TONE;
228
- }
229
- }
230
- else {
231
- message = new MideaACMessage_1.MessageSwitchDisplay(this.device_protocol_version);
232
- }
233
- }
234
- else if (['INDIRECT_WIND', 'BREEZELESS'].includes(k)) {
235
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
236
- if (message instanceof MideaACMessage_1.MessageNewProtocolSet) {
237
- message[k.toLowerCase()] = !!v;
238
- message.prompt_tone = this.attributes.PROMPT_TONE;
239
- }
240
- }
241
- else if (k === 'FRESH_AIR_POWER') {
242
- if (this.fresh_air_version) {
243
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
244
- message[this.fresh_air_version] = [!!v, this.attributes.FRESH_AIR_FAN_SPEED];
245
- }
246
- }
247
- else if (k === 'FRESH_AIR_MODE' && this.fresh_air_version) {
248
- if (Object.values(this.FRESH_AIR_FAN_SPEEDS).includes(v)) {
249
- const speed = Number.parseInt(Object.keys(this.FRESH_AIR_FAN_SPEEDS).find((key) => this.FRESH_AIR_FAN_SPEEDS[key] === v));
250
- const fresh_air = speed > 0 ? [true, speed] : [false, this.attributes.FRESH_AIR_FAN_SPEED];
251
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
252
- message[this.fresh_air_version] = fresh_air;
253
- }
254
- else if (!v) {
255
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
256
- message[this.fresh_air_version] = [false, this.attributes.FRESH_AIR_FAN_SPEED];
257
- }
258
- }
259
- else if (k === 'FRESH_AIR_FAN_SPEED' && this.fresh_air_version) {
260
- message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
261
- const value = v;
262
- const fresh_air = value > 0 ? [true, value] : [false, this.attributes.FRESH_AIR_FAN_SPEED];
263
- message[this.fresh_air_version] = fresh_air;
264
- }
265
- else {
266
- message = this.make_message_unique_set();
267
- if (['BOOST_MODE', 'SLEEP_MODE', 'FROST_PROTECT', 'COMFORT_MODE', 'ECO_MODE'].includes(k)) {
268
- if (message instanceof MideaACMessage_1.MessageGeneralSet || message instanceof MideaACMessage_1.MessageSubProtocolSet) {
269
- message.sleep_mode = false;
270
- message.boost_mode = false;
271
- message.eco_mode = false;
272
- if (message instanceof MideaACMessage_1.MessageGeneralSet) {
273
- message.frost_protect = false;
274
- message.comfort_mode = false;
275
- }
276
- message[k.toLowerCase()] = !!v;
277
- if (k === 'MODE') {
278
- message.power = true;
279
- }
280
- }
281
- }
282
- }
283
- }
284
- if (message) {
285
- this.logger.debug(`[${this.name}] Set message:\n${JSON.stringify(message)}`);
286
- await this.build_send(message);
287
- }
288
- }
289
- }
290
- catch (err) {
291
- const msg = err instanceof Error ? err.stack : err;
292
- this.logger.debug(`[${this.name}] Error in set_attribute (${this.ip}:${this.port}):\n${msg}`);
293
- }
294
- }
295
- set_alternate_switch_display(value) {
296
- this.alternate_switch_display = value;
297
- }
298
- async set_target_temperature(target_temperature, mode) {
299
- this.logger.info(`[${this.name}] Set target temperature to: ${target_temperature}`);
300
- const message = this.make_message_unique_set();
301
- message.target_temperature = target_temperature;
302
- this.attributes.TARGET_TEMPERATURE = target_temperature;
303
- if (mode) {
304
- message.mode = mode;
305
- message.power = true;
306
- this.attributes.MODE = mode;
307
- this.attributes.POWER = true;
308
- }
309
- await this.build_send(message);
310
- }
311
- async set_swing(swing_horizontal, swing_vertical) {
312
- this.logger.info(`[${this.name}] Set swing horizontal to: ${swing_horizontal}, vertical to: ${swing_vertical}`);
313
- const message = this.make_message_set();
314
- message.swing_horizontal = swing_horizontal;
315
- message.swing_vertical = swing_vertical;
316
- this.attributes.SWING_HORIZONTAL = swing_horizontal;
317
- this.attributes.SWING_VERTICAL = swing_vertical;
318
- this.attributes.WIND_SWING_LR_ANGLE = 0;
319
- this.attributes.WIND_SWING_UD_ANGLE = 0;
320
- await this.build_send(message);
321
- }
322
- async set_fan_auto(fan_auto) {
323
- this.logger.info(`[${this.name}] Set fan auto to: ${fan_auto}`);
324
- const message = this.make_message_unique_set();
325
- if (fan_auto) {
326
- // Save last fan speed before setting to auto
327
- this.last_fan_speed = this.attributes.FAN_SPEED;
328
- }
329
- const fan_speed = fan_auto ? 102 : this.last_fan_speed;
330
- message.fan_speed = fan_speed;
331
- this.attributes.FAN_SPEED = fan_speed;
332
- this.attributes.FAN_AUTO = fan_auto;
333
- await this.build_send(message);
334
- }
335
- async set_swing_angle(swing_direction, swing_angle) {
336
- this.logger.info(`[${this.name}] Set swing ${swing_direction} angle to: ${swing_angle}`);
337
- const message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
338
- this.attributes.SWING_HORIZONTAL = false;
339
- this.attributes.SWING_VERTICAL = false;
340
- switch (swing_direction) {
341
- case platformUtils_1.SwingAngle.HORIZONTAL:
342
- message.wind_swing_lr_angle = swing_angle;
343
- this.attributes.WIND_SWING_LR_ANGLE = swing_angle;
344
- break;
345
- case platformUtils_1.SwingAngle.VERTICAL:
346
- message.wind_swing_ud_angle = swing_angle;
347
- this.attributes.WIND_SWING_UD_ANGLE = swing_angle;
348
- break;
349
- }
350
- message.prompt_tone = this.attributes.PROMPT_TONE;
351
- await this.build_send(message);
352
- }
353
- set_subtype() {
354
- this.logger.debug('No subtype for AC device');
355
- }
356
- }
357
- exports.default = MideaACDevice;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const MideaDevice_1 = __importDefault(require("../../core/MideaDevice"));
7
+ const MideaACMessage_1 = require("./MideaACMessage");
8
+ const platformUtils_1 = require("../../platformUtils");
9
+ class MideaACDevice extends MideaDevice_1.default {
10
+ /*********************************************************************
11
+ * Constructor initializes all the attributes. We set some to invalid
12
+ * values so that they are detected as "changed" on the first status
13
+ * refresh... and passed back to the Homebridge/HomeKit accessory callback
14
+ * function to set their initial values.
15
+ */
16
+ constructor(logger, device_info, config, deviceConfig) {
17
+ super(logger, device_info, config, deviceConfig);
18
+ this.FRESH_AIR_FAN_SPEEDS = {
19
+ 0: 'Off',
20
+ 20: 'Silent',
21
+ 40: 'Low',
22
+ 60: 'Medium',
23
+ 80: 'High',
24
+ 100: 'Full',
25
+ };
26
+ this.FRESH_AIR_FAN_SPEEDS_REVERSE = {
27
+ 100: 'Full',
28
+ 80: 'High',
29
+ 60: 'Medium',
30
+ 40: 'Low',
31
+ 20: 'Silent',
32
+ 0: 'Off',
33
+ };
34
+ this.used_subprotocol = false;
35
+ this.bb_sn8_flag = false;
36
+ this.bb_timer = false;
37
+ this.DEFAULT_POWER_ANALYSIS_METHOD = 2;
38
+ this.alternate_switch_display = false;
39
+ this.last_fan_speed = 0;
40
+ this.attributes = {
41
+ PROMPT_TONE: false,
42
+ POWER: undefined,
43
+ MODE: 0,
44
+ TARGET_TEMPERATURE: 0,
45
+ FAN_SPEED: 0,
46
+ FAN_AUTO: false,
47
+ SWING_VERTICAL: undefined,
48
+ WIND_SWING_UD_ANGLE: 0,
49
+ SWING_HORIZONTAL: undefined,
50
+ WIND_SWING_LR_ANGLE: 0,
51
+ SMART_EYE: false,
52
+ DRY: false,
53
+ AUX_HEATING: false,
54
+ BOOST_MODE: false,
55
+ SLEEP_MODE: false,
56
+ FROST_PROTECT: false,
57
+ COMFORT_MODE: false,
58
+ ECO_MODE: false,
59
+ NATURAL_WIND: false,
60
+ TEMP_FAHRENHEIT: false,
61
+ SCREEN_DISPLAY: undefined,
62
+ SCREEN_DISPLAY_NEW: false,
63
+ FULL_DUST: false,
64
+ INDOOR_TEMPERATURE: undefined,
65
+ OUTDOOR_TEMPERATURE: undefined,
66
+ INDIRECT_WIND: false,
67
+ INDOOR_HUMIDITY: undefined,
68
+ BREEZELESS: false,
69
+ TOTAL_ENERGY_CONSUMPTION: undefined,
70
+ CURRENT_ENERGY_CONSUMPTION: undefined,
71
+ REALTIME_POWER: 0,
72
+ FRESH_AIR_POWER: false,
73
+ FRESH_AIR_FAN_SPEED: 0,
74
+ FRESH_AIR_MODE: undefined,
75
+ FRESH_AIR_1: false,
76
+ FRESH_AIR_2: false,
77
+ };
78
+ this.defaultFahrenheit = deviceConfig.AC_options.fahrenheit;
79
+ this.defaultScreenOff = deviceConfig.AC_options.screenOff;
80
+ }
81
+ build_query() {
82
+ if (this.used_subprotocol) {
83
+ return [
84
+ new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x10),
85
+ new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x11),
86
+ new MideaACMessage_1.MessageSubProtocolQuery(this.device_protocol_version, 0x30),
87
+ ];
88
+ }
89
+ return [
90
+ new MideaACMessage_1.MessageQuery(this.device_protocol_version),
91
+ new MideaACMessage_1.MessageNewProtocolQuery(this.device_protocol_version, this.alternate_switch_display),
92
+ new MideaACMessage_1.MessagePowerQuery(this.device_protocol_version),
93
+ ];
94
+ }
95
+ process_message(msg) {
96
+ const message = new MideaACMessage_1.MessageACResponse(msg, this.power_analysis_method);
97
+ if (this.verbose) {
98
+ this.logger.debug(`[${this.name}] Body:\n${JSON.stringify(message.body)}`);
99
+ }
100
+ const changed = {};
101
+ let has_fresh_air = false;
102
+ if (message.used_subprotocol) {
103
+ this.used_subprotocol = true;
104
+ if (message.get_body_attribute('sn8_flag')) {
105
+ this.bb_sn8_flag = message.get_body_attribute('sn8_flag');
106
+ }
107
+ if (message.get_body_attribute('timer')) {
108
+ this.bb_timer = message.get_body_attribute('timer');
109
+ }
110
+ }
111
+ for (const status of Object.keys(this.attributes)) {
112
+ const value = message.get_body_attribute(status.toLowerCase());
113
+ if (value !== undefined) {
114
+ if (this.attributes[status] !== value) {
115
+ // Track only those attributes that change value. So when we send to the Homebridge /
116
+ // HomeKit accessory we only update values that change. First time through this
117
+ // should be most/all attributes having initialized them to invalid values.
118
+ this.logger.debug(`[${this.name}] Value for ${status} changed from '${this.attributes[status]}' to '${value}'`);
119
+ changed[status] = value;
120
+ }
121
+ this.attributes[status] = value;
122
+ if (status === 'FRESH_AIR_POWER') {
123
+ has_fresh_air = true;
124
+ }
125
+ }
126
+ }
127
+ // Following attributes do not have equivalents in Homebridge / Homekit accessory so
128
+ // there is no need to track whether anything has changed.
129
+ if (has_fresh_air) {
130
+ if (this.attributes.FRESH_AIR_POWER) {
131
+ for (const [k, v] of Object.entries(this.FRESH_AIR_FAN_SPEEDS_REVERSE)) {
132
+ if (this.attributes.FRESH_AIR_FAN_SPEED > Number.parseInt(k)) {
133
+ break;
134
+ }
135
+ else {
136
+ this.attributes.FRESH_AIR_MODE = v;
137
+ }
138
+ }
139
+ }
140
+ else {
141
+ this.attributes.FRESH_AIR_MODE = 'Off';
142
+ }
143
+ }
144
+ if (!this.attributes.POWER || this.attributes.SWING_VERTICAL) {
145
+ this.attributes.INDIRECT_WIND = false;
146
+ }
147
+ if (!this.attributes.POWER) {
148
+ this.attributes.SCREEN_DISPLAY = false;
149
+ }
150
+ if (this.attributes.FRESH_AIR_1) {
151
+ this.fresh_air_version = 1;
152
+ }
153
+ else if (this.attributes.FRESH_AIR_2) {
154
+ this.fresh_air_version = 2;
155
+ }
156
+ // Now we update Homebridge / Homekit accessory
157
+ if (Object.keys(changed).length > 0) {
158
+ this.update(changed);
159
+ }
160
+ else {
161
+ this.logger.debug(`[${this.name}] Status unchanged`);
162
+ }
163
+ }
164
+ make_message_set() {
165
+ const message = new MideaACMessage_1.MessageGeneralSet(this.device_protocol_version);
166
+ message.power = !!this.attributes.POWER; // force to boolean
167
+ message.prompt_tone = this.attributes.PROMPT_TONE;
168
+ message.mode = this.attributes.MODE;
169
+ message.target_temperature = this.attributes.TARGET_TEMPERATURE;
170
+ message.fan_speed = this.attributes.FAN_SPEED;
171
+ message.swing_vertical = !!this.attributes.SWING_VERTICAL; // force to boolean
172
+ message.swing_horizontal = !!this.attributes.SWING_HORIZONTAL; // force to boolean
173
+ message.boost_mode = this.attributes.BOOST_MODE;
174
+ message.smart_eye = this.attributes.SMART_EYE;
175
+ message.dry = this.attributes.DRY;
176
+ message.eco_mode = this.attributes.ECO_MODE;
177
+ message.aux_heating = this.attributes.AUX_HEATING;
178
+ message.sleep_mode = this.attributes.SLEEP_MODE;
179
+ message.frost_protect = this.attributes.FROST_PROTECT;
180
+ message.comfort_mode = this.attributes.COMFORT_MODE;
181
+ message.natural_wind = this.attributes.NATURAL_WIND;
182
+ message.temp_fahrenheit = this.attributes.TEMP_FAHRENHEIT;
183
+ return message;
184
+ }
185
+ make_subprotocol_message_set() {
186
+ const message = new MideaACMessage_1.MessageSubProtocolSet(this.device_protocol_version);
187
+ message.power = !!this.attributes.POWER; // force to boolean
188
+ message.prompt_tone = this.attributes.PROMPT_TONE;
189
+ message.aux_heating = this.attributes.AUX_HEATING;
190
+ message.mode = this.attributes.MODE;
191
+ message.target_temperature = this.attributes.TARGET_TEMPERATURE;
192
+ message.fan_speed = this.attributes.FAN_SPEED;
193
+ message.boost_mode = this.attributes.BOOST_MODE;
194
+ message.dry = this.attributes.DRY;
195
+ message.eco_mode = this.attributes.ECO_MODE;
196
+ message.sleep_mode = this.attributes.SLEEP_MODE;
197
+ message.sn8_flag = this.bb_sn8_flag;
198
+ message.timer = this.bb_timer;
199
+ return message;
200
+ }
201
+ make_message_unique_set() {
202
+ return this.used_subprotocol ? this.make_subprotocol_message_set() : this.make_message_set();
203
+ }
204
+ async set_attribute(attributes) {
205
+ let sendScreenCommand = false;
206
+ try {
207
+ for (const [k, v] of Object.entries(attributes)) {
208
+ let message = undefined;
209
+ this.logger.info(`[${this.name}] Set device attribute ${k} to: ${v}`);
210
+ // not sensor data
211
+ if (![
212
+ 'INDOOR_TEMPERATURE',
213
+ 'OUTDOOR_TEMPERATURE',
214
+ 'INDOOR_HUMIDITY',
215
+ 'FULL_DUST',
216
+ 'TOTAL_ENERGY_CONSUMPTION',
217
+ 'CURRENT_ENERGY_CONSUMPTION',
218
+ 'REALTIME_POWER',
219
+ ].includes(k)) {
220
+ this.attributes[k] = v;
221
+ if (k === 'PROMPT_TONE') {
222
+ this.attributes.PROMPT_TONE = !!v;
223
+ }
224
+ else if (k === 'SCREEN_DISPLAY') {
225
+ // if (this.attributes.SCREEN_DISPLAY_NEW)
226
+ if (this.alternate_switch_display) {
227
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
228
+ if (message instanceof MideaACMessage_1.MessageNewProtocolSet) {
229
+ message.screen_display = !!v;
230
+ message.prompt_tone = this.attributes.PROMPT_TONE;
231
+ }
232
+ }
233
+ else {
234
+ message = new MideaACMessage_1.MessageSwitchDisplay(this.device_protocol_version);
235
+ }
236
+ }
237
+ else if (['INDIRECT_WIND', 'BREEZELESS'].includes(k)) {
238
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
239
+ if (message instanceof MideaACMessage_1.MessageNewProtocolSet) {
240
+ message[k.toLowerCase()] = !!v;
241
+ message.prompt_tone = this.attributes.PROMPT_TONE;
242
+ }
243
+ }
244
+ else if (k === 'FRESH_AIR_POWER') {
245
+ if (this.fresh_air_version) {
246
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
247
+ message[this.fresh_air_version] = [!!v, this.attributes.FRESH_AIR_FAN_SPEED];
248
+ }
249
+ }
250
+ else if (k === 'FRESH_AIR_MODE' && this.fresh_air_version) {
251
+ if (Object.values(this.FRESH_AIR_FAN_SPEEDS).includes(v)) {
252
+ const speed = Number.parseInt(Object.keys(this.FRESH_AIR_FAN_SPEEDS).find((key) => this.FRESH_AIR_FAN_SPEEDS[key] === v));
253
+ const fresh_air = speed > 0 ? [true, speed] : [false, this.attributes.FRESH_AIR_FAN_SPEED];
254
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
255
+ message[this.fresh_air_version] = fresh_air;
256
+ }
257
+ else if (!v) {
258
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
259
+ message[this.fresh_air_version] = [false, this.attributes.FRESH_AIR_FAN_SPEED];
260
+ }
261
+ }
262
+ else if (k === 'FRESH_AIR_FAN_SPEED' && this.fresh_air_version) {
263
+ message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
264
+ const value = v;
265
+ const fresh_air = value > 0 ? [true, value] : [false, this.attributes.FRESH_AIR_FAN_SPEED];
266
+ message[this.fresh_air_version] = fresh_air;
267
+ }
268
+ else {
269
+ message = this.make_message_unique_set();
270
+ if (['BOOST_MODE', 'SLEEP_MODE', 'FROST_PROTECT', 'COMFORT_MODE', 'ECO_MODE'].includes(k)) {
271
+ if (message instanceof MideaACMessage_1.MessageGeneralSet || message instanceof MideaACMessage_1.MessageSubProtocolSet) {
272
+ message.sleep_mode = false;
273
+ message.boost_mode = false;
274
+ message.eco_mode = false;
275
+ if (message instanceof MideaACMessage_1.MessageGeneralSet) {
276
+ message.frost_protect = false;
277
+ message.comfort_mode = false;
278
+ }
279
+ message[k.toLowerCase()] = !!v;
280
+ if (k === 'MODE') {
281
+ message.power = true;
282
+ }
283
+ }
284
+ }
285
+ if (k === 'POWER' && v === true && message instanceof MideaACMessage_1.MessageGeneralSet) {
286
+ message.temp_fahrenheit = this.defaultFahrenheit;
287
+ this.attributes.TEMP_FAHRENHEIT = this.defaultFahrenheit;
288
+ if (this.defaultScreenOff) {
289
+ sendScreenCommand = true;
290
+ }
291
+ }
292
+ }
293
+ }
294
+ if (message) {
295
+ this.logger.debug(`[${this.name}] Set message:\n${JSON.stringify(message)}`);
296
+ await this.build_send(message);
297
+ if (sendScreenCommand) {
298
+ await this.build_send(new MideaACMessage_1.MessageSwitchDisplay(this.device_protocol_version));
299
+ }
300
+ }
301
+ }
302
+ }
303
+ catch (err) {
304
+ const msg = err instanceof Error ? err.stack : err;
305
+ this.logger.debug(`[${this.name}] Error in set_attribute (${this.ip}:${this.port}):\n${msg}`);
306
+ }
307
+ }
308
+ set_alternate_switch_display(value) {
309
+ this.alternate_switch_display = value;
310
+ }
311
+ async set_target_temperature(target_temperature, mode) {
312
+ this.logger.info(`[${this.name}] Set target temperature to: ${target_temperature}`);
313
+ const message = this.make_message_unique_set();
314
+ message.target_temperature = target_temperature;
315
+ this.attributes.TARGET_TEMPERATURE = target_temperature;
316
+ if (mode) {
317
+ message.mode = mode;
318
+ message.power = true;
319
+ this.attributes.MODE = mode;
320
+ this.attributes.POWER = true;
321
+ }
322
+ await this.build_send(message);
323
+ }
324
+ async set_swing(swing_horizontal, swing_vertical) {
325
+ this.logger.info(`[${this.name}] Set swing horizontal to: ${swing_horizontal}, vertical to: ${swing_vertical}`);
326
+ const message = this.make_message_set();
327
+ message.swing_horizontal = swing_horizontal;
328
+ message.swing_vertical = swing_vertical;
329
+ this.attributes.SWING_HORIZONTAL = swing_horizontal;
330
+ this.attributes.SWING_VERTICAL = swing_vertical;
331
+ this.attributes.WIND_SWING_LR_ANGLE = 0;
332
+ this.attributes.WIND_SWING_UD_ANGLE = 0;
333
+ await this.build_send(message);
334
+ }
335
+ async set_fan_auto(fan_auto) {
336
+ this.logger.info(`[${this.name}] Set fan auto to: ${fan_auto}`);
337
+ const message = this.make_message_unique_set();
338
+ if (fan_auto) {
339
+ // Save last fan speed before setting to auto
340
+ this.last_fan_speed = this.attributes.FAN_SPEED;
341
+ }
342
+ const fan_speed = fan_auto ? 102 : this.last_fan_speed;
343
+ message.fan_speed = fan_speed;
344
+ this.attributes.FAN_SPEED = fan_speed;
345
+ this.attributes.FAN_AUTO = fan_auto;
346
+ await this.build_send(message);
347
+ }
348
+ async set_swing_angle(swing_direction, swing_angle) {
349
+ this.logger.info(`[${this.name}] Set swing ${swing_direction} angle to: ${swing_angle}`);
350
+ const message = new MideaACMessage_1.MessageNewProtocolSet(this.device_protocol_version);
351
+ this.attributes.SWING_HORIZONTAL = false;
352
+ this.attributes.SWING_VERTICAL = false;
353
+ switch (swing_direction) {
354
+ case platformUtils_1.SwingAngle.HORIZONTAL:
355
+ message.wind_swing_lr_angle = swing_angle;
356
+ this.attributes.WIND_SWING_LR_ANGLE = swing_angle;
357
+ break;
358
+ case platformUtils_1.SwingAngle.VERTICAL:
359
+ message.wind_swing_ud_angle = swing_angle;
360
+ this.attributes.WIND_SWING_UD_ANGLE = swing_angle;
361
+ break;
362
+ }
363
+ message.prompt_tone = this.attributes.PROMPT_TONE;
364
+ await this.build_send(message);
365
+ }
366
+ set_subtype() {
367
+ this.logger.debug('No subtype for AC device');
368
+ }
369
+ }
370
+ exports.default = MideaACDevice;
358
371
  //# sourceMappingURL=MideaACDevice.js.map