ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
mitsubishi_cn105_climate.cpp
Go to the documentation of this file.
2
3#include "esphome/core/log.h"
4
6
7ESPHOME_LOG_TAG(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
53static constexpr climate::ClimateAction resolve_climate_action(climate::ClimateMode mode,
54 const MitsubishiCN105::Status &status,
56 if (!status.power_on) {
58 }
61 }
62 if (!status.operating) {
64 }
67 }
68 switch (direction) {
73 default:
75 }
76}
77
79 LOG_CLIMATE("", "Mitsubishi CN105 Climate", this);
80 ESP_LOGCONFIG(TAG, " Temperature unit: °%c",
81 this->parent_->get_temperature_mapping().get_use_fahrenheit() ? 'F' : 'C');
82}
83
85 this->parent_->add_on_status_callback([this]() { this->apply_values_(); });
86 if (this->parent_->is_status_initialized()) {
87 this->apply_values_();
88 }
89}
90
93
94 for (const auto &p : MODE_MAP) {
95 traits.add_supported_mode(p.second);
96 }
97
98 for (const auto &p : FAN_MODE_MAP) {
100 }
101
103
104 const bool use_fahrenheit = this->parent_->get_temperature_mapping().get_use_fahrenheit();
106 traits.set_visual_min_temperature(use_fahrenheit ? 61.0f : 16.0f);
107 traits.set_visual_max_temperature(use_fahrenheit ? 88.0f : 31.0f);
109
110 if (this->parent_->is_telemetry_polling_enabled()) {
112 traits.set_visual_current_temperature_step(use_fahrenheit ? 1.0f : 0.5f);
113 }
114
115 return traits;
116}
117
119 if (const auto target_temperature = call.get_target_temperature()) {
120 this->parent_->set_target_temperature(this->parent_->get_temperature_mapping().to_mitsubishi(*target_temperature));
121 }
122
123 if (const auto mode = call.get_mode()) {
125 this->parent_->set_power(false);
126 } else if (const auto mapped = reverse_map_lookup(MODE_MAP, *mode)) {
127 this->parent_->set_power(true);
128 this->parent_->set_mode(*mapped);
129 }
130 }
131
132 if (const auto fan_mode = reverse_map_lookup(FAN_MODE_MAP, call.get_fan_mode())) {
133 this->parent_->set_fan_mode(*fan_mode);
134 }
135
136 if (const auto swing_mode = call.get_swing_mode()) {
137 if (const auto vane = this->swing_mode_manager_.vane_from(*swing_mode)) {
138 this->parent_->set_vane_mode(*vane);
139 }
140 if (const auto wide = this->swing_mode_manager_.wide_vane_from(*swing_mode)) {
141 this->parent_->set_wide_vane_mode(*wide);
142 }
143 }
144
145 this->parent_->publish_status();
146}
147
149 const auto &status = this->parent_->status();
150
151 this->target_temperature = this->parent_->get_temperature_mapping().from_mitsubishi(status.target_temperature);
152
153 if (status.power_on) {
154 if (!map_lookup(MODE_MAP, status.mode, this->mode)) {
155 ESP_LOGD(TAG, "Unable to map mode");
156 }
157 } else {
158 this->mode = climate::CLIMATE_MODE_OFF;
159 }
160
161 if (this->parent_->is_telemetry_polling_enabled()) {
162 this->current_temperature = this->parent_->get_temperature_mapping().from_mitsubishi(status.room_temperature);
163 this->action = resolve_climate_action(this->mode, status, this->parent_->run_direction());
164 }
165
167 if (map_lookup(FAN_MODE_MAP, status.fan_mode, fan_mode)) {
168 this->fan_mode = fan_mode;
169 } else {
170 ESP_LOGD(TAG, "Unable to map fan mode");
171 }
172
173 if (const auto swing_mode =
174 this->swing_mode_manager_.update_and_get_swing_mode(status.vane_mode, status.wide_vane_mode)) {
175 this->swing_mode = *swing_mode;
176 }
177
178 this->publish_state();
179}
180
182 climate::ClimateSwingModeMask supported_swing_modes;
183 switch (mode) {
185 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
186 supported_swing_modes.insert(climate::CLIMATE_SWING_VERTICAL);
187 break;
188
190 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
191 supported_swing_modes.insert(climate::CLIMATE_SWING_HORIZONTAL);
192 break;
193
195 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
196 supported_swing_modes.insert(climate::CLIMATE_SWING_VERTICAL);
197 supported_swing_modes.insert(climate::CLIMATE_SWING_HORIZONTAL);
198 supported_swing_modes.insert(climate::CLIMATE_SWING_BOTH);
199 break;
200
202 default:
203 break;
204 }
205 this->swing_mode_manager_.set_supported_swing_modes(supported_swing_modes);
206}
207
208} // namespace esphome::mitsubishi_cn105
BedjetMode mode
BedJet operating mode.
uint8_t status
Definition bl0942.h:8
constexpr void insert(ValueType value)
Add a single value to the set (std::set compatibility)
This class is used to encode all control actions on a climate device.
Definition climate.h:31
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:317
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
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:323
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:291
ClimateAction action
The active state of the climate device.
Definition climate.h:320
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
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_temperature_unit(TemperatureUnit unit)
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_supported_swing_modes(const climate::ClimateSwingModeMask &supported_swing_modes)
std::optional< climate::ClimateSwingMode > update_and_get_swing_mode(MitsubishiCN105::VaneMode vane_mode, MitsubishiCN105::WideVaneMode wide_vane_mode)
const climate::ClimateSwingModeMask & supported_swing_modes() const
std::optional< MitsubishiCN105::WideVaneMode > wide_vane_from(climate::ClimateSwingMode swing_mode) const
std::optional< MitsubishiCN105::VaneMode > vane_from(climate::ClimateSwingMode swing_mode) const
const char * key
FanDirection direction
Definition fan.h:5
std::vector< uint8_t > & out
Definition gif.cpp:49
@ 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.
ClimateMode
Enum for all modes a climate device can be in.
@ 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.
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
@ CLIMATE_ACTION_OFF
The climate device is off (inactive or no power)
@ CLIMATE_ACTION_IDLE
The climate device is idle (monitoring climate but no action needed)
@ CLIMATE_ACTION_DRYING
The climate device is drying.
@ CLIMATE_ACTION_HEATING
The climate device is actively heating.
@ CLIMATE_ACTION_COOLING
The climate device is actively cooling.
@ CLIMATE_ACTION_FAN
The climate device is in fan only mode.
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.
ESPHOME_LOG_TAG(TAG, "mitsubishi_cn105.driver")
STL namespace.