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;
18 climate_ir::ClimateIR::setup();
23 this->publish_settings_();
27void AirtonClimate::publish_settings_() {
60 PUBLISH_STATE(this->sleep_mode_switch_,
state);
72 PUBLISH_STATE(this->display_switch_,
state);
85 PUBLISH_STATE(this->vertical_direction_select_,
static_cast<size_t>(
direction));
103 ClimateIR::control(
call);
114 uint8_t remote_state[AIRTON_STATE_FRAME_SIZE] = {
123 remote_state[6] =
checksum(remote_state);
125 ESP_LOGV(TAG,
"Sending: %02X %02X %02X %02X %02X %02X %02X", remote_state[6], remote_state[5], remote_state[4],
126 remote_state[3], remote_state[2], remote_state[1], remote_state[0]);
129 auto *data = transmit.get_data();
130 data->set_carrier_frequency(AIRTON_IR_FREQUENCY);
131 data->mark(AIRTON_HEADER_MARK);
132 data->space(AIRTON_HEADER_SPACE);
133 data->item_bytes<AIRTON_BIT_TIMINGS>(remote_state, AIRTON_STATE_FRAME_SIZE);
135 data->mark(AIRTON_BIT_MARK);
136 data->space(AIRTON_MESSAGE_SPACE);
142 uint8_t operating_mode = 0b1000;
143 switch (this->
mode) {
145 operating_mode |= AIRTON_MODE_COOL;
148 operating_mode |= AIRTON_MODE_DRY;
151 operating_mode |= AIRTON_MODE_HEAT;
154 operating_mode |= AIRTON_MODE_AUTO;
157 operating_mode |= AIRTON_MODE_FAN;
164 return operating_mode;
171 fan_speed = AIRTON_FAN_1;
174 fan_speed = AIRTON_FAN_3;
177 fan_speed = AIRTON_FAN_5;
181 fan_speed = AIRTON_FAN_AUTO;
187 switch (this->
mode) {
189 return AIRTON_AUTO_MODE_TEMP - AIRTON_TEMP_MIN;
191 return static_cast<uint8_t
>(roundf(clamp<float>(this->
target_temperature, AIRTON_TEMP_MIN, AIRTON_TEMP_MAX))) -
199 uint8_t settings = 0;
201 settings |= (1 << 4);
204 settings |= (1 << 7);
207 settings |= (1 << 1);
209 settings |= 0b01000000;
211 settings |= 0b00000100;
217 uint8_t
mode = frame[2];
220 if (
mode & 0b00001000) {
221 switch (
mode & 0b00000111) {
222 case AIRTON_MODE_COOL:
225 case AIRTON_MODE_DRY:
228 case AIRTON_MODE_HEAT:
231 case AIRTON_MODE_AUTO:
234 case AIRTON_MODE_FAN:
241 uint8_t
fan_mode = (frame[2] & 0b01110000) >> 4;
255 case AIRTON_FAN_AUTO:
264 const uint8_t
direction = frame[4] & 0b00001111;
268 ESP_LOGV(TAG,
"Unknown vertical direction %u",
direction);
277 uint8_t remote_state[AIRTON_STATE_FRAME_SIZE];
278 if (!data.expect_item(AIRTON_HEADER_MARK, AIRTON_HEADER_SPACE)) {
279 ESP_LOGV(TAG,
"Wrong header encoding detected!");
282 if (!data.expect_bytes<AIRTON_BIT_TIMINGS>(remote_state, AIRTON_STATE_FRAME_SIZE)) {
283 ESP_LOGV(TAG,
"Wrong modulation encoding");
287 if (remote_state[0] != AIRTON_HEADER_BYTE0 || remote_state[1] != AIRTON_HEADER_BYTE1) {
288 ESP_LOGV(TAG,
"Wrong header contents: %02X %02X", remote_state[1], remote_state[0]);
291 const uint8_t expected =
checksum(remote_state);
292 if (remote_state[AIRTON_STATE_FRAME_SIZE - 1] != expected) {
293 ESP_LOGV(TAG,
"Checksum error: calculated %02X, received %02X", expected,
294 remote_state[AIRTON_STATE_FRAME_SIZE - 1]);
297 ESP_LOGV(TAG,
"Received: %02X %02X %02X %02X %02X %02X %02X", remote_state[6], remote_state[5], remote_state[4],
298 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)
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)
bool set_vertical_direction_state(VerticalDirection direction)
SUB_SWITCH(sleep_mode) SUB_SWITCH(display) SUB_SELECT(vertical_direction) protected void save_settings_()
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_
@ 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