ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
mitsubishi_cn105_climate.cpp
Go to the documentation of this file.
2
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 ESP_LOGCONFIG(TAG, " Temperature unit: °%c",
56 this->parent_->get_temperature_mapping().get_use_fahrenheit() ? 'F' : 'C');
57}
58
60 this->parent_->add_on_status_callback([this]() { this->apply_values_(); });
61 if (this->parent_->is_status_initialized()) {
62 this->apply_values_();
63 }
64}
65
68
69 for (const auto &p : MODE_MAP) {
70 traits.add_supported_mode(p.second);
71 }
72
73 for (const auto &p : FAN_MODE_MAP) {
75 }
76
78
79 const bool use_fahrenheit = this->parent_->get_temperature_mapping().get_use_fahrenheit();
81 traits.set_visual_min_temperature(use_fahrenheit ? 61.0f : 16.0f);
82 traits.set_visual_max_temperature(use_fahrenheit ? 88.0f : 31.0f);
84
85 if (this->parent_->is_telemetry_polling_enabled()) {
87 traits.set_visual_current_temperature_step(use_fahrenheit ? 1.0f : 0.5f);
88 }
89
90 return traits;
91}
92
94 if (const auto target_temperature = call.get_target_temperature()) {
95 this->parent_->set_target_temperature(this->parent_->get_temperature_mapping().to_mitsubishi(*target_temperature));
96 }
97
98 if (const auto mode = call.get_mode()) {
100 this->parent_->set_power(false);
101 } else if (const auto mapped = reverse_map_lookup(MODE_MAP, *mode)) {
102 this->parent_->set_power(true);
103 this->parent_->set_mode(*mapped);
104 }
105 }
106
107 if (const auto fan_mode = reverse_map_lookup(FAN_MODE_MAP, call.get_fan_mode())) {
108 this->parent_->set_fan_mode(*fan_mode);
109 }
110
111 if (const auto swing_mode = call.get_swing_mode()) {
112 if (const auto vane = this->swing_mode_manager_.vane_from(*swing_mode)) {
113 this->parent_->set_vane_mode(*vane);
114 }
115 if (const auto wide = this->swing_mode_manager_.wide_vane_from(*swing_mode)) {
116 this->parent_->set_wide_vane_mode(*wide);
117 }
118 }
119
120 this->parent_->publish_status();
121}
122
124 const auto &status = this->parent_->status();
125
126 this->target_temperature = this->parent_->get_temperature_mapping().from_mitsubishi(status.target_temperature);
127
128 if (this->parent_->is_telemetry_polling_enabled()) {
129 this->current_temperature = this->parent_->get_temperature_mapping().from_mitsubishi(status.room_temperature);
130 }
131
132 if (status.power_on) {
133 if (!map_lookup(MODE_MAP, status.mode, this->mode)) {
134 ESP_LOGD(TAG, "Unable to map mode");
135 }
136 } else {
138 }
139
141 if (map_lookup(FAN_MODE_MAP, status.fan_mode, fan_mode)) {
142 this->fan_mode = fan_mode;
143 } else {
144 ESP_LOGD(TAG, "Unable to map fan mode");
145 }
146
147 if (const auto swing_mode =
148 this->swing_mode_manager_.update_and_get_swing_mode(status.vane_mode, status.wide_vane_mode)) {
149 this->swing_mode = *swing_mode;
150 }
151
152 this->publish_state();
153}
154
156 climate::ClimateSwingModeMask supported_swing_modes;
157 switch (mode) {
159 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
160 supported_swing_modes.insert(climate::CLIMATE_SWING_VERTICAL);
161 break;
162
164 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
165 supported_swing_modes.insert(climate::CLIMATE_SWING_HORIZONTAL);
166 break;
167
169 supported_swing_modes.insert(climate::CLIMATE_SWING_OFF);
170 supported_swing_modes.insert(climate::CLIMATE_SWING_VERTICAL);
171 supported_swing_modes.insert(climate::CLIMATE_SWING_HORIZONTAL);
172 supported_swing_modes.insert(climate::CLIMATE_SWING_BOTH);
173 break;
174
176 default:
177 break;
178 }
179 this->swing_mode_manager_.set_supported_swing_modes(supported_swing_modes);
180}
181
182} // 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: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:304
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:298
float target_temperature
The target temperature of the climate device.
Definition climate.h:285
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:310
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:278
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_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
@ 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.
STL namespace.