ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
hon_climate.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <queue>
5#ifdef USE_SENSOR
7#endif
8#ifdef USE_BINARY_SENSOR
10#endif
11#ifdef USE_TEXT_SENSOR
13#endif
14#ifdef USE_SWITCH
16#endif
18#include "haier_base.h"
19#include "hon_packet.h"
20
21namespace esphome::haier {
22
23enum class CleaningState : uint8_t {
24 NO_CLEANING = 0,
25 SELF_CLEAN = 1,
26 STERI_CLEAN = 2,
27};
28
30
37
39#ifdef USE_SENSOR
40 public:
59
60 protected:
61 void update_sub_sensor_(SubSensorType type, float value);
63#endif
64#ifdef USE_BINARY_SENSOR
65 public:
76
77 protected:
80#endif
81#ifdef USE_TEXT_SENSOR
82 public:
90
91 protected:
92 void update_sub_text_sensor_(SubTextSensorType type, const char *value);
94#endif
95#ifdef USE_SWITCH
96 public:
99
100 protected:
103#endif
104 public:
105 HonClimate();
106 HonClimate(const HonClimate &) = delete;
107 HonClimate &operator=(const HonClimate &) = delete;
108 ~HonClimate();
109 void dump_config() override;
110 void set_beeper_state(bool state);
111 bool get_beeper_state() const;
112 void set_quiet_mode_state(bool state);
113 bool get_quiet_mode_state() const;
114 esphome::optional<hon_protocol::VerticalSwingMode> get_vertical_airflow() const;
116 esphome::optional<hon_protocol::HorizontalSwingMode> get_horizontal_airflow() const;
118 const char *get_cleaning_status_text() const;
120 void start_self_cleaning();
125 void set_control_method(HonControlMethod method) { this->control_method_ = method; };
126 template<typename F> void add_alarm_start_callback(F &&callback) {
127 this->alarm_start_callback_.add(std::forward<F>(callback));
128 }
129 template<typename F> void add_alarm_end_callback(F &&callback) {
130 this->alarm_end_callback_.add(std::forward<F>(callback));
131 }
132 float get_active_alarm_count() const { return this->active_alarm_count_; }
133
134 protected:
135 void set_handlers() override;
136 void process_phase(std::chrono::steady_clock::time_point now) override;
137 haier_protocol::HaierMessage get_control_message() override;
138 haier_protocol::HaierMessage get_power_message(bool state) override;
139 void initialization() override;
140 bool prepare_pending_action() override;
141 void process_protocol_reset() override;
143
144 // Answers handlers
145 haier_protocol::HandlerError get_device_version_answer_handler_(haier_protocol::FrameType request_type,
146 haier_protocol::FrameType message_type,
147 const uint8_t *data, size_t data_size);
148 haier_protocol::HandlerError get_device_id_answer_handler_(haier_protocol::FrameType request_type,
149 haier_protocol::FrameType message_type,
150 const uint8_t *data, size_t data_size);
151 haier_protocol::HandlerError status_handler_(haier_protocol::FrameType request_type,
152 haier_protocol::FrameType message_type, const uint8_t *data,
153 size_t data_size);
154 haier_protocol::HandlerError get_management_information_answer_handler_(haier_protocol::FrameType request_type,
155 haier_protocol::FrameType message_type,
156 const uint8_t *data, size_t data_size);
157 haier_protocol::HandlerError get_alarm_status_answer_handler_(haier_protocol::FrameType request_type,
158 haier_protocol::FrameType message_type,
159 const uint8_t *data, size_t data_size);
160 haier_protocol::HandlerError alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer,
161 size_t size);
162 // Helper functions
163 haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
164 void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new);
167
168 static constexpr size_t HARDWARE_INFO_STR_SIZE = 9;
176
179 esphome::optional<hon_protocol::VerticalSwingMode> pending_vertical_direction_{};
180 esphome::optional<hon_protocol::HorizontalSwingMode> pending_horizontal_direction_{};
181 esphome::optional<HardwareInfo> hvac_hardware_info_{};
182 uint8_t active_alarms_[8];
189 std::queue<haier_protocol::HaierMessage> control_messages_queue_;
190 CallbackManager<void(uint8_t, const char *)> alarm_start_callback_{};
191 CallbackManager<void(uint8_t, const char *)> alarm_end_callback_{};
193 std::chrono::steady_clock::time_point last_alarm_request_;
196 esphome::optional<hon_protocol::VerticalSwingMode> current_vertical_swing_{};
197 esphome::optional<hon_protocol::HorizontalSwingMode> current_horizontal_swing_{};
201};
202
203} // namespace esphome::haier
Base class for all binary_sensor-type classes.
void set_quiet_mode_switch(switch_::Switch *sw)
esphome::optional< hon_protocol::VerticalSwingMode > get_vertical_airflow() const
ESPPreferenceObject hon_rtc_
void set_sub_text_sensor(SubTextSensorType type, text_sensor::TextSensor *sens)
haier_protocol::HandlerError status_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
HonControlMethod control_method_
void initialization() override
haier_protocol::HandlerError get_device_id_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
float get_active_alarm_count() const
CallbackManager< void(uint8_t, const char *)> alarm_end_callback_
void set_status_message_header_size(size_t size)
void set_extra_sensors_packet_bytes_size(size_t size)
esphome::optional< HardwareInfo > hvac_hardware_info_
void set_sub_sensor(SubSensorType type, sensor::Sensor *sens)
CallbackManager< void(uint8_t, const char *)> alarm_start_callback_
void update_sub_sensor_(SubSensorType type, float value)
void set_sub_binary_sensor(SubBinarySensorType type, binary_sensor::BinarySensor *sens)
haier_protocol::HaierMessage get_power_message(bool state) override
text_sensor::TextSensor * sub_text_sensors_[(size_t) SubTextSensorType::SUB_TEXT_SENSOR_TYPE_COUNT]
Definition hon_climate.h:93
haier_protocol::HandlerError get_alarm_status_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
switch_::Switch * beeper_switch_
std::chrono::steady_clock::time_point last_alarm_request_
sensor::Sensor * sub_sensors_[(size_t) SubSensorType::SUB_SENSOR_TYPE_COUNT]
Definition hon_climate.h:62
void set_beeper_state(bool state)
void set_horizontal_airflow(hon_protocol::HorizontalSwingMode direction)
haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size)
HonClimate & operator=(const HonClimate &)=delete
void set_vertical_airflow(hon_protocol::VerticalSwingMode direction)
CleaningState cleaning_status_
haier_protocol::HandlerError get_management_information_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
void set_control_method(HonControlMethod method)
std::queue< haier_protocol::HaierMessage > control_messages_queue_
esphome::optional< hon_protocol::HorizontalSwingMode > current_horizontal_swing_
void set_quiet_mode_state(bool state)
void add_alarm_end_callback(F &&callback)
void set_extra_control_packet_bytes_size(size_t size)
haier_protocol::HandlerError get_device_version_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
binary_sensor::BinarySensor * sub_binary_sensors_[(size_t) SubBinarySensorType::SUB_BINARY_SENSOR_TYPE_COUNT]
Definition hon_climate.h:79
haier_protocol::HandlerError alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer, size_t size)
const char * get_cleaning_status_text() const
void update_sub_binary_sensor_(SubBinarySensorType type, uint8_t value)
haier_protocol::HaierMessage get_control_message() override
void process_phase(std::chrono::steady_clock::time_point now) override
void add_alarm_start_callback(F &&callback)
esphome::optional< hon_protocol::HorizontalSwingMode > pending_horizontal_direction_
static constexpr size_t HARDWARE_INFO_STR_SIZE
bool get_quiet_mode_state() const
switch_::Switch * quiet_mode_switch_
HonClimate(const HonClimate &)=delete
void process_protocol_reset() override
CleaningState get_cleaning_status() const
esphome::optional< hon_protocol::HorizontalSwingMode > get_horizontal_airflow() const
void set_beeper_switch(switch_::Switch *sw)
esphome::optional< hon_protocol::VerticalSwingMode > current_vertical_swing_
void update_sub_text_sensor_(SubTextSensorType type, const char *value)
void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new)
bool prepare_pending_action() override
esphome::optional< hon_protocol::VerticalSwingMode > pending_vertical_direction_
Base-class for all sensors.
Definition sensor.h:47
Base class for all switches.
Definition switch.h:38
uint16_t type
FanDirection direction
Definition fan.h:5
bool state
Definition fan.h:2
uint16_t size
Definition helpers.cpp:25
char hardware_version_[HARDWARE_INFO_STR_SIZE]
char protocol_version_[HARDWARE_INFO_STR_SIZE]
char device_name_[HARDWARE_INFO_STR_SIZE]
char software_version_[HARDWARE_INFO_STR_SIZE]
hon_protocol::HorizontalSwingMode last_horizontal_swing
Definition hon_climate.h:33
hon_protocol::VerticalSwingMode last_vertiacal_swing
Definition hon_climate.h:32