homebridge-midea-platform 1.1.2-beta.9 → 1.2.0-beta.2

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