ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
delonghi.cpp
Go to the documentation of this file.
1#include "delonghi.h"
4
6
7ESPHOME_LOG_TAG(TAG, "delonghi.climate");
8
10 uint8_t remote_state[DELONGHI_STATE_FRAME_SIZE] = {0};
11 remote_state[0] = DELONGHI_ADDRESS;
12 remote_state[1] = this->temperature_();
13 remote_state[1] |= (this->fan_speed_()) << 5;
14 remote_state[2] = this->operation_mode_();
15 // Calculate checksum
16 for (int i = 0; i < DELONGHI_STATE_FRAME_SIZE - 1; i++) {
17 remote_state[DELONGHI_STATE_FRAME_SIZE - 1] += remote_state[i];
18 }
19
20 auto transmit = this->transmitter_->transmit();
21 auto *data = transmit.get_data();
22 data->set_carrier_frequency(DELONGHI_IR_FREQUENCY);
23
24 data->mark(DELONGHI_HEADER_MARK);
25 data->space(DELONGHI_HEADER_SPACE);
26 data->item_bytes<DELONGHI_BIT_TIMINGS>(remote_state, DELONGHI_STATE_FRAME_SIZE);
27 data->mark(DELONGHI_BIT_MARK);
28 data->space(0);
29
30 transmit.perform();
31}
32
34 uint8_t operating_mode = DELONGHI_MODE_ON;
35 switch (this->mode) {
37 operating_mode |= DELONGHI_MODE_COOL;
38 break;
40 operating_mode |= DELONGHI_MODE_DRY;
41 break;
43 operating_mode |= DELONGHI_MODE_HEAT;
44 break;
46 operating_mode |= DELONGHI_MODE_AUTO;
47 break;
49 operating_mode |= DELONGHI_MODE_FAN;
50 break;
52 default:
53 operating_mode = DELONGHI_MODE_OFF;
54 break;
55 }
56 return operating_mode;
57}
58
60 uint16_t fan_speed;
61 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
63 fan_speed = DELONGHI_FAN_LOW;
64 break;
66 fan_speed = DELONGHI_FAN_MEDIUM;
67 break;
69 fan_speed = DELONGHI_FAN_HIGH;
70 break;
72 default:
73 fan_speed = DELONGHI_FAN_AUTO;
74 }
75 return fan_speed;
76}
77
79 // Force special temperatures depending on the mode
80 uint8_t temperature = 0b0001;
81 switch (this->mode) {
83 temperature = (uint8_t) roundf(this->target_temperature) - DELONGHI_TEMP_OFFSET_HEAT;
84 break;
90 default:
91 temperature = (uint8_t) roundf(this->target_temperature) - DELONGHI_TEMP_OFFSET_COOL;
92 }
93 if (temperature > 0x0F) {
94 temperature = 0x0F; // clamp maximum
95 }
96 return temperature;
97}
98
99bool DelonghiClimate::parse_state_frame_(const uint8_t frame[]) {
100 const uint8_t checksum = sum_bytes(frame, DELONGHI_STATE_FRAME_SIZE - 1);
101 if (frame[DELONGHI_STATE_FRAME_SIZE - 1] != checksum) {
102 return false;
103 }
104 uint8_t mode = frame[2] & 0x0F;
105 if (mode & DELONGHI_MODE_ON) {
106 switch (mode & 0x0E) {
108 this->mode = climate::CLIMATE_MODE_COOL;
109 break;
111 this->mode = climate::CLIMATE_MODE_DRY;
112 break;
114 this->mode = climate::CLIMATE_MODE_HEAT;
115 break;
118 break;
121 break;
122 }
123 } else {
124 this->mode = climate::CLIMATE_MODE_OFF;
125 }
126 uint8_t temperature = frame[1] & 0x0F;
127 if (this->mode == climate::CLIMATE_MODE_HEAT) {
128 this->target_temperature = temperature + DELONGHI_TEMP_OFFSET_HEAT;
129 } else {
130 this->target_temperature = temperature + DELONGHI_TEMP_OFFSET_COOL;
131 }
132 uint8_t fan_mode = frame[1] >> 5;
133 switch (fan_mode) {
134 case DELONGHI_FAN_LOW:
135 this->fan_mode = climate::CLIMATE_FAN_LOW;
136 break;
138 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
139 break;
141 this->fan_mode = climate::CLIMATE_FAN_HIGH;
142 break;
144 this->fan_mode = climate::CLIMATE_FAN_AUTO;
145 break;
146 default:
147 break;
148 }
149 this->publish_state();
150 return true;
151}
152
154 uint8_t state_frame[DELONGHI_STATE_FRAME_SIZE];
155 if (!data.expect_item(DELONGHI_HEADER_MARK, DELONGHI_HEADER_SPACE)) {
156 return false;
157 }
158 if (!data.expect_bytes<DELONGHI_BIT_TIMINGS>(state_frame, DELONGHI_STATE_FRAME_SIZE) ||
159 state_frame[0] != DELONGHI_ADDRESS)
160 return false;
161 return this->parse_state_frame_(state_frame);
162}
163
164} // namespace esphome::delonghi
uint8_t checksum
Definition bl0906.h:3
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:311
float target_temperature
The target temperature of the climate device.
Definition climate.h:298
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
bool parse_state_frame_(const uint8_t frame[])
Definition delonghi.cpp:99
bool on_receive(remote_base::RemoteReceiveData data) override
Definition delonghi.cpp:153
@ 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_ON
The fan mode is set to On.
@ 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.
const uint32_t DELONGHI_HEADER_SPACE
Definition delonghi.h:34
const uint8_t DELONGHI_FAN_HIGH
Definition delonghi.h:27
const uint32_t DELONGHI_BIT_MARK
Definition delonghi.h:35
const uint8_t DELONGHI_FAN_AUTO
Definition delonghi.h:26
const uint8_t DELONGHI_MODE_ON
Definition delonghi.h:23
const uint8_t DELONGHI_TEMP_OFFSET_COOL
Definition delonghi.h:13
const uint8_t DELONGHI_MODE_DRY
Definition delonghi.h:20
const uint8_t DELONGHI_MODE_COOL
Definition delonghi.h:18
const uint8_t DELONGHI_FAN_MEDIUM
Definition delonghi.h:28
ESPHOME_LOG_TAG(TAG, "delonghi.climate")
const uint8_t DELONGHI_TEMP_OFFSET_HEAT
Definition delonghi.h:14
const uint32_t DELONGHI_IR_FREQUENCY
Definition delonghi.h:32
const uint8_t DELONGHI_MODE_FAN
Definition delonghi.h:21
const uint8_t DELONGHI_FAN_LOW
Definition delonghi.h:29
const uint8_t DELONGHI_STATE_FRAME_SIZE
Definition delonghi.h:40
const uint8_t DELONGHI_ADDRESS
Definition delonghi.h:8
const uint32_t DELONGHI_HEADER_MARK
Definition delonghi.h:33
const uint8_t DELONGHI_MODE_AUTO
Definition delonghi.h:17
const uint8_t DELONGHI_MODE_HEAT
Definition delonghi.h:19
const uint8_t DELONGHI_MODE_OFF
Definition delonghi.h:22
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...
Definition helpers.h:894
uint16_t temperature
Definition sun_gtil2.cpp:12