homebridge-midea-platform 1.2.0-beta.1 → 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 (94) hide show
  1. package/.husky/pre-commit +0 -0
  2. package/config.schema.json +6 -0
  3. package/dist/accessory/AccessoryFactory.d.ts +12 -12
  4. package/dist/accessory/AccessoryFactory.js +31 -31
  5. package/dist/accessory/AirConditionerAccessory.d.ts +92 -89
  6. package/dist/accessory/AirConditionerAccessory.d.ts.map +1 -1
  7. package/dist/accessory/AirConditionerAccessory.js +607 -584
  8. package/dist/accessory/AirConditionerAccessory.js.map +1 -1
  9. package/dist/accessory/BaseAccessory.d.ts +11 -11
  10. package/dist/accessory/BaseAccessory.js +21 -21
  11. package/dist/accessory/DehumidifierAccessory.d.ts +45 -45
  12. package/dist/accessory/DehumidifierAccessory.js +344 -344
  13. package/dist/accessory/DishwasherAccessory.d.ts +30 -28
  14. package/dist/accessory/DishwasherAccessory.d.ts.map +1 -1
  15. package/dist/accessory/DishwasherAccessory.js +63 -62
  16. package/dist/accessory/DishwasherAccessory.js.map +1 -1
  17. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -44
  18. package/dist/accessory/ElectricWaterHeaterAccessory.js +176 -176
  19. package/dist/accessory/FanAccessory.d.ts +39 -39
  20. package/dist/accessory/FanAccessory.js +123 -123
  21. package/dist/accessory/FrontLoadWasherAccessory.d.ts +30 -30
  22. package/dist/accessory/FrontLoadWasherAccessory.d.ts.map +1 -1
  23. package/dist/accessory/FrontLoadWasherAccessory.js +66 -60
  24. package/dist/accessory/FrontLoadWasherAccessory.js.map +1 -1
  25. package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -51
  26. package/dist/accessory/GasWaterHeaterAccessory.js +216 -216
  27. package/dist/core/MideaCloud.d.ts +35 -35
  28. package/dist/core/MideaCloud.js +350 -350
  29. package/dist/core/MideaConstants.d.ts +50 -50
  30. package/dist/core/MideaConstants.js +58 -58
  31. package/dist/core/MideaDevice.d.ts +76 -76
  32. package/dist/core/MideaDevice.js +409 -409
  33. package/dist/core/MideaDiscover.d.ts +35 -35
  34. package/dist/core/MideaDiscover.js +212 -212
  35. package/dist/core/MideaMessage.d.ts +75 -75
  36. package/dist/core/MideaMessage.js +184 -184
  37. package/dist/core/MideaPacketBuilder.d.ts +10 -10
  38. package/dist/core/MideaPacketBuilder.js +60 -60
  39. package/dist/core/MideaSecurity.d.ts +63 -63
  40. package/dist/core/MideaSecurity.js +251 -251
  41. package/dist/core/MideaUtils.d.ts +32 -32
  42. package/dist/core/MideaUtils.js +181 -181
  43. package/dist/devices/DeviceFactory.d.ts +13 -13
  44. package/dist/devices/DeviceFactory.js +36 -36
  45. package/dist/devices/a1/MideaA1Device.d.ts +76 -76
  46. package/dist/devices/a1/MideaA1Device.js +145 -145
  47. package/dist/devices/a1/MideaA1Device.js.map +1 -1
  48. package/dist/devices/a1/MideaA1Message.d.ts +40 -40
  49. package/dist/devices/a1/MideaA1Message.js +198 -198
  50. package/dist/devices/ac/MideaACDevice.d.ts +104 -100
  51. package/dist/devices/ac/MideaACDevice.d.ts.map +1 -1
  52. package/dist/devices/ac/MideaACDevice.js +384 -367
  53. package/dist/devices/ac/MideaACDevice.js.map +1 -1
  54. package/dist/devices/ac/MideaACMessage.d.ts +94 -92
  55. package/dist/devices/ac/MideaACMessage.d.ts.map +1 -1
  56. package/dist/devices/ac/MideaACMessage.js +611 -589
  57. package/dist/devices/ac/MideaACMessage.js.map +1 -1
  58. package/dist/devices/db/MideaDBDevice.d.ts +29 -29
  59. package/dist/devices/db/MideaDBDevice.js +100 -100
  60. package/dist/devices/db/MideaDBDevice.js.map +1 -1
  61. package/dist/devices/db/MideaDBMessage.d.ts +32 -32
  62. package/dist/devices/db/MideaDBMessage.js +101 -101
  63. package/dist/devices/e1/MideaE1Device.d.ts +56 -56
  64. package/dist/devices/e1/MideaE1Device.js +128 -128
  65. package/dist/devices/e1/MideaE1Device.js.map +1 -1
  66. package/dist/devices/e1/MideaE1Message.d.ts +28 -28
  67. package/dist/devices/e1/MideaE1Message.js +107 -107
  68. package/dist/devices/e2/MideaE2Device.d.ts +44 -44
  69. package/dist/devices/e2/MideaE2Device.js +129 -129
  70. package/dist/devices/e2/MideaE2Device.js.map +1 -1
  71. package/dist/devices/e2/MideaE2Message.d.ts +33 -33
  72. package/dist/devices/e2/MideaE2Message.js +132 -132
  73. package/dist/devices/e3/MideaE3Device.d.ts +43 -43
  74. package/dist/devices/e3/MideaE3Device.js +137 -137
  75. package/dist/devices/e3/MideaE3Device.js.map +1 -1
  76. package/dist/devices/e3/MideaE3Message.d.ts +51 -51
  77. package/dist/devices/e3/MideaE3Message.js +136 -136
  78. package/dist/devices/fa/MideaFADevice.d.ts +36 -36
  79. package/dist/devices/fa/MideaFADevice.js +106 -106
  80. package/dist/devices/fa/MideaFADevice.js.map +1 -1
  81. package/dist/devices/fa/MideaFAMessage.d.ts +38 -38
  82. package/dist/devices/fa/MideaFAMessage.js +98 -98
  83. package/dist/index.d.ts +6 -6
  84. package/dist/index.js +6 -6
  85. package/dist/platform.d.ts +60 -60
  86. package/dist/platform.js +212 -212
  87. package/dist/platformUtils.d.ts +106 -105
  88. package/dist/platformUtils.d.ts.map +1 -1
  89. package/dist/platformUtils.js +101 -100
  90. package/dist/platformUtils.js.map +1 -1
  91. package/dist/settings.d.ts +8 -8
  92. package/dist/settings.js +11 -11
  93. package/package.json +1 -1
  94. package/AC_ori.lua +0 -5150
@@ -1,590 +1,612 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageACResponse = exports.MessageNewProtocolSet = exports.MessageGeneralSet = exports.MessageSubProtocolSet = exports.MessageSubProtocolQuery = exports.MessageSubProtocol = exports.MessageNewProtocolQuery = exports.MessageSwitchDisplay = exports.MessagePowerQuery = exports.MessageQuery = void 0;
4
- /***********************************************************************
5
- * Midea Air Conditioner Device message handler class
6
- *
7
- * Copyright (c) 2023 Kovalovszky Patrik, https://github.com/kovapatrik
8
- *
9
- * With thanks to https://github.com/georgezhao2010/midea_ac_lan
10
- *
11
- */
12
- const MideaConstants_1 = require("../../core/MideaConstants");
13
- const MideaMessage_1 = require("../../core/MideaMessage");
14
- const MideaUtils_1 = require("../../core/MideaUtils");
15
- var NewProtocolTags;
16
- (function (NewProtocolTags) {
17
- NewProtocolTags[NewProtocolTags["WIND_SWING_UD_ANGLE"] = 9] = "WIND_SWING_UD_ANGLE";
18
- NewProtocolTags[NewProtocolTags["WIND_SWING_LR_ANGLE"] = 10] = "WIND_SWING_LR_ANGLE";
19
- NewProtocolTags[NewProtocolTags["INDOOR_HUMIDITY"] = 21] = "INDOOR_HUMIDITY";
20
- NewProtocolTags[NewProtocolTags["SCREEN_DISPLAY"] = 23] = "SCREEN_DISPLAY";
21
- NewProtocolTags[NewProtocolTags["BREEZELESS"] = 24] = "BREEZELESS";
22
- NewProtocolTags[NewProtocolTags["PROMPT_TONE"] = 26] = "PROMPT_TONE";
23
- NewProtocolTags[NewProtocolTags["INDIRECT_WIND"] = 66] = "INDIRECT_WIND";
24
- NewProtocolTags[NewProtocolTags["FRESH_AIR_1"] = 563] = "FRESH_AIR_1";
25
- NewProtocolTags[NewProtocolTags["FRESH_AIR_2"] = 75] = "FRESH_AIR_2";
26
- })(NewProtocolTags || (NewProtocolTags = {}));
27
- const BB_AC_MODES = [0, 3, 1, 2, 4, 5];
28
- class MessageACBase extends MideaMessage_1.MessageRequest {
29
- constructor(device_protocol_version, message_type, body_type) {
30
- super(MideaConstants_1.DeviceType.AIR_CONDITIONER, message_type, body_type, device_protocol_version);
31
- MessageACBase.message_serial += 1;
32
- if (MessageACBase.message_serial >= 254) {
33
- MessageACBase.message_serial = 1;
34
- }
35
- this.message_id = MessageACBase.message_serial;
36
- }
37
- get body() {
38
- let body = Buffer.concat([Buffer.from([this.body_type]), this._body, Buffer.from([this.message_id])]);
39
- body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
40
- return body;
41
- }
42
- }
43
- MessageACBase.message_serial = 0;
44
- class MessageQuery extends MessageACBase {
45
- constructor(device_protocol_version) {
46
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
47
- }
48
- get _body() {
49
- return Buffer.from([0x81, 0x00, 0xff, 0x03, 0xff, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
50
- }
51
- }
52
- exports.MessageQuery = MessageQuery;
53
- class MessagePowerQuery extends MessageACBase {
54
- constructor(device_protocol_version) {
55
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
56
- }
57
- get _body() {
58
- return Buffer.from([0x21, 0x01, 0x44, 0x00, 0x01]);
59
- }
60
- get body() {
61
- let body = Buffer.concat([Buffer.from([this.body_type]), this._body]);
62
- body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
63
- return body;
64
- }
65
- }
66
- exports.MessagePowerQuery = MessagePowerQuery;
67
- class MessageSwitchDisplay extends MessageACBase {
68
- constructor(device_protocol_version) {
69
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
70
- }
71
- get _body() {
72
- return Buffer.from([0x81, 0x00, 0xff, 0x02, 0xff, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
73
- }
74
- }
75
- exports.MessageSwitchDisplay = MessageSwitchDisplay;
76
- class MessageNewProtocolQuery extends MessageACBase {
77
- constructor(device_protocol_version, alternate_display = false) {
78
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0xb1);
79
- this.alternate_display = alternate_display;
80
- }
81
- get _body() {
82
- const query_params = [
83
- NewProtocolTags.WIND_SWING_UD_ANGLE,
84
- NewProtocolTags.WIND_SWING_LR_ANGLE,
85
- NewProtocolTags.INDIRECT_WIND,
86
- NewProtocolTags.BREEZELESS,
87
- NewProtocolTags.INDOOR_HUMIDITY,
88
- this.alternate_display ? NewProtocolTags.SCREEN_DISPLAY : undefined,
89
- NewProtocolTags.FRESH_AIR_1,
90
- NewProtocolTags.FRESH_AIR_2,
91
- ];
92
- let body = Buffer.from([query_params.length]);
93
- for (const param of query_params) {
94
- if (param) {
95
- body = Buffer.concat([body, Buffer.from([param & 0xff, param >> 8])]);
96
- }
97
- }
98
- return body;
99
- }
100
- }
101
- exports.MessageNewProtocolQuery = MessageNewProtocolQuery;
102
- class MessageSubProtocol extends MessageACBase {
103
- constructor(device_protocol_version, message_type, subprotocol_query_type) {
104
- super(device_protocol_version, message_type, 0xaa);
105
- this.subprotocol_query_type = subprotocol_query_type;
106
- }
107
- get body() {
108
- let body = Buffer.concat([Buffer.from([this.body_type]), this._body]);
109
- body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
110
- body = Buffer.concat([body, Buffer.from([this.checksum(body)])]);
111
- return body;
112
- }
113
- get _body() {
114
- let body = Buffer.from([
115
- 6 + 2 + (this.subprotocol_body ? this.subprotocol_body.length : 0),
116
- 0x00,
117
- 0xff,
118
- 0xff,
119
- this.subprotocol_query_type,
120
- ]);
121
- if (this.subprotocol_body) {
122
- body = Buffer.concat([body, this.subprotocol_body]);
123
- }
124
- return body;
125
- }
126
- }
127
- exports.MessageSubProtocol = MessageSubProtocol;
128
- class MessageSubProtocolQuery extends MessageSubProtocol {
129
- constructor(device_protocol_version, subprotocol_query_type) {
130
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, subprotocol_query_type);
131
- }
132
- }
133
- exports.MessageSubProtocolQuery = MessageSubProtocolQuery;
134
- class MessageSubProtocolSet extends MessageSubProtocol {
135
- constructor(device_protocol_version) {
136
- super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x20);
137
- this.power = false;
138
- this.mode = 0;
139
- this.target_temperature = 20.0;
140
- this.fan_speed = 102;
141
- this.boost_mode = false;
142
- this.aux_heating = false;
143
- this.dry = false;
144
- this.eco_mode = false;
145
- this.sleep_mode = false;
146
- this.sn8_flag = false;
147
- this.timer = false;
148
- this.prompt_tone = false;
149
- }
150
- get subprotocol_body() {
151
- const power = this.power ? 0x01 : 0x00;
152
- const dry = this.dry && this.power ? 0x10 : 0;
153
- const boost_mode = this.boost_mode ? 0x20 : 0;
154
- const aux_heating = this.aux_heating ? 0x40 : 0;
155
- const sleep_mode = this.sleep_mode ? 0x80 : 0;
156
- const mode = this.mode === 0 ? 0 : this.mode < BB_AC_MODES.length ? BB_AC_MODES[this.mode] - 1 : 2;
157
- const target_temperature = (this.target_temperature * 2 + 30) | 0;
158
- const water_model_temperature_set = ((this.target_temperature - 1) * 2 + 50) | 0;
159
- const fan_speed = this.fan_speed;
160
- const eco = this.eco_mode ? 0x40 : 0;
161
- const prompt_tone = this.prompt_tone ? 0x01 : 0;
162
- const timer = this.sn8_flag && this.timer ? 0x04 : 0;
163
- return Buffer.from([
164
- boost_mode | power | dry,
165
- aux_heating,
166
- sleep_mode,
167
- 0x00,
168
- 0x00,
169
- mode,
170
- target_temperature,
171
- fan_speed,
172
- 0x32,
173
- 0x00,
174
- 0x00,
175
- 0x00,
176
- 0x00,
177
- 0x00,
178
- 0x00,
179
- 0x01,
180
- 0x01,
181
- 0x00,
182
- 0x01,
183
- water_model_temperature_set,
184
- prompt_tone,
185
- target_temperature,
186
- 0x32,
187
- 0x66,
188
- 0x00,
189
- eco | timer,
190
- 0x00,
191
- 0x00,
192
- 0x00,
193
- 0x00,
194
- 0x00,
195
- 0x00,
196
- 0x00,
197
- 0x00,
198
- 0x00,
199
- 0x00,
200
- 0x08,
201
- ]);
202
- }
203
- }
204
- exports.MessageSubProtocolSet = MessageSubProtocolSet;
205
- class MessageGeneralSet extends MessageACBase {
206
- constructor(device_protocol_version) {
207
- super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x40);
208
- this.power = false;
209
- this.prompt_tone = true;
210
- this.mode = 0;
211
- this.target_temperature = 20.0;
212
- this.fan_speed = 102;
213
- this.swing_vertical = false;
214
- this.swing_horizontal = false;
215
- this.boost_mode = false;
216
- this.smart_eye = false;
217
- this.dry = false;
218
- this.aux_heating = false;
219
- this.eco_mode = false;
220
- this.temp_fahrenheit = false;
221
- this.sleep_mode = false;
222
- this.natural_wind = false;
223
- this.frost_protect = false;
224
- this.comfort_mode = false;
225
- }
226
- get _body() {
227
- // Byte1, Power, prompt_tone
228
- const power = this.power ? 0x01 : 0x00;
229
- const prompt_tone = this.prompt_tone ? 0x40 : 0x00;
230
- // Byte2, mode target_temperature
231
- const mode = (this.mode << 5) & 0xe0;
232
- const target_temperature = ((this.target_temperature | 0) & 0xf) | ((Math.round(this.target_temperature * 2) | 0) % 2 !== 0 ? 0x10 : 0);
233
- // Byte 3, fan_speed
234
- const fan_speed = this.fan_speed & 0x7f;
235
- // Byte 7, swing_mode
236
- const swing_mode = 0x30 | (this.swing_vertical ? 0x0c : 0) | (this.swing_horizontal ? 0x03 : 0);
237
- // Byte 8, turbo
238
- const boost_mode = this.boost_mode ? 0x20 : 0;
239
- // Byte 9 aux_heating eco_mode
240
- const smart_eye = this.smart_eye ? 0x01 : 0;
241
- const dry = this.dry ? 0x04 : 0;
242
- const aux_heating = this.aux_heating ? 0x08 : 0;
243
- const eco_mode = this.eco_mode ? 0x80 : 0;
244
- // Byte 10 temp_fahrenheit
245
- const temp_fahrenheit = this.temp_fahrenheit ? 0x04 : 0;
246
- const sleep_mode = this.sleep_mode ? 0x01 : 0;
247
- const boost_mode_1 = this.boost_mode ? 0x02 : 0;
248
- // Byte 17 natural_wind
249
- const natural_wind = this.natural_wind ? 0x40 : 0;
250
- // Byte 21 frost_protect
251
- const frost_protect = this.frost_protect ? 0x80 : 0;
252
- // Byte 22 comfort_mode
253
- const comfort_mode = this.comfort_mode ? 0x01 : 0;
254
- return Buffer.from([
255
- power | prompt_tone,
256
- mode | target_temperature,
257
- fan_speed,
258
- 0x00,
259
- 0x00,
260
- 0x00,
261
- swing_mode,
262
- boost_mode,
263
- smart_eye | dry | aux_heating | eco_mode,
264
- temp_fahrenheit | sleep_mode | boost_mode_1,
265
- 0x00,
266
- 0x00,
267
- 0x00,
268
- 0x00,
269
- 0x00,
270
- 0x00,
271
- natural_wind,
272
- 0x00,
273
- 0x00,
274
- 0x00,
275
- frost_protect,
276
- comfort_mode,
277
- ]);
278
- }
279
- }
280
- exports.MessageGeneralSet = MessageGeneralSet;
281
- class MessageNewProtocolSet extends MessageACBase {
282
- constructor(device_protocol_version) {
283
- super(device_protocol_version, MideaMessage_1.MessageType.SET, 0xb0);
284
- this.prompt_tone = false;
285
- }
286
- get _body() {
287
- let pack_count = 0;
288
- let payload = Buffer.from([0x00]);
289
- if (this.wind_swing_ud_angle !== undefined) {
290
- pack_count += 1;
291
- payload = Buffer.concat([
292
- payload,
293
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.WIND_SWING_UD_ANGLE, Buffer.from([this.wind_swing_ud_angle])),
294
- ]);
295
- }
296
- if (this.wind_swing_lr_angle !== undefined) {
297
- pack_count += 1;
298
- payload = Buffer.concat([
299
- payload,
300
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.WIND_SWING_LR_ANGLE, Buffer.from([this.wind_swing_lr_angle])),
301
- ]);
302
- }
303
- if (this.breezeless !== undefined) {
304
- pack_count += 1;
305
- payload = Buffer.concat([
306
- payload,
307
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.BREEZELESS, Buffer.from([this.breezeless ? 0x01 : 0x00])),
308
- ]);
309
- }
310
- if (this.indirect_wind !== undefined) {
311
- pack_count += 1;
312
- payload = Buffer.concat([
313
- payload,
314
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.INDIRECT_WIND, Buffer.from([this.indirect_wind ? 0x02 : 0x01])),
315
- ]);
316
- }
317
- if (this.screen_display !== undefined) {
318
- pack_count += 1;
319
- payload = Buffer.concat([
320
- payload,
321
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.SCREEN_DISPLAY, Buffer.from([this.screen_display ? 0x64 : 0x00])),
322
- ]);
323
- }
324
- if (this.fresh_air_1 !== undefined && this.fresh_air_1.length === 2) {
325
- pack_count += 1;
326
- const fresh_air_power = this.fresh_air_1[0] > 0 ? 2 : 1;
327
- const fresh_air_fan_speed = this.fresh_air_1[1];
328
- payload = Buffer.concat([
329
- payload,
330
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.FRESH_AIR_1, Buffer.from([fresh_air_power, fresh_air_fan_speed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])),
331
- ]);
332
- }
333
- if (this.fresh_air_2 !== undefined && this.fresh_air_2.length === 2) {
334
- pack_count += 1;
335
- const fresh_air_power = this.fresh_air_2[0] > 0 ? 1 : 0;
336
- const fresh_air_fan_speed = this.fresh_air_2[1];
337
- payload = Buffer.concat([
338
- payload,
339
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.FRESH_AIR_2, Buffer.from([fresh_air_power, fresh_air_fan_speed, 0xff])),
340
- ]);
341
- }
342
- pack_count += 1;
343
- payload = Buffer.concat([
344
- payload,
345
- MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.PROMPT_TONE, Buffer.from([this.prompt_tone ? 0x01 : 0x00])),
346
- ]);
347
- payload[0] = pack_count;
348
- return payload;
349
- }
350
- }
351
- exports.MessageNewProtocolSet = MessageNewProtocolSet;
352
- class XA0MessageBody extends MideaMessage_1.MessageBody {
353
- constructor(body) {
354
- super(body);
355
- this.power = (body[1] & 0x1) > 0;
356
- this.target_temperature = ((body[1] & 0x3e) >> 1) - 4 + 16.0 + ((body[1] & 0x40) > 0 ? 0.5 : 0.0);
357
- this.mode = (body[2] & 0xe0) >> 5;
358
- this.fan_speed = body[3] & 0x7f;
359
- this.fan_auto = this.fan_speed > 100;
360
- this.swing_vertical = (body[7] & 0xc) > 0;
361
- this.swing_horizontal = (body[7] & 0x3) > 0;
362
- this.boost_mode = (body[8] & 0x20) > 0 || (body[10] & 0x2) > 0;
363
- this.smart_eye = (body[9] & 0x01) > 0;
364
- this.dry = (body[9] & 0x04) > 0;
365
- this.aux_heating = (body[9] & 0x08) > 0;
366
- this.eco_mode = (body[9] & 0x10) > 0;
367
- this.sleep_mode = (body[10] & 0x01) > 0;
368
- this.natural_wind = (body[10] & 0x40) > 0;
369
- this.full_dust = (body[13] & 0x20) > 0;
370
- this.comfort_mode = body.length > 16 ? (body[14] & 0x1) > 0 : false;
371
- }
372
- }
373
- class XA1MessageBody extends MideaMessage_1.MessageBody {
374
- constructor(body) {
375
- super(body);
376
- if (body[13] !== 0xff) {
377
- const temp_integer = ((body[13] - 50) / 2) | 0;
378
- const temp_decimal = body.length > 20 ? (body[18] & 0xf) * 0.1 : 0;
379
- if (body[13] > 49) {
380
- this.indoor_temperature = temp_integer + temp_decimal;
381
- }
382
- else {
383
- this.indoor_temperature = temp_integer - temp_decimal;
384
- }
385
- }
386
- if (body[14] === 0xff) {
387
- this.outdoor_temperature = undefined;
388
- }
389
- else {
390
- const temp_integer = ((body[14] - 50) / 2) | 0;
391
- const temp_decimal = body.length > 20 ? ((body[18] & 0xf0) >> 4) * 0.1 : 0;
392
- if (body[14] > 49) {
393
- this.outdoor_temperature = temp_integer + temp_decimal;
394
- }
395
- else {
396
- this.outdoor_temperature = temp_integer - temp_decimal;
397
- }
398
- }
399
- this.indoor_humidity = body[17];
400
- }
401
- }
402
- class XBXMessageBody extends MideaMessage_1.NewProtocolMessageBody {
403
- constructor(body, body_type) {
404
- super(body, body_type);
405
- const params = this.parse();
406
- if (NewProtocolTags.WIND_SWING_LR_ANGLE in params) {
407
- this.wind_swing_lr_angle = params[NewProtocolTags.WIND_SWING_LR_ANGLE][0];
408
- }
409
- if (NewProtocolTags.WIND_SWING_UD_ANGLE in params) {
410
- this.wind_swing_ud_angle = params[NewProtocolTags.WIND_SWING_UD_ANGLE][0];
411
- }
412
- if (NewProtocolTags.INDIRECT_WIND in params) {
413
- this.indirect_wind = params[NewProtocolTags.INDIRECT_WIND][0] === 0x02;
414
- }
415
- if (NewProtocolTags.INDOOR_HUMIDITY in params) {
416
- this.indoor_humidity = params[NewProtocolTags.INDOOR_HUMIDITY][0];
417
- }
418
- if (NewProtocolTags.BREEZELESS in params) {
419
- this.breezeless = params[NewProtocolTags.BREEZELESS][0] === 1;
420
- }
421
- if (NewProtocolTags.SCREEN_DISPLAY in params) {
422
- this.screen_display = params[NewProtocolTags.SCREEN_DISPLAY][0] > 0;
423
- this.screen_display_new = true;
424
- }
425
- if (NewProtocolTags.FRESH_AIR_1 in params) {
426
- this.fresh_air_1 = true;
427
- const data = params[NewProtocolTags.FRESH_AIR_1];
428
- this.fresh_air_power = data[0] === 0x02;
429
- this.fresh_air_fan_speed = data[1];
430
- }
431
- if (NewProtocolTags.FRESH_AIR_2 in params) {
432
- this.fresh_air_2 = true;
433
- const data = params[NewProtocolTags.FRESH_AIR_2];
434
- this.fresh_air_power = data[0] > 0;
435
- this.fresh_air_fan_speed = data[1];
436
- }
437
- }
438
- }
439
- class XC0MessageBody extends MideaMessage_1.MessageBody {
440
- constructor(body) {
441
- super(body);
442
- this.power = (body[1] & 0x1) > 0;
443
- this.mode = (body[2] & 0xe0) >> 5;
444
- this.target_temperature = (body[2] & 0x0f) + 16.0 + ((body[2] & 0x10) > 0 ? 0.5 : 0.0);
445
- this.fan_speed = body[3] & 0x7f;
446
- this.fan_auto = this.fan_speed > 100;
447
- this.swing_vertical = (body[7] & 0x0c) > 0;
448
- this.swing_horizontal = (body[7] & 0x03) > 0;
449
- this.boost_mode = (body[8] & 0x20) > 0 || (body[10] & 0x2) > 0;
450
- this.smart_eye = (body[8] & 0x40) > 0;
451
- this.natural_wind = (body[9] & 0x2) > 0;
452
- this.dry = (body[9] & 0x4) > 0;
453
- this.eco_mode = (body[9] & 0x10) > 0;
454
- this.aux_heating = (body[9] & 0x08) > 0;
455
- this.temp_fahrenheit = (body[10] & 0x04) > 0;
456
- this.sleep_mode = (body[10] & 0x01) > 0;
457
- if (body[11] !== 0xff) {
458
- const temp_integer = ((body[11] - 50) / 2) | 0;
459
- const temp_decimal = (body[15] & 0x0f) * 0.1;
460
- if (body[11] > 49) {
461
- this.indoor_temperature = temp_integer + temp_decimal;
462
- }
463
- else {
464
- this.indoor_temperature = temp_integer - temp_decimal;
465
- }
466
- }
467
- if (body[12] === 0xff) {
468
- this.outdoor_temperature = undefined;
469
- }
470
- else {
471
- const temp_integer = ((body[12] - 50) / 2) | 0;
472
- const temp_decimal = ((body[15] & 0xf0) >> 4) * 0.1;
473
- if (body[12] > 49) {
474
- this.outdoor_temperature = temp_integer + temp_decimal;
475
- }
476
- else {
477
- this.outdoor_temperature = temp_integer - temp_decimal;
478
- }
479
- }
480
- this.full_dust = (body[13] & 0x20) > 0;
481
- this.screen_display = ((body[14] >> 4) & 0x7) !== 0x07 && this.power;
482
- this.frost_protect = body.length > 23 ? (body[21] & 0x80) > 0 : false;
483
- this.comfort_mode = body.length > 24 ? (body[22] & 0x1) > 0 : false;
484
- }
485
- }
486
- class XC1MessageBody extends MideaMessage_1.MessageBody {
487
- constructor(body, analysis_method = 3) {
488
- super(body);
489
- if (body[3] === 0x44) {
490
- this.total_energy_consumption = XC1MessageBody.parse_consumption(analysis_method, body[4], body[5], body[6], body[7]);
491
- this.current_energy_consumption = XC1MessageBody.parse_consumption(analysis_method, body[12], body[13], body[14], body[15]);
492
- this.realtime_power = XC1MessageBody.parse_power(analysis_method, body[16], body[17], body[18]);
493
- }
494
- }
495
- static parse_power(analysis_method, byte1, byte2, byte3) {
496
- if (analysis_method === 1) {
497
- return byte1 + byte2 / 100 + byte3 / 10000;
498
- }
499
- else if (analysis_method === 2) {
500
- return ((byte1 << 16) + (byte2 << 8) + byte3) / 1000;
501
- }
502
- else {
503
- return (byte1 * 10000 + byte2 * 100 + byte3) / 10;
504
- }
505
- }
506
- static parse_consumption(analysis_method, byte1, byte2, byte3, byte4) {
507
- if (analysis_method === 1) {
508
- return byte1 * 10000 + byte2 * 100 + byte3 + byte4 / 100;
509
- }
510
- else if (analysis_method === 2) {
511
- return ((byte1 << 32) + (byte2 << 16) + (byte3 << 8) + byte4) / 1000;
512
- }
513
- else {
514
- return (byte1 * 1000000 + byte2 * 10000 + byte3 * 100 + byte4) / 100;
515
- }
516
- }
517
- }
518
- class XBBMessageBody extends MideaMessage_1.MessageBody {
519
- constructor(body) {
520
- super(body);
521
- const subprotocol_head = body.subarray(0, 6);
522
- const subprotocol_body = body.subarray(6, body.length);
523
- const data_type = subprotocol_head[subprotocol_head.length - 1];
524
- const subprotocol_body_len = subprotocol_body.length;
525
- if (data_type === 0x20 || data_type === 0x11) {
526
- this.power = (subprotocol_body[0] & 0x1) > 0;
527
- this.dry = (subprotocol_body[0] & 0x10) > 0;
528
- this.boost_mode = (subprotocol_body[0] & 0x20) > 0;
529
- this.aux_heating = (subprotocol_body[1] & 0x40) > 0;
530
- this.sleep_mode = (subprotocol_body[2] & 0x80) > 0;
531
- this.mode = BB_AC_MODES.indexOf(subprotocol_body[5] + 1);
532
- if (this.mode === -1) {
533
- this.mode = 0;
534
- }
535
- this.target_temperature = (subprotocol_body[6] - 30) / 2;
536
- this.fan_speed = subprotocol_body[7];
537
- this.fan_auto = this.fan_speed > 100;
538
- this.timer = subprotocol_body_len > 27 ? (subprotocol_body[25] & 0x04) > 0 : false;
539
- this.eco_mode = subprotocol_body_len > 27 ? (subprotocol_body[25] & 0x40) > 0 : false;
540
- }
541
- else if (data_type === 0x10) {
542
- if ((subprotocol_body[8] & 0x80) === 0x80) {
543
- this.indoor_temperature = ((0 - (~(subprotocol_body[7] + subprotocol_body[8] * 256) + 1)) & 0xffff) / 100;
544
- }
545
- else {
546
- this.indoor_temperature = (subprotocol_body[7] + subprotocol_body[8] * 256) / 100;
547
- }
548
- this.indoor_humidity = subprotocol_body[30];
549
- this.sn8_flag = subprotocol_body[80] === 0x31;
550
- }
551
- else if (data_type === 0x30) {
552
- if ((subprotocol_body[6] & 0x80) === 0x80) {
553
- this.outdoor_temperature = ((0 - (~(subprotocol_body[5] + subprotocol_body[6] * 256) + 1)) & 0xffff) / 100;
554
- }
555
- else {
556
- this.outdoor_temperature = (subprotocol_body[5] + subprotocol_body[6] * 256) / 100;
557
- }
558
- }
559
- }
560
- }
561
- class MessageACResponse extends MideaMessage_1.MessageResponse {
562
- constructor(message, power_analysis_method = 3) {
563
- super(message);
564
- this.message = message;
565
- if (this.message_type === MideaMessage_1.MessageType.NOTIFY2 && this.body_type === 0xa0) {
566
- this.set_body(new XA0MessageBody(this.body));
567
- }
568
- else if (this.message_type === MideaMessage_1.MessageType.NOTIFY1 && this.body_type === 0xa1) {
569
- this.set_body(new XA1MessageBody(this.body));
570
- }
571
- else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET, MideaMessage_1.MessageType.NOTIFY2].includes(this.message_type) &&
572
- [0xb0, 0xb1, 0xb5].includes(this.body_type)) {
573
- this.set_body(new XBXMessageBody(this.body, this.body_type));
574
- }
575
- else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET].includes(this.message_type) && this.body_type === 0xc0) {
576
- this.set_body(new XC0MessageBody(this.body));
577
- }
578
- else if (this.message_type === MideaMessage_1.MessageType.QUERY && this.body_type === 0xc1) {
579
- this.set_body(new XC1MessageBody(this.body, power_analysis_method));
580
- }
581
- else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET, MideaMessage_1.MessageType.NOTIFY2].includes(this.message_type) &&
582
- this.body_type === 0xbb &&
583
- this.body.length >= 21) {
584
- this.used_subprotocol = true;
585
- this.set_body(new XBBMessageBody(this.body));
586
- }
587
- }
588
- }
589
- exports.MessageACResponse = MessageACResponse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageACResponse = exports.MessageNewProtocolSet = exports.MessageGeneralSet = exports.MessageSubProtocolSet = exports.MessageSubProtocolQuery = exports.MessageSubProtocol = exports.MessageNewProtocolQuery = exports.MessageSwitchDisplay = exports.MessagePowerQuery = exports.MessageQuery = void 0;
4
+ /***********************************************************************
5
+ * Midea Air Conditioner Device message handler class
6
+ *
7
+ * Copyright (c) 2023 Kovalovszky Patrik, https://github.com/kovapatrik
8
+ *
9
+ * With thanks to https://github.com/georgezhao2010/midea_ac_lan
10
+ *
11
+ */
12
+ const MideaConstants_1 = require("../../core/MideaConstants");
13
+ const MideaMessage_1 = require("../../core/MideaMessage");
14
+ const MideaUtils_1 = require("../../core/MideaUtils");
15
+ var NewProtocolTags;
16
+ (function (NewProtocolTags) {
17
+ NewProtocolTags[NewProtocolTags["WIND_SWING_UD_ANGLE"] = 9] = "WIND_SWING_UD_ANGLE";
18
+ NewProtocolTags[NewProtocolTags["WIND_SWING_LR_ANGLE"] = 10] = "WIND_SWING_LR_ANGLE";
19
+ NewProtocolTags[NewProtocolTags["INDOOR_HUMIDITY"] = 21] = "INDOOR_HUMIDITY";
20
+ NewProtocolTags[NewProtocolTags["SCREEN_DISPLAY"] = 23] = "SCREEN_DISPLAY";
21
+ NewProtocolTags[NewProtocolTags["BREEZELESS"] = 24] = "BREEZELESS";
22
+ NewProtocolTags[NewProtocolTags["PROMPT_TONE"] = 26] = "PROMPT_TONE";
23
+ NewProtocolTags[NewProtocolTags["INDIRECT_WIND"] = 66] = "INDIRECT_WIND";
24
+ NewProtocolTags[NewProtocolTags["FRESH_AIR_1"] = 563] = "FRESH_AIR_1";
25
+ NewProtocolTags[NewProtocolTags["FRESH_AIR_2"] = 75] = "FRESH_AIR_2";
26
+ NewProtocolTags[NewProtocolTags["SELF_CLEAN"] = 57] = "SELF_CLEAN";
27
+ NewProtocolTags[NewProtocolTags["RATE_SELECT"] = 72] = "RATE_SELECT";
28
+ })(NewProtocolTags || (NewProtocolTags = {}));
29
+ const BB_AC_MODES = [0, 3, 1, 2, 4, 5];
30
+ class MessageACBase extends MideaMessage_1.MessageRequest {
31
+ constructor(device_protocol_version, message_type, body_type) {
32
+ super(MideaConstants_1.DeviceType.AIR_CONDITIONER, message_type, body_type, device_protocol_version);
33
+ MessageACBase.message_serial += 1;
34
+ if (MessageACBase.message_serial >= 254) {
35
+ MessageACBase.message_serial = 1;
36
+ }
37
+ this.message_id = MessageACBase.message_serial;
38
+ }
39
+ get body() {
40
+ let body = Buffer.concat([Buffer.from([this.body_type]), this._body, Buffer.from([this.message_id])]);
41
+ body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
42
+ return body;
43
+ }
44
+ }
45
+ MessageACBase.message_serial = 0;
46
+ class MessageQuery extends MessageACBase {
47
+ constructor(device_protocol_version) {
48
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
49
+ }
50
+ get _body() {
51
+ return Buffer.from([0x81, 0x00, 0xff, 0x03, 0xff, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
52
+ }
53
+ }
54
+ exports.MessageQuery = MessageQuery;
55
+ class MessagePowerQuery extends MessageACBase {
56
+ constructor(device_protocol_version) {
57
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
58
+ }
59
+ get _body() {
60
+ return Buffer.from([0x21, 0x01, 0x44, 0x00, 0x01]);
61
+ }
62
+ get body() {
63
+ let body = Buffer.concat([Buffer.from([this.body_type]), this._body]);
64
+ body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
65
+ return body;
66
+ }
67
+ }
68
+ exports.MessagePowerQuery = MessagePowerQuery;
69
+ class MessageSwitchDisplay extends MessageACBase {
70
+ constructor(device_protocol_version) {
71
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x41);
72
+ }
73
+ get _body() {
74
+ return Buffer.from([0x81, 0x00, 0xff, 0x02, 0xff, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
75
+ }
76
+ }
77
+ exports.MessageSwitchDisplay = MessageSwitchDisplay;
78
+ class MessageNewProtocolQuery extends MessageACBase {
79
+ constructor(device_protocol_version, alternate_display = false) {
80
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0xb1);
81
+ this.alternate_display = alternate_display;
82
+ }
83
+ get _body() {
84
+ const query_params = [
85
+ NewProtocolTags.WIND_SWING_UD_ANGLE,
86
+ NewProtocolTags.WIND_SWING_LR_ANGLE,
87
+ NewProtocolTags.INDIRECT_WIND,
88
+ NewProtocolTags.BREEZELESS,
89
+ NewProtocolTags.INDOOR_HUMIDITY,
90
+ this.alternate_display ? NewProtocolTags.SCREEN_DISPLAY : undefined,
91
+ NewProtocolTags.FRESH_AIR_1,
92
+ NewProtocolTags.FRESH_AIR_2,
93
+ NewProtocolTags.SELF_CLEAN,
94
+ NewProtocolTags.RATE_SELECT,
95
+ ];
96
+ let body = Buffer.from([query_params.length]);
97
+ for (const param of query_params) {
98
+ if (param) {
99
+ body = Buffer.concat([body, Buffer.from([param & 0xff, param >> 8])]);
100
+ }
101
+ }
102
+ return body;
103
+ }
104
+ }
105
+ exports.MessageNewProtocolQuery = MessageNewProtocolQuery;
106
+ class MessageSubProtocol extends MessageACBase {
107
+ constructor(device_protocol_version, message_type, subprotocol_query_type) {
108
+ super(device_protocol_version, message_type, 0xaa);
109
+ this.subprotocol_query_type = subprotocol_query_type;
110
+ }
111
+ get body() {
112
+ let body = Buffer.concat([Buffer.from([this.body_type]), this._body]);
113
+ body = Buffer.concat([body, Buffer.from([(0, MideaUtils_1.calculate)(body)])]);
114
+ body = Buffer.concat([body, Buffer.from([this.checksum(body)])]);
115
+ return body;
116
+ }
117
+ get _body() {
118
+ let body = Buffer.from([
119
+ 6 + 2 + (this.subprotocol_body ? this.subprotocol_body.length : 0),
120
+ 0x00,
121
+ 0xff,
122
+ 0xff,
123
+ this.subprotocol_query_type,
124
+ ]);
125
+ if (this.subprotocol_body) {
126
+ body = Buffer.concat([body, this.subprotocol_body]);
127
+ }
128
+ return body;
129
+ }
130
+ }
131
+ exports.MessageSubProtocol = MessageSubProtocol;
132
+ class MessageSubProtocolQuery extends MessageSubProtocol {
133
+ constructor(device_protocol_version, subprotocol_query_type) {
134
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, subprotocol_query_type);
135
+ }
136
+ }
137
+ exports.MessageSubProtocolQuery = MessageSubProtocolQuery;
138
+ class MessageSubProtocolSet extends MessageSubProtocol {
139
+ constructor(device_protocol_version) {
140
+ super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x20);
141
+ this.power = false;
142
+ this.mode = 0;
143
+ this.target_temperature = 20.0;
144
+ this.fan_speed = 102;
145
+ this.boost_mode = false;
146
+ this.aux_heating = false;
147
+ this.dry = false;
148
+ this.eco_mode = false;
149
+ this.sleep_mode = false;
150
+ this.sn8_flag = false;
151
+ this.timer = false;
152
+ this.prompt_tone = false;
153
+ }
154
+ get subprotocol_body() {
155
+ const power = this.power ? 0x01 : 0x00;
156
+ const dry = this.dry && this.power ? 0x10 : 0;
157
+ const boost_mode = this.boost_mode ? 0x20 : 0;
158
+ const aux_heating = this.aux_heating ? 0x40 : 0;
159
+ const sleep_mode = this.sleep_mode ? 0x80 : 0;
160
+ const mode = this.mode === 0 ? 0 : this.mode < BB_AC_MODES.length ? BB_AC_MODES[this.mode] - 1 : 2;
161
+ const target_temperature = (this.target_temperature * 2 + 30) | 0;
162
+ const water_model_temperature_set = ((this.target_temperature - 1) * 2 + 50) | 0;
163
+ const fan_speed = this.fan_speed;
164
+ const eco = this.eco_mode ? 0x40 : 0;
165
+ const prompt_tone = this.prompt_tone ? 0x01 : 0;
166
+ const timer = this.sn8_flag && this.timer ? 0x04 : 0;
167
+ return Buffer.from([
168
+ boost_mode | power | dry,
169
+ aux_heating,
170
+ sleep_mode,
171
+ 0x00,
172
+ 0x00,
173
+ mode,
174
+ target_temperature,
175
+ fan_speed,
176
+ 0x32,
177
+ 0x00,
178
+ 0x00,
179
+ 0x00,
180
+ 0x00,
181
+ 0x00,
182
+ 0x00,
183
+ 0x01,
184
+ 0x01,
185
+ 0x00,
186
+ 0x01,
187
+ water_model_temperature_set,
188
+ prompt_tone,
189
+ target_temperature,
190
+ 0x32,
191
+ 0x66,
192
+ 0x00,
193
+ eco | timer,
194
+ 0x00,
195
+ 0x00,
196
+ 0x00,
197
+ 0x00,
198
+ 0x00,
199
+ 0x00,
200
+ 0x00,
201
+ 0x00,
202
+ 0x00,
203
+ 0x00,
204
+ 0x08,
205
+ ]);
206
+ }
207
+ }
208
+ exports.MessageSubProtocolSet = MessageSubProtocolSet;
209
+ class MessageGeneralSet extends MessageACBase {
210
+ constructor(device_protocol_version) {
211
+ super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x40);
212
+ this.power = false;
213
+ this.prompt_tone = true;
214
+ this.mode = 0;
215
+ this.target_temperature = 20.0;
216
+ this.fan_speed = 102;
217
+ this.swing_vertical = false;
218
+ this.swing_horizontal = false;
219
+ this.boost_mode = false;
220
+ this.smart_eye = false;
221
+ this.dry = false;
222
+ this.aux_heating = false;
223
+ this.eco_mode = false;
224
+ this.temp_fahrenheit = false;
225
+ this.sleep_mode = false;
226
+ this.natural_wind = false;
227
+ this.frost_protect = false;
228
+ this.comfort_mode = false;
229
+ }
230
+ get _body() {
231
+ // Byte1, Power, prompt_tone
232
+ const power = this.power ? 0x01 : 0x00;
233
+ const prompt_tone = this.prompt_tone ? 0x40 : 0x00;
234
+ // Byte2, mode target_temperature
235
+ const mode = (this.mode << 5) & 0xe0;
236
+ const target_temperature = ((this.target_temperature | 0) & 0xf) | ((Math.round(this.target_temperature * 2) | 0) % 2 !== 0 ? 0x10 : 0);
237
+ // Byte 3, fan_speed
238
+ const fan_speed = this.fan_speed & 0x7f;
239
+ // Byte 7, swing_mode
240
+ const swing_mode = 0x30 | (this.swing_vertical ? 0x0c : 0) | (this.swing_horizontal ? 0x03 : 0);
241
+ // Byte 8, turbo
242
+ const boost_mode = this.boost_mode ? 0x20 : 0;
243
+ // Byte 9 aux_heating eco_mode
244
+ const smart_eye = this.smart_eye ? 0x01 : 0;
245
+ const dry = this.dry ? 0x04 : 0;
246
+ const aux_heating = this.aux_heating ? 0x08 : 0;
247
+ const eco_mode = this.eco_mode ? 0x80 : 0;
248
+ // Byte 10 temp_fahrenheit
249
+ const temp_fahrenheit = this.temp_fahrenheit ? 0x04 : 0;
250
+ const sleep_mode = this.sleep_mode ? 0x01 : 0;
251
+ const boost_mode_1 = this.boost_mode ? 0x02 : 0;
252
+ // Byte 17 natural_wind
253
+ const natural_wind = this.natural_wind ? 0x40 : 0;
254
+ // Byte 21 frost_protect
255
+ const frost_protect = this.frost_protect ? 0x80 : 0;
256
+ // Byte 22 comfort_mode
257
+ const comfort_mode = this.comfort_mode ? 0x01 : 0;
258
+ return Buffer.from([
259
+ power | prompt_tone,
260
+ mode | target_temperature,
261
+ fan_speed,
262
+ 0x00,
263
+ 0x00,
264
+ 0x00,
265
+ swing_mode,
266
+ boost_mode,
267
+ smart_eye | dry | aux_heating | eco_mode,
268
+ temp_fahrenheit | sleep_mode | boost_mode_1,
269
+ 0x00,
270
+ 0x00,
271
+ 0x00,
272
+ 0x00,
273
+ 0x00,
274
+ 0x00,
275
+ natural_wind,
276
+ 0x00,
277
+ 0x00,
278
+ 0x00,
279
+ frost_protect,
280
+ comfort_mode,
281
+ ]);
282
+ }
283
+ }
284
+ exports.MessageGeneralSet = MessageGeneralSet;
285
+ class MessageNewProtocolSet extends MessageACBase {
286
+ constructor(device_protocol_version) {
287
+ super(device_protocol_version, MideaMessage_1.MessageType.SET, 0xb0);
288
+ this.prompt_tone = false;
289
+ }
290
+ get _body() {
291
+ let pack_count = 0;
292
+ let payload = Buffer.from([0x00]);
293
+ if (this.wind_swing_ud_angle !== undefined) {
294
+ pack_count += 1;
295
+ payload = Buffer.concat([
296
+ payload,
297
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.WIND_SWING_UD_ANGLE, Buffer.from([this.wind_swing_ud_angle])),
298
+ ]);
299
+ }
300
+ if (this.wind_swing_lr_angle !== undefined) {
301
+ pack_count += 1;
302
+ payload = Buffer.concat([
303
+ payload,
304
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.WIND_SWING_LR_ANGLE, Buffer.from([this.wind_swing_lr_angle])),
305
+ ]);
306
+ }
307
+ if (this.breezeless !== undefined) {
308
+ pack_count += 1;
309
+ payload = Buffer.concat([
310
+ payload,
311
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.BREEZELESS, Buffer.from([this.breezeless ? 0x01 : 0x00])),
312
+ ]);
313
+ }
314
+ if (this.indirect_wind !== undefined) {
315
+ pack_count += 1;
316
+ payload = Buffer.concat([
317
+ payload,
318
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.INDIRECT_WIND, Buffer.from([this.indirect_wind ? 0x02 : 0x01])),
319
+ ]);
320
+ }
321
+ if (this.screen_display !== undefined) {
322
+ pack_count += 1;
323
+ payload = Buffer.concat([
324
+ payload,
325
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.SCREEN_DISPLAY, Buffer.from([this.screen_display ? 0x64 : 0x00])),
326
+ ]);
327
+ }
328
+ if (this.fresh_air_1 !== undefined && this.fresh_air_1.length === 2) {
329
+ pack_count += 1;
330
+ const fresh_air_power = this.fresh_air_1[0] > 0 ? 2 : 1;
331
+ const fresh_air_fan_speed = this.fresh_air_1[1];
332
+ payload = Buffer.concat([
333
+ payload,
334
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.FRESH_AIR_1, Buffer.from([fresh_air_power, fresh_air_fan_speed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])),
335
+ ]);
336
+ }
337
+ if (this.fresh_air_2 !== undefined && this.fresh_air_2.length === 2) {
338
+ pack_count += 1;
339
+ const fresh_air_power = this.fresh_air_2[0] > 0 ? 1 : 0;
340
+ const fresh_air_fan_speed = this.fresh_air_2[1];
341
+ payload = Buffer.concat([
342
+ payload,
343
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.FRESH_AIR_2, Buffer.from([fresh_air_power, fresh_air_fan_speed, 0xff])),
344
+ ]);
345
+ }
346
+ if (this.self_clean !== undefined) {
347
+ pack_count += 1;
348
+ payload = Buffer.concat([
349
+ payload,
350
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.SELF_CLEAN, Buffer.from([this.self_clean ? 0x01 : 0x00])),
351
+ ]);
352
+ }
353
+ if (this.rate_select !== undefined) {
354
+ pack_count += 1;
355
+ payload = Buffer.concat([payload, MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.RATE_SELECT, Buffer.from([this.rate_select]))]);
356
+ }
357
+ pack_count += 1;
358
+ payload = Buffer.concat([
359
+ payload,
360
+ MideaMessage_1.NewProtocolMessageBody.packet(NewProtocolTags.PROMPT_TONE, Buffer.from([this.prompt_tone ? 0x01 : 0x00])),
361
+ ]);
362
+ payload[0] = pack_count;
363
+ return payload;
364
+ }
365
+ }
366
+ exports.MessageNewProtocolSet = MessageNewProtocolSet;
367
+ class XA0MessageBody extends MideaMessage_1.MessageBody {
368
+ constructor(body) {
369
+ super(body);
370
+ this.power = (body[1] & 0x1) > 0;
371
+ this.target_temperature = ((body[1] & 0x3e) >> 1) - 4 + 16.0 + ((body[1] & 0x40) > 0 ? 0.5 : 0.0);
372
+ this.mode = (body[2] & 0xe0) >> 5;
373
+ this.fan_speed = body[3] & 0x7f;
374
+ this.fan_auto = this.fan_speed > 100;
375
+ this.swing_vertical = (body[7] & 0xc) > 0;
376
+ this.swing_horizontal = (body[7] & 0x3) > 0;
377
+ this.boost_mode = (body[8] & 0x20) > 0 || (body[10] & 0x2) > 0;
378
+ this.smart_eye = (body[9] & 0x01) > 0;
379
+ this.dry = (body[9] & 0x04) > 0;
380
+ this.aux_heating = (body[9] & 0x08) > 0;
381
+ this.eco_mode = (body[9] & 0x10) > 0;
382
+ this.sleep_mode = (body[10] & 0x01) > 0;
383
+ this.natural_wind = (body[10] & 0x40) > 0;
384
+ this.full_dust = (body[13] & 0x20) > 0;
385
+ this.comfort_mode = body.length > 16 ? (body[14] & 0x1) > 0 : false;
386
+ }
387
+ }
388
+ class XA1MessageBody extends MideaMessage_1.MessageBody {
389
+ constructor(body) {
390
+ super(body);
391
+ if (body[13] !== 0xff) {
392
+ const temp_integer = ((body[13] - 50) / 2) | 0;
393
+ const temp_decimal = body.length > 20 ? (body[18] & 0xf) * 0.1 : 0;
394
+ if (body[13] > 49) {
395
+ this.indoor_temperature = temp_integer + temp_decimal;
396
+ }
397
+ else {
398
+ this.indoor_temperature = temp_integer - temp_decimal;
399
+ }
400
+ }
401
+ if (body[14] === 0xff) {
402
+ this.outdoor_temperature = undefined;
403
+ }
404
+ else {
405
+ const temp_integer = ((body[14] - 50) / 2) | 0;
406
+ const temp_decimal = body.length > 20 ? ((body[18] & 0xf0) >> 4) * 0.1 : 0;
407
+ if (body[14] > 49) {
408
+ this.outdoor_temperature = temp_integer + temp_decimal;
409
+ }
410
+ else {
411
+ this.outdoor_temperature = temp_integer - temp_decimal;
412
+ }
413
+ }
414
+ this.indoor_humidity = body[17];
415
+ }
416
+ }
417
+ class XBXMessageBody extends MideaMessage_1.NewProtocolMessageBody {
418
+ constructor(body, body_type) {
419
+ super(body, body_type);
420
+ const params = this.parse();
421
+ if (NewProtocolTags.WIND_SWING_LR_ANGLE in params) {
422
+ this.wind_swing_lr_angle = params[NewProtocolTags.WIND_SWING_LR_ANGLE][0];
423
+ }
424
+ if (NewProtocolTags.WIND_SWING_UD_ANGLE in params) {
425
+ this.wind_swing_ud_angle = params[NewProtocolTags.WIND_SWING_UD_ANGLE][0];
426
+ }
427
+ if (NewProtocolTags.INDIRECT_WIND in params) {
428
+ this.indirect_wind = params[NewProtocolTags.INDIRECT_WIND][0] === 0x02;
429
+ }
430
+ if (NewProtocolTags.INDOOR_HUMIDITY in params) {
431
+ this.indoor_humidity = params[NewProtocolTags.INDOOR_HUMIDITY][0];
432
+ }
433
+ if (NewProtocolTags.BREEZELESS in params) {
434
+ this.breezeless = params[NewProtocolTags.BREEZELESS][0] === 1;
435
+ }
436
+ if (NewProtocolTags.SCREEN_DISPLAY in params) {
437
+ this.screen_display = params[NewProtocolTags.SCREEN_DISPLAY][0] > 0;
438
+ this.screen_display_new = true;
439
+ }
440
+ if (NewProtocolTags.FRESH_AIR_1 in params) {
441
+ this.fresh_air_1 = true;
442
+ const data = params[NewProtocolTags.FRESH_AIR_1];
443
+ this.fresh_air_power = data[0] === 0x02;
444
+ this.fresh_air_fan_speed = data[1];
445
+ }
446
+ if (NewProtocolTags.FRESH_AIR_2 in params) {
447
+ this.fresh_air_2 = true;
448
+ const data = params[NewProtocolTags.FRESH_AIR_2];
449
+ this.fresh_air_power = data[0] > 0;
450
+ this.fresh_air_fan_speed = data[1];
451
+ }
452
+ if (NewProtocolTags.SELF_CLEAN in params) {
453
+ this.self_clean = params[NewProtocolTags.SELF_CLEAN][0] === 0x1;
454
+ }
455
+ if (NewProtocolTags.RATE_SELECT in params) {
456
+ console.log('RATE_SELECT:', params[NewProtocolTags.RATE_SELECT]);
457
+ this.rate_select = params[NewProtocolTags.RATE_SELECT][0];
458
+ }
459
+ }
460
+ }
461
+ class XC0MessageBody extends MideaMessage_1.MessageBody {
462
+ constructor(body) {
463
+ super(body);
464
+ this.power = (body[1] & 0x1) > 0;
465
+ this.mode = (body[2] & 0xe0) >> 5;
466
+ this.target_temperature = (body[2] & 0x0f) + 16.0 + ((body[2] & 0x10) > 0 ? 0.5 : 0.0);
467
+ this.fan_speed = body[3] & 0x7f;
468
+ this.fan_auto = this.fan_speed > 100;
469
+ this.swing_vertical = (body[7] & 0x0c) > 0;
470
+ this.swing_horizontal = (body[7] & 0x03) > 0;
471
+ this.boost_mode = (body[8] & 0x20) > 0 || (body[10] & 0x2) > 0;
472
+ this.smart_eye = (body[8] & 0x40) > 0;
473
+ this.natural_wind = (body[9] & 0x2) > 0;
474
+ this.dry = (body[9] & 0x4) > 0;
475
+ this.eco_mode = (body[9] & 0x10) > 0;
476
+ this.aux_heating = (body[9] & 0x08) > 0;
477
+ this.temp_fahrenheit = (body[10] & 0x04) > 0;
478
+ this.sleep_mode = (body[10] & 0x01) > 0;
479
+ if (body[11] !== 0xff) {
480
+ const temp_integer = ((body[11] - 50) / 2) | 0;
481
+ const temp_decimal = (body[15] & 0x0f) * 0.1;
482
+ if (body[11] > 49) {
483
+ this.indoor_temperature = temp_integer + temp_decimal;
484
+ }
485
+ else {
486
+ this.indoor_temperature = temp_integer - temp_decimal;
487
+ }
488
+ }
489
+ if (body[12] === 0xff) {
490
+ this.outdoor_temperature = undefined;
491
+ }
492
+ else {
493
+ const temp_integer = ((body[12] - 50) / 2) | 0;
494
+ const temp_decimal = ((body[15] & 0xf0) >> 4) * 0.1;
495
+ if (body[12] > 49) {
496
+ this.outdoor_temperature = temp_integer + temp_decimal;
497
+ }
498
+ else {
499
+ this.outdoor_temperature = temp_integer - temp_decimal;
500
+ }
501
+ }
502
+ this.full_dust = (body[13] & 0x20) > 0;
503
+ this.screen_display = (body[14] & 0x70) >> 4 !== 0x07 && this.power;
504
+ this.frost_protect = body.length > 23 ? (body[21] & 0x80) > 0 : false;
505
+ this.comfort_mode = body.length > 24 ? (body[22] & 0x1) > 0 : false;
506
+ }
507
+ }
508
+ class XC1MessageBody extends MideaMessage_1.MessageBody {
509
+ constructor(body, analysis_method = 3) {
510
+ super(body);
511
+ if (body[3] === 0x44) {
512
+ this.total_energy_consumption = XC1MessageBody.parse_consumption(analysis_method, body[4], body[5], body[6], body[7]);
513
+ this.current_energy_consumption = XC1MessageBody.parse_consumption(analysis_method, body[12], body[13], body[14], body[15]);
514
+ this.realtime_power = XC1MessageBody.parse_power(analysis_method, body[16], body[17], body[18]);
515
+ }
516
+ }
517
+ static parse_power(analysis_method, byte1, byte2, byte3) {
518
+ if (analysis_method === 1) {
519
+ return byte1 + byte2 / 100 + byte3 / 10000;
520
+ }
521
+ else if (analysis_method === 2) {
522
+ return ((byte1 << 16) + (byte2 << 8) + byte3) / 1000;
523
+ }
524
+ else {
525
+ return (byte1 * 10000 + byte2 * 100 + byte3) / 10;
526
+ }
527
+ }
528
+ static parse_consumption(analysis_method, byte1, byte2, byte3, byte4) {
529
+ if (analysis_method === 1) {
530
+ return byte1 * 10000 + byte2 * 100 + byte3 + byte4 / 100;
531
+ }
532
+ else if (analysis_method === 2) {
533
+ return ((byte1 << 32) + (byte2 << 16) + (byte3 << 8) + byte4) / 1000;
534
+ }
535
+ else {
536
+ return (byte1 * 1000000 + byte2 * 10000 + byte3 * 100 + byte4) / 100;
537
+ }
538
+ }
539
+ }
540
+ class XBBMessageBody extends MideaMessage_1.MessageBody {
541
+ constructor(body) {
542
+ super(body);
543
+ const subprotocol_head = body.subarray(0, 6);
544
+ const subprotocol_body = body.subarray(6, body.length);
545
+ const data_type = subprotocol_head[subprotocol_head.length - 1];
546
+ const subprotocol_body_len = subprotocol_body.length;
547
+ if (data_type === 0x20 || data_type === 0x11) {
548
+ this.power = (subprotocol_body[0] & 0x1) > 0;
549
+ this.dry = (subprotocol_body[0] & 0x10) > 0;
550
+ this.boost_mode = (subprotocol_body[0] & 0x20) > 0;
551
+ this.aux_heating = (subprotocol_body[1] & 0x40) > 0;
552
+ this.sleep_mode = (subprotocol_body[2] & 0x80) > 0;
553
+ this.mode = BB_AC_MODES.indexOf(subprotocol_body[5] + 1);
554
+ if (this.mode === -1) {
555
+ this.mode = 0;
556
+ }
557
+ this.target_temperature = (subprotocol_body[6] - 30) / 2;
558
+ this.fan_speed = subprotocol_body[7];
559
+ this.fan_auto = this.fan_speed > 100;
560
+ this.timer = subprotocol_body_len > 27 ? (subprotocol_body[25] & 0x04) > 0 : false;
561
+ this.eco_mode = subprotocol_body_len > 27 ? (subprotocol_body[25] & 0x40) > 0 : false;
562
+ }
563
+ else if (data_type === 0x10) {
564
+ if ((subprotocol_body[8] & 0x80) === 0x80) {
565
+ this.indoor_temperature = ((0 - (~(subprotocol_body[7] + subprotocol_body[8] * 256) + 1)) & 0xffff) / 100;
566
+ }
567
+ else {
568
+ this.indoor_temperature = (subprotocol_body[7] + subprotocol_body[8] * 256) / 100;
569
+ }
570
+ this.indoor_humidity = subprotocol_body[30];
571
+ this.sn8_flag = subprotocol_body[80] === 0x31;
572
+ }
573
+ else if (data_type === 0x30) {
574
+ if ((subprotocol_body[6] & 0x80) === 0x80) {
575
+ this.outdoor_temperature = ((0 - (~(subprotocol_body[5] + subprotocol_body[6] * 256) + 1)) & 0xffff) / 100;
576
+ }
577
+ else {
578
+ this.outdoor_temperature = (subprotocol_body[5] + subprotocol_body[6] * 256) / 100;
579
+ }
580
+ }
581
+ }
582
+ }
583
+ class MessageACResponse extends MideaMessage_1.MessageResponse {
584
+ constructor(message, power_analysis_method = 3) {
585
+ super(message);
586
+ this.message = message;
587
+ if (this.message_type === MideaMessage_1.MessageType.NOTIFY2 && this.body_type === 0xa0) {
588
+ this.set_body(new XA0MessageBody(this.body));
589
+ }
590
+ else if (this.message_type === MideaMessage_1.MessageType.NOTIFY1 && this.body_type === 0xa1) {
591
+ this.set_body(new XA1MessageBody(this.body));
592
+ }
593
+ else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET, MideaMessage_1.MessageType.NOTIFY2].includes(this.message_type) &&
594
+ [0xb0, 0xb1, 0xb5].includes(this.body_type)) {
595
+ this.set_body(new XBXMessageBody(this.body, this.body_type));
596
+ }
597
+ else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET].includes(this.message_type) && this.body_type === 0xc0) {
598
+ this.set_body(new XC0MessageBody(this.body));
599
+ }
600
+ else if (this.message_type === MideaMessage_1.MessageType.QUERY && this.body_type === 0xc1) {
601
+ this.set_body(new XC1MessageBody(this.body, power_analysis_method));
602
+ }
603
+ else if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET, MideaMessage_1.MessageType.NOTIFY2].includes(this.message_type) &&
604
+ this.body_type === 0xbb &&
605
+ this.body.length >= 21) {
606
+ this.used_subprotocol = true;
607
+ this.set_body(new XBBMessageBody(this.body));
608
+ }
609
+ }
610
+ }
611
+ exports.MessageACResponse = MessageACResponse;
590
612
  //# sourceMappingURL=MideaACMessage.js.map