ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
mitsubishi_cn105_component.h
Go to the documentation of this file.
1#pragma once
2
3#include "mitsubishi_cn105.h"
4
8
9#include <algorithm>
10#include <cmath>
11#include <optional>
12#include <utility>
13
15
17 float to_mitsubishi(float value) const {
18 if (!this->use_fahrenheit_) {
19 return value;
20 }
21 const int fahrenheit = std::clamp(static_cast<int>(std::round(value)), 61, 88);
22 return 0.5f * (fahrenheit - 28 + (fahrenheit > 68) - (fahrenheit < 68));
23 }
24
25 float from_mitsubishi(float value) const {
26 if (!this->use_fahrenheit_) {
27 return value;
28 }
29 if (value < 16.0f || value > 30.5f) {
30 return celsius_to_fahrenheit(value);
31 }
32 const int mitsubishi_half_degrees = static_cast<int>(std::round(value * 2.0f));
33 return mitsubishi_half_degrees + 29 - (mitsubishi_half_degrees >= 40) - (mitsubishi_half_degrees > 40);
34 }
35
36 bool get_use_fahrenheit() const { return this->use_fahrenheit_; }
37 void set_use_fahrenheit(bool value) { this->use_fahrenheit_ = value; }
38
39 protected:
40 bool use_fahrenheit_{false};
41};
42
53
61
63
64struct VaneCall {
65 struct Vertical {
67 const std::optional<VerticalVaneMode> &get_direction() const { return this->direction_; }
68
69 protected:
70 std::optional<VerticalVaneMode> direction_;
71 };
72
73 explicit VaneCall(MitsubishiCN105Component *parent) : parent_(parent) {}
74
76
77 void perform();
78
79 protected:
81};
82
84 public:
85 explicit MitsubishiCN105Component() : hp_(*this) {}
86
87 void setup() override;
88 void loop() override;
89 void dump_config() override;
90
94
97
98 void set_power(bool power_on) { this->hp_.set_power(power_on); }
99 void set_target_temperature(float target_temperature) { this->hp_.set_target_temperature(target_temperature); }
102 void set_vane_mode(MitsubishiCN105::VaneMode vane_mode) { this->hp_.set_vane_mode(vane_mode); }
104 VaneCall make_vane_call() { return VaneCall(this); }
105
106 const MitsubishiCN105::Status &status() const { return this->hp_.status(); }
107 bool is_status_initialized() const { return this->hp_.is_status_initialized(); }
110
111 template<typename F> void add_on_status_callback(F &&callback) {
112 this->status_callback_.add(std::forward<F>(callback));
113 }
114
115 template<typename F> void add_on_vane_state_callback(F &&callback) {
116 this->vane_state_callback_.add(std::forward<F>(callback));
117 }
118
120 if (this->is_status_initialized()) {
122 }
123 }
124
125 protected:
127 this->status_callback_.call();
129 .vertical = {.direction = static_cast<VerticalVaneMode>(this->status().vane_mode)},
130 });
131 }
132
137};
138
139} // namespace esphome::mitsubishi_cn105
BedjetMode mode
BedJet operating mode.
LazyCallbackManager< void(const VaneState &)> vane_state_callback_
void set_wide_vane_mode(MitsubishiCN105::WideVaneMode mode)
void set_vane_mode(MitsubishiCN105::VaneMode vane_mode)
void set_telemetry_request_min_interval(uint32_t interval_ms)
void set_target_temperature(float target_temperature)
void set_update_interval(uint32_t interval_ms)
float target_temperature
Definition climate.h:0
ClimateFanMode fan_mode
Definition climate.h:3
FanDirection direction
Definition fan.h:5
constexpr float celsius_to_fahrenheit(float value)
Convert degrees Celsius to degrees Fahrenheit.
Definition helpers.h:1653
static void uint32_t
const std::optional< VerticalVaneMode > & get_direction() const
VaneCall(MitsubishiCN105Component *parent)
uint16_t temperature
Definition sun_gtil2.cpp:12