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