ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
delonghi.cpp
Go to the documentation of this file.
1#include "delonghi.h"
3
5
6static const char *const TAG = "delonghi.climate";
7
9 uint8_t remote_state[DELONGHI_STATE_FRAME_SIZE] = {0};
10 remote_state[0] = DELONGHI_ADDRESS;
11 remote_state[1] = this->temperature_();
12 remote_state[1] |= (this->fan_speed_()) << 5;
13 remote_state[2] = this->operation_mode_();
14 // Calculate checksum
15 for (int i = 0; i < DELONGHI_STATE_FRAME_SIZE - 1; i++) {
16 remote_state[DELONGHI_STATE_FRAME_SIZE - 1] += remote_state[i];
17 }
18
19 auto transmit = this->transmitter_->transmit();
20 auto *data = transmit.get_data();
21 data->set_carrier_frequency(DELONGHI_IR_FREQUENCY);
22
23 data->mark(DELONGHI_HEADER_MARK);
24 data->space(DELONGHI_HEADER_SPACE);
25 for (unsigned char b : remote_state) {
26 for (uint8_t mask = 1; mask > 0; mask <<= 1) { // iterate through bit mask
27 data->mark(DELONGHI_BIT_MARK);
28 bool bit = b & mask;
29 data->space(bit ? DELONGHI_ONE_SPACE : DELONGHI_ZERO_SPACE);
30 }
31 }
32 data->mark(DELONGHI_BIT_MARK);
33 data->space(0);
34
35 transmit.perform();
36}
37
39 uint8_t operating_mode = DELONGHI_MODE_ON;
40 switch (this->mode) {
42 operating_mode |= DELONGHI_MODE_COOL;
43 break;
45 operating_mode |= DELONGHI_MODE_DRY;
46 break;
48 operating_mode |= DELONGHI_MODE_HEAT;
49 break;
51 operating_mode |= DELONGHI_MODE_AUTO;
52 break;
54 operating_mode |= DELONGHI_MODE_FAN;
55 break;
57 default:
58 operating_mode = DELONGHI_MODE_OFF;
59 break;
60 }
61 return operating_mode;
62}
63
65 uint16_t fan_speed;
66 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
68 fan_speed = DELONGHI_FAN_LOW;
69 break;
71 fan_speed = DELONGHI_FAN_MEDIUM;
72 break;
74 fan_speed = DELONGHI_FAN_HIGH;
75 break;
77 default:
78 fan_speed = DELONGHI_FAN_AUTO;
79 }
80 return fan_speed;
81}
82
84 // Force special temperatures depending on the mode
85 uint8_t temperature = 0b0001;
86 switch (this->mode) {
88 temperature = (uint8_t) roundf(this->target_temperature) - DELONGHI_TEMP_OFFSET_HEAT;
89 break;
95 default:
96 temperature = (uint8_t) roundf(this->target_temperature) - DELONGHI_TEMP_OFFSET_COOL;
97 }
98 if (temperature > 0x0F) {
99 temperature = 0x0F; // clamp maximum
100 }
101 return temperature;
102}
103
104bool DelonghiClimate::parse_state_frame_(const uint8_t frame[]) {
105 uint8_t checksum = 0;
106 for (int i = 0; i < (DELONGHI_STATE_FRAME_SIZE - 1); i++) {
107 checksum += frame[i];
108 }
109 if (frame[DELONGHI_STATE_FRAME_SIZE - 1] != checksum) {
110 return false;
111 }
112 uint8_t mode = frame[2] & 0x0F;
113 if (mode & DELONGHI_MODE_ON) {
114 switch (mode & 0x0E) {
116 this->mode = climate::CLIMATE_MODE_COOL;
117 break;
119 this->mode = climate::CLIMATE_MODE_DRY;
120 break;
122 this->mode = climate::CLIMATE_MODE_HEAT;
123 break;
126 break;
129 break;
130 }
131 } else {
132 this->mode = climate::CLIMATE_MODE_OFF;
133 }
134 uint8_t temperature = frame[1] & 0x0F;
135 if (this->mode == climate::CLIMATE_MODE_HEAT) {
136 this->target_temperature = temperature + DELONGHI_TEMP_OFFSET_HEAT;
137 } else {
138 this->target_temperature = temperature + DELONGHI_TEMP_OFFSET_COOL;
139 }
140 uint8_t fan_mode = frame[1] >> 5;
141 switch (fan_mode) {
142 case DELONGHI_FAN_LOW:
143 this->fan_mode = climate::CLIMATE_FAN_LOW;
144 break;
146 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
147 break;
149 this->fan_mode = climate::CLIMATE_FAN_HIGH;
150 break;
152 this->fan_mode = climate::CLIMATE_FAN_AUTO;
153 break;
154 }
155 this->publish_state();
156 return true;
157}
158
160 uint8_t state_frame[DELONGHI_STATE_FRAME_SIZE] = {};
161 if (!data.expect_item(DELONGHI_HEADER_MARK, DELONGHI_HEADER_SPACE)) {
162 return false;
163 }
164 for (uint8_t pos = 0; pos < DELONGHI_STATE_FRAME_SIZE; pos++) {
165 uint8_t byte = 0;
166 for (int8_t bit = 0; bit < 8; bit++) {
167 if (data.expect_item(DELONGHI_BIT_MARK, DELONGHI_ONE_SPACE)) {
168 byte |= 1 << bit;
169 } else if (!data.expect_item(DELONGHI_BIT_MARK, DELONGHI_ZERO_SPACE)) {
170 return false;
171 }
172 }
173 state_frame[pos] = byte;
174 if (pos == 0) {
175 // frame header
176 if (byte != DELONGHI_ADDRESS) {
177 return false;
178 }
179 }
180 }
181 return this->parse_state_frame_(state_frame);
182}
183
184} // namespace esphome::delonghi
uint8_t checksum
Definition bl0906.h:3
ClimateMode mode
The active mode of the climate device.
Definition climate.h:293
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:287
float target_temperature
The target temperature of the climate device.
Definition climate.h:274
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:437
bool parse_state_frame_(const uint8_t frame[])
Definition delonghi.cpp:104
bool on_receive(remote_base::RemoteReceiveData data) override
Definition delonghi.cpp:159
@ 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 uint32_t DELONGHI_ONE_SPACE
Definition delonghi.h:36
const uint8_t DELONGHI_TEMP_OFFSET_COOL
Definition delonghi.h:13
const uint32_t DELONGHI_ZERO_SPACE
Definition delonghi.h:37
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
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
size_t size_t pos
Definition helpers.h:1038
uint16_t temperature
Definition sun_gtil2.cpp:12