ESPHome 2026.4.0
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
108
110 if (const auto target_temperature = call.get_target_temperature()) {
112 }
113
114 if (const auto mode = call.get_mode()) {
116 this->hp_.set_power(false);
117 } else if (const auto mapped = reverse_map_lookup(MODE_MAP, *mode)) {
118 this->hp_.set_power(true);
119 this->hp_.set_mode(*mapped);
120 }
121 }
122
123 if (const auto fan_mode = reverse_map_lookup(FAN_MODE_MAP, call.get_fan_mode())) {
124 this->hp_.set_fan_mode(*fan_mode);
125 }
126
127 if (this->hp_.is_status_initialized()) {
128 this->apply_values_();
129 }
130}
131
133 const auto &status = this->hp_.status();
134
135 this->target_temperature = status.target_temperature;
136
137 if (this->hp_.is_room_temperature_enabled()) {
138 this->current_temperature = status.room_temperature;
139 }
140
141 if (status.power_on) {
142 if (!map_lookup(MODE_MAP, status.mode, this->mode)) {
143 ESP_LOGD(TAG, "Unable to map mode");
144 }
145 } else {
147 }
148
150 if (map_lookup(FAN_MODE_MAP, status.fan_mode, fan_mode)) {
151 this->fan_mode = fan_mode;
152 } else {
153 ESP_LOGD(TAG, "Unable to map fan mode");
154 }
155
156 this->publish_state();
157}
158
159} // namespace esphome::mitsubishi_cn105
uint8_t status
Definition bl0942.h:8
This class is used to encode all control actions on a climate device.
Definition climate.h:34
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
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:436
void set_visual_max_temperature(float visual_max_temperature)
void add_feature_flags(uint32_t feature_flags)
void set_visual_temperature_step(float temperature_step)
void set_visual_min_temperature(float visual_min_temperature)
void set_visual_current_temperature_step(float temperature_step)
void set_supported_modes(ClimateModeMask modes)
void set_supported_fan_modes(ClimateFanModeMask modes)
void control(const climate::ClimateCall &call) override
void set_target_temperature(float target_temperature)
UARTParityOptions get_parity() const
UARTComponent * parent_
Definition uart.h:73
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ 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_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
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.