ESPHome 2026.6.2
Loading...
Searching...
No Matches
mitsubishi_cn105_climate.cpp
Go to the documentation of this file.
1#include <cinttypes>
3#include "esphome/core/log.h"
4
6
7static const char *const TAG = "mitsubishi_cn105.climate";
8
9static constexpr std::array MODE_MAP{
15};
16
17static constexpr std::array FAN_MODE_MAP{
24};
25
26template<typename A, typename B, std::size_t N>
27static bool map_lookup(const std::array<std::pair<A, B>, N> &map, A key, B &out) {
28 for (const auto &[from, to] : map) {
29 if (from == key) {
30 out = to;
31 return true;
32 }
33 }
34 return false;
35}
36
37template<typename Left, typename Right, std::size_t N>
38static constexpr std::optional<Left> reverse_map_lookup(const std::array<std::pair<Left, Right>, N> &map, Right key) {
39 for (const auto &entry : map) {
40 if (entry.second == key) {
41 return entry.first;
42 }
43 }
44 return std::nullopt;
45}
46
47template<typename Left, typename Right, std::size_t N>
48static constexpr std::optional<Left> reverse_map_lookup(const std::array<std::pair<Left, Right>, N> &map,
49 const std::optional<Right> &key) {
50 return key.has_value() ? reverse_map_lookup(map, *key) : std::nullopt;
51}
52
54 LOG_CLIMATE("", "Mitsubishi CN105 Climate", this);
55 if (this->hp_.is_room_temperature_enabled()) {
56 ESP_LOGCONFIG(TAG, " Current temperature min interval: %" PRIu32 " ms",
58 } else {
59 ESP_LOGCONFIG(TAG, " Current temperature: DISABLED");
60 }
61 ESP_LOGCONFIG(TAG,
62 " Update interval: %" PRIu32 " ms\n"
63 " UART: baud_rate=%" PRIu32 " data_bits=%u parity=%s stop_bits=%u",
64 this->hp_.get_update_interval(), this->parent_->get_baud_rate(), this->parent_->get_data_bits(),
65 LOG_STR_ARG(parity_to_str(this->parent_->get_parity())), this->parent_->get_stop_bits());
66}
67
69
71 if (this->hp_.update()) {
72 this->apply_values_();
73 }
74}
75
100
102 if (const auto target_temperature = call.get_target_temperature()) {
104 }
105
106 if (const auto mode = call.get_mode()) {
108 this->hp_.set_power(false);
109 } else if (const auto mapped = reverse_map_lookup(MODE_MAP, *mode)) {
110 this->hp_.set_power(true);
111 this->hp_.set_mode(*mapped);
112 }
113 }
114
115 if (const auto fan_mode = reverse_map_lookup(FAN_MODE_MAP, call.get_fan_mode())) {
116 this->hp_.set_fan_mode(*fan_mode);
117 }
118
119 if (const auto swing_mode = call.get_swing_mode()) {
120 auto vane = this->last_non_swing_vane_mode_;
121 auto wide = this->last_non_swing_wide_vane_mode_;
122
123 switch (*swing_mode) {
127 break;
128
131 break;
132
135 break;
136
138 default:
139 break;
140 }
141
143 this->hp_.set_vane_mode(vane);
144 }
146 this->hp_.set_wide_vane_mode(wide);
147 }
148 }
149
150 if (this->hp_.is_status_initialized()) {
151 this->apply_values_();
152 }
153}
154
156 const auto &status = this->hp_.status();
157
158 this->target_temperature = status.target_temperature;
159
160 if (this->hp_.is_room_temperature_enabled()) {
161 this->current_temperature = status.room_temperature;
162 }
163
164 if (status.power_on) {
165 if (!map_lookup(MODE_MAP, status.mode, this->mode)) {
166 ESP_LOGD(TAG, "Unable to map mode");
167 }
168 } else {
170 }
171
173 if (map_lookup(FAN_MODE_MAP, status.fan_mode, fan_mode)) {
174 this->fan_mode = fan_mode;
175 } else {
176 ESP_LOGD(TAG, "Unable to map fan mode");
177 }
178
179 if (!this->supported_swing_modes_.empty()) {
180 bool vertical_swinging = false;
181 bool horizontal_swinging = false;
182
184 if (status.vane_mode == MitsubishiCN105::VaneMode::SWING) {
185 vertical_swinging = true;
186 } else if (status.vane_mode != MitsubishiCN105::VaneMode::UNKNOWN) {
187 this->last_non_swing_vane_mode_ = status.vane_mode;
188 }
189 }
190
192 if (status.wide_vane_mode == MitsubishiCN105::WideVaneMode::SWING) {
193 horizontal_swinging = true;
194 } else if (status.wide_vane_mode != MitsubishiCN105::WideVaneMode::UNKNOWN) {
195 this->last_non_swing_wide_vane_mode_ = status.wide_vane_mode;
196 }
197 }
198
199 if (vertical_swinging && horizontal_swinging) {
201 } else if (vertical_swinging) {
203 } else if (horizontal_swinging) {
205 } else {
207 }
208 }
209
210 this->publish_state();
211}
212
238
239} // namespace esphome::mitsubishi_cn105
BedjetMode mode
BedJet operating mode.
uint8_t status
Definition bl0942.h:8
constexpr size_t count(ValueType value) const
Check if the set contains a specific value (std::set compatibility) Returns 1 if present,...
constexpr void clear()
Clear all values from the set.
constexpr void insert(ValueType value)
Add a single value to the set (std::set compatibility)
constexpr bool empty() const
Check if the set is empty.
This class is used to encode all control actions on a climate device.
Definition climate.h:34
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:314
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:312
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
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:299
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:267
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:437
void set_visual_max_temperature(float visual_max_temperature)
void add_feature_flags(uint32_t feature_flags)
void add_supported_fan_mode(ClimateFanMode mode)
void set_visual_temperature_step(float temperature_step)
void set_supported_swing_modes(ClimateSwingModeMask modes)
void set_visual_min_temperature(float visual_min_temperature)
void set_visual_current_temperature_step(float temperature_step)
void add_supported_mode(ClimateMode mode)
void control(const climate::ClimateCall &call) override
void set_supported_swing_mode(climate::ClimateSwingMode mode)
void set_target_temperature(float target_temperature)
UARTParityOptions get_parity() const
UARTComponent * parent_
Definition uart.h:73
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ 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.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ 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_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.