ESPHome 2026.8.2
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
53void MitsubishiCN105Climate::dump_config() { LOG_CLIMATE("", "Mitsubishi CN105 Climate", this); }
54
56 this->parent_->add_on_status_callback([this]() { this->apply_values_(); });
57 if (this->parent_->is_status_initialized()) {
58 this->apply_values_();
59 }
60}
61
64
65 for (const auto &p : MODE_MAP) {
66 traits.add_supported_mode(p.second);
67 }
68
69 for (const auto &p : FAN_MODE_MAP) {
71 }
72
74
75 traits.set_visual_min_temperature(16.0f);
78
79 if (this->parent_->is_telemetry_polling_enabled()) {
82 }
83
84 return traits;
85}
86
88 if (const auto target_temperature = call.get_target_temperature()) {
89 this->parent_->set_target_temperature(*target_temperature);
90 }
91
92 if (const auto mode = call.get_mode()) {
94 this->parent_->set_power(false);
95 } else if (const auto mapped = reverse_map_lookup(MODE_MAP, *mode)) {
96 this->parent_->set_power(true);
97 this->parent_->set_mode(*mapped);
98 }
99 }
100
101 if (const auto fan_mode = reverse_map_lookup(FAN_MODE_MAP, call.get_fan_mode())) {
102 this->parent_->set_fan_mode(*fan_mode);
103 }
104
105 if (const auto swing_mode = call.get_swing_mode()) {
106 auto vane = this->last_non_swing_vane_mode_;
107 auto wide = this->last_non_swing_wide_vane_mode_;
108
109 switch (*swing_mode) {
113 break;
114
117 break;
118
121 break;
122
124 default:
125 break;
126 }
127
129 this->parent_->set_vane_mode(vane);
130 }
132 this->parent_->set_wide_vane_mode(wide);
133 }
134 }
135
136 this->parent_->publish_status();
137}
138
140 const auto &status = this->parent_->status();
141
142 this->target_temperature = status.target_temperature;
143
144 if (this->parent_->is_telemetry_polling_enabled()) {
145 this->current_temperature = status.room_temperature;
146 }
147
148 if (status.power_on) {
149 if (!map_lookup(MODE_MAP, status.mode, this->mode)) {
150 ESP_LOGD(TAG, "Unable to map mode");
151 }
152 } else {
154 }
155
157 if (map_lookup(FAN_MODE_MAP, status.fan_mode, fan_mode)) {
158 this->fan_mode = fan_mode;
159 } else {
160 ESP_LOGD(TAG, "Unable to map fan mode");
161 }
162
163 if (!this->supported_swing_modes_.empty()) {
164 bool vertical_swinging = false;
165 bool horizontal_swinging = false;
166
168 if (status.vane_mode == MitsubishiCN105::VaneMode::SWING) {
169 vertical_swinging = true;
170 } else if (status.vane_mode != MitsubishiCN105::VaneMode::UNKNOWN) {
171 this->last_non_swing_vane_mode_ = status.vane_mode;
172 }
173 }
174
176 if (status.wide_vane_mode == MitsubishiCN105::WideVaneMode::SWING) {
177 horizontal_swinging = true;
178 } else if (status.wide_vane_mode != MitsubishiCN105::WideVaneMode::UNKNOWN) {
179 this->last_non_swing_wide_vane_mode_ = status.wide_vane_mode;
180 }
181 }
182
183 if (vertical_swinging && horizontal_swinging) {
185 } else if (vertical_swinging) {
187 } else if (horizontal_swinging) {
189 } else {
191 }
192 }
193
194 this->publish_state();
195}
196
222
223} // 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)
@ 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.