ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
mitsubishi_cn105_swing_mode_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
6#include "mitsubishi_cn105.h"
7
9
10class SwingModeManager final {
11 public:
12 const climate::ClimateSwingModeMask &supported_swing_modes() const { return this->supported_swing_modes_; }
16
17 std::optional<MitsubishiCN105::VaneMode> vane_from(climate::ClimateSwingMode swing_mode) const {
18 if (!this->supported_swing_modes_.count(climate::CLIMATE_SWING_VERTICAL)) {
19 return std::nullopt;
20 }
21
22 switch (swing_mode) {
26 default:
27 return this->last_non_swing_vane_mode_;
28 }
29 }
30
31 std::optional<MitsubishiCN105::WideVaneMode> wide_vane_from(climate::ClimateSwingMode swing_mode) const {
32 if (!this->supported_swing_modes_.count(climate::CLIMATE_SWING_HORIZONTAL)) {
33 return std::nullopt;
34 }
35
36 switch (swing_mode) {
40 default:
41 return this->last_non_swing_wide_vane_mode_;
42 }
43 }
44
45 std::optional<climate::ClimateSwingMode> update_and_get_swing_mode(MitsubishiCN105::VaneMode vane_mode,
46 MitsubishiCN105::WideVaneMode wide_vane_mode) {
47 if (this->supported_swing_modes_.empty()) {
48 return std::nullopt;
49 }
50
51 bool vertical_swinging = false;
52 bool horizontal_swinging = false;
53 if (this->supported_swing_modes_.count(climate::CLIMATE_SWING_VERTICAL)) {
54 if (vane_mode == MitsubishiCN105::VaneMode::SWING) {
55 vertical_swinging = true;
56 } else if (vane_mode != MitsubishiCN105::VaneMode::UNKNOWN) {
57 this->last_non_swing_vane_mode_ = vane_mode;
58 }
59 }
60 if (this->supported_swing_modes_.count(climate::CLIMATE_SWING_HORIZONTAL)) {
61 if (wide_vane_mode == MitsubishiCN105::WideVaneMode::SWING) {
62 horizontal_swinging = true;
63 } else if (wide_vane_mode != MitsubishiCN105::WideVaneMode::UNKNOWN) {
64 this->last_non_swing_wide_vane_mode_ = wide_vane_mode;
65 }
66 }
67
68 if (vertical_swinging && horizontal_swinging) {
70 }
71 if (vertical_swinging) {
73 }
74 if (horizontal_swinging) {
76 }
78 }
79
80 private:
81 climate::ClimateSwingModeMask supported_swing_modes_{};
84};
85
86} // namespace esphome::mitsubishi_cn105
constexpr size_t count(ValueType value) const
Check if the set contains a specific value (std::set compatibility) Returns 1 if present,...
constexpr bool empty() const
Check if the set is empty.
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
ClimateSwingMode swing_mode
Definition climate.h:11
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.