ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
mitsubishi_cn105.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <cmath>
7#include <span>
8
10
12
14 public:
15 enum class Mode : uint8_t {
16 HEAT,
17 DRY,
18 COOL,
20 AUTO,
21 UNKNOWN,
22 };
23
24 enum class FanMode : uint8_t {
25 AUTO,
26 QUIET,
27 SPEED_1,
28 SPEED_2,
29 SPEED_3,
30 SPEED_4,
31 UNKNOWN,
32 };
33
34 enum class VaneMode : uint8_t {
35 AUTO,
41 SWING,
42 UNKNOWN,
43 };
44
45 // Positions are numbered from the far left (1) to the far right (5).
46 enum class WideVaneMode : uint8_t {
47 POSITION_1, // far left
48 POSITION_2, // left
49 POSITION_3, // center
50 POSITION_4, // right
51 POSITION_5, // far right
52 SPLIT, // left and right
53 SWING,
54 UNKNOWN,
55 };
56
57 // Direction of the current run. 0x06 does not report it, so in AUTO it is inferred when the run starts.
63
64 struct Status {
66 float room_temperature{NAN};
67 bool power_on{false};
68 bool operating{false}; // held false while the unit winds down after a run ended
73 };
74
75 explicit MitsubishiCN105(uart::UARTDevice &device) : device_(device) {}
76
77 void initialize();
78 bool update();
79
81 void set_update_interval(uint32_t interval_ms) { this->update_interval_ms_ = interval_ms; }
82
86 this->telemetry_request_min_interval_ms_ = interval_ms;
87 }
88
89 const Status &status() const { return this->status_; }
90 bool is_status_initialized() const {
91 return this->is_telemetry_polling_enabled() ? !std::isnan(this->status_.room_temperature)
92 : !std::isnan(this->status_.target_temperature);
93 }
95
96 void set_power(bool power_on);
98 void set_mode(Mode mode);
100 void set_vane_mode(VaneMode vane_mode);
104 RunDirection run_direction() const { return this->run_direction_; }
105
106 protected:
120
122 public:
123 template<typename Callback> bool read_and_parse(uart::UARTDevice &device, Callback &&callback);
124 void reset() { read_pos_ = 0; }
125 static void dump_buffer_vv(const char *prefix, const uint8_t *data, size_t len);
126
127 protected:
128 void reset_and_dump_buffer_(const char *prefix);
129
130 private:
131 static constexpr size_t READ_BUFFER_SIZE = 32;
132 uint8_t read_buffer_[READ_BUFFER_SIZE];
133 uint8_t read_pos_{0};
134 };
135
136 enum class PropertyId : uint8_t {
137 TEMPERATURE = 0,
138 POWER = 1,
139 MODE = 2,
140 FAN = 3,
141 VANE = 4,
142 WIDE_VANE = 5,
144 };
145
146 struct UpdateFlags {
147 void set(PropertyId id) { this->mask_.insert(id); }
148 void clear(PropertyId id) { this->mask_.erase(id); }
149 bool any() const { return !this->mask_.empty(); }
150 bool contains(PropertyId id) const { return this->mask_.count(id); }
151 bool contains_only(PropertyId id) const { return this->mask_.get_mask() == Mask{id}.get_mask(); }
152
153 protected:
154 using Mask =
157 };
158
159 // An early refresh reads 0x06 after a mode or power change; it is spent until the next regular telemetry read.
165
168 bool set_wide_vane_high_bit : 1 {false};
169 };
170
171 friend struct Property;
172
173 void set_state_(State new_state);
174 void did_transition_(State to);
175 bool process_rx_packet_(uint8_t type, const uint8_t *payload, size_t len);
176 bool process_status_packet_(const uint8_t *payload, size_t len);
177 bool parse_status_payload_(uint8_t msg_type, const uint8_t *payload, size_t len);
178 void send_packet_(std::span<const uint8_t> packet);
179 void update_status_();
180 bool should_request_telemetry_() const;
182 bool is_early_telemetry_refresh_() const;
183 bool is_refresh_due_() const;
185 uint8_t next_status_msg_type_() const;
190 bool hold_if_run_ended_(bool was_on, Mode was_mode);
192 void update_run_direction_(bool was_operating);
193 void apply_settings_();
194 bool has_timed_out_(uint32_t timeout) const { return ((get_loop_time_ms() - this->operation_start_ms_) >= timeout); }
195 void set_remote_temperature_half_deg_(uint8_t temperature_half_deg);
196 static bool should_transition(State from, State to);
197 static const LogString *state_to_string(State state);
198
200 // Default 1s; legacy climate-owned hub compatibility relies on this when update_interval is omitted.
201 // Remove legacy note in 2027.2.0.
205 // Default 60s; legacy climate-owned hub compatibility relies on this when current_temperature_min_interval is
206 // omitted. Remove legacy note in 2027.2.0.
216
217 static constexpr uint8_t REMOTE_TEMPERATURE_DISABLED = 0;
219 bool status_changed_ : 1 {false};
220 bool has_telemetry_update_ : 1 {false}; // last_telemetry_update_ms_ is set
222 // Consecutive 0x06 timeouts; 0x06 is no longer requested once it reaches the maximum.
224 static constexpr uint8_t OPERATING_STATUS_MAX_MISSES = 3;
226 // Non-zero while a "running" 0x06 report is taken as wind-down from the previous mode or power state: one plus the
227 // number of 0x06 reads since the hold started. The last read was at wind_down_read_ms_.
228 uint8_t wind_down_reads_ : 4 {0};
229 // Power and mode before the first local change that has not been sent yet; the hold starts from what is sent.
230 bool unsent_from_power_on_ : 1 {false};
232 static constexpr uint8_t WIND_DOWN_HELD_READS = 9;
233};
234
235} // namespace esphome::mitsubishi_cn105
BedjetMode mode
BedJet operating mode.
constexpr size_t count(ValueType value) const
Check if the set contains a specific value (std::set compatibility) Returns 1 if present,...
constexpr bitmask_t get_mask() const
Get the raw bitmask value for optimized operations.
constexpr void insert(ValueType value)
Add a single value to the set (std::set compatibility)
constexpr void erase(ValueType value)
Remove a value from the set (std::set compatibility)
constexpr bool empty() const
Check if the set is empty.
bool read_and_parse(uart::UARTDevice &device, Callback &&callback)
static void dump_buffer_vv(const char *prefix, const uint8_t *data, size_t len)
void set_telemetry_request_min_interval(uint32_t interval_ms)
bool process_status_packet_(const uint8_t *payload, size_t len)
static bool should_transition(State from, State to)
static constexpr uint8_t OPERATING_STATUS_MAX_MISSES
void set_remote_temperature_half_deg_(uint8_t temperature_half_deg)
bool process_rx_packet_(uint8_t type, const uint8_t *payload, size_t len)
bool has_timed_out_(uint32_t timeout) const
static constexpr uint8_t REMOTE_TEMPERATURE_DISABLED
bool hold_if_run_ended_(bool was_on, Mode was_mode)
void send_packet_(std::span< const uint8_t > packet)
static const LogString * state_to_string(State state)
void set_target_temperature(float target_temperature)
bool parse_status_payload_(uint8_t msg_type, const uint8_t *payload, size_t len)
void set_update_interval(uint32_t interval_ms)
float target_temperature
Definition climate.h:0
ClimateFanMode fan_mode
Definition climate.h:3
uint8_t type
bool state
Definition fan.h:2
const void size_t len
Definition hal.h:68
constexpr uint32_t SCHEDULER_DONT_RUN
Definition component.h:63
static void uint32_t
Lightweight type-erased callback (8 bytes on 32-bit) that avoids std::function overhead.
Definition helpers.h:1893
uint16_t temperature
Definition sun_gtil2.cpp:12