10static constexpr uint32_t RESTORE_SETTINGS_VERSION = 0x2E86A1F3UL;
13static uint8_t
checksum(
const uint8_t *frame) {
14 return static_cast<uint8_t
>(0x7F -
sum_bytes(frame, AIRTON_STATE_FRAME_SIZE - 1)) ^ 0x2C;
109 ClimateIR::control(
call);
120 uint8_t remote_state[AIRTON_STATE_FRAME_SIZE] = {
129 remote_state[6] =
checksum(remote_state);
131 ESP_LOGV(TAG,
"Sending: %02X %02X %02X %02X %02X %02X %02X", remote_state[6], remote_state[5], remote_state[4],
132 remote_state[3], remote_state[2], remote_state[1], remote_state[0]);
135 auto *data = transmit.get_data();
136 data->set_carrier_frequency(AIRTON_IR_FREQUENCY);
137 data->mark(AIRTON_HEADER_MARK);
138 data->space(AIRTON_HEADER_SPACE);
139 data->item_bytes<AIRTON_BIT_TIMINGS>(remote_state, AIRTON_STATE_FRAME_SIZE);
141 data->mark(AIRTON_BIT_MARK);
142 data->space(AIRTON_MESSAGE_SPACE);
148 uint8_t operating_mode = 0b1000;
149 switch (this->
mode) {
151 operating_mode |= AIRTON_MODE_COOL;
154 operating_mode |= AIRTON_MODE_DRY;
157 operating_mode |= AIRTON_MODE_HEAT;
160 operating_mode |= AIRTON_MODE_AUTO;
163 operating_mode |= AIRTON_MODE_FAN;
170 return operating_mode;
177 fan_speed = AIRTON_FAN_1;
180 fan_speed = AIRTON_FAN_3;
183 fan_speed = AIRTON_FAN_5;
187 fan_speed = AIRTON_FAN_AUTO;
193 switch (this->
mode) {
195 return AIRTON_AUTO_MODE_TEMP - AIRTON_TEMP_MIN;
197 return static_cast<uint8_t
>(roundf(clamp<float>(this->
target_temperature, AIRTON_TEMP_MIN, AIRTON_TEMP_MAX))) -
205 uint8_t settings = 0;
207 settings |= (1 << 4);
210 settings |= (1 << 7);
213 settings |= (1 << 1);
215 settings |= 0b01000000;
217 settings |= 0b00000100;
223 uint8_t
mode = frame[2];
226 if (
mode & 0b00001000) {
227 switch (
mode & 0b00000111) {
228 case AIRTON_MODE_COOL:
231 case AIRTON_MODE_DRY:
234 case AIRTON_MODE_HEAT:
237 case AIRTON_MODE_AUTO:
240 case AIRTON_MODE_FAN:
247 uint8_t
fan_mode = (frame[2] & 0b01110000) >> 4;
261 case AIRTON_FAN_AUTO:
270 const uint8_t
direction = frame[4] & 0b00001111;
274 ESP_LOGV(TAG,
"Unknown vertical direction %u",
direction);
283 uint8_t remote_state[AIRTON_STATE_FRAME_SIZE];
284 if (!data.expect_item(AIRTON_HEADER_MARK, AIRTON_HEADER_SPACE)) {
285 ESP_LOGV(TAG,
"Wrong header encoding detected!");
288 if (!data.expect_bytes<AIRTON_BIT_TIMINGS>(remote_state, AIRTON_STATE_FRAME_SIZE)) {
289 ESP_LOGV(TAG,
"Wrong modulation encoding");
293 if (remote_state[0] != AIRTON_HEADER_BYTE0 || remote_state[1] != AIRTON_HEADER_BYTE1) {
294 ESP_LOGV(TAG,
"Wrong header contents: %02X %02X", remote_state[1], remote_state[0]);
297 const uint8_t expected =
checksum(remote_state);
298 if (remote_state[AIRTON_STATE_FRAME_SIZE - 1] != expected) {
299 ESP_LOGV(TAG,
"Checksum error: calculated %02X, received %02X", expected,
300 remote_state[AIRTON_STATE_FRAME_SIZE - 1]);
303 ESP_LOGV(TAG,
"Received: %02X %02X %02X %02X %02X %02X %02X", remote_state[6], remote_state[5], remote_state[4],
304 remote_state[3], remote_state[2], remote_state[1], remote_state[0]);
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
bool set_display_state(bool state)
switch_::Switch * display_switch_
uint8_t operation_settings_()
bool sleep_mode_allowed_() const
void control(const climate::ClimateCall &call) override
uint8_t operation_mode_()
bool set_sleep_mode_state(bool state)
void transmit_state() override
void parse_state_frame_(const uint8_t *frame)
select::Select * vertical_direction_select_
bool set_vertical_direction_state(VerticalDirection direction)
switch_::Switch * sleep_mode_switch_
ESPPreferenceObject settings_pref_
bool on_receive(remote_base::RemoteReceiveData data) override
This class is used to encode all control actions on a climate device.
ClimateMode mode
The active mode of the climate device.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
float target_temperature
The target temperature of the climate device.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
void publish_state()
Publish the state of the climate device, to be called from integrations.
RemoteTransmitterBase * transmitter_
void publish_state(const std::string &state)
void publish_state(bool state)
Publish a state to the front-end from the back-end.
@ VERTICAL_DIRECTION_DOWN
@ VERTICAL_DIRECTION_SWING
ESPHOME_LOG_TAG(TAG, "airton.climate")
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
constexpr uint8_t sum_bytes(const uint8_t *data, size_t len, uint8_t sum=0)
Add up the bytes of data with size len, truncated to 8 bits: the checksum many serial and IR protocol...
VerticalDirection vertical_direction