ESPHome 2026.3.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 {
22namespace haier {
23
24enum class CleaningState : uint8_t {
25 NO_CLEANING = 0,
26 SELF_CLEAN = 1,
27 STERI_CLEAN = 2,
28};
29
31
38
40#ifdef USE_SENSOR
41 public:
60
61 protected:
62 void update_sub_sensor_(SubSensorType type, float value);
64#endif
65#ifdef USE_BINARY_SENSOR
66 public:
77
78 protected:
81#endif
82#ifdef USE_TEXT_SENSOR
83 public:
91
92 protected:
93 void update_sub_text_sensor_(SubTextSensorType type, const std::string &value);
95#endif
96#ifdef USE_SWITCH
97 public:
100
101 protected:
104#endif
105 public:
106 HonClimate();
107 HonClimate(const HonClimate &) = delete;
108 HonClimate &operator=(const HonClimate &) = delete;
109 ~HonClimate();
110 void dump_config() override;
111 void set_beeper_state(bool state);
112 bool get_beeper_state() const;
113 void set_quiet_mode_state(bool state);
114 bool get_quiet_mode_state() const;
119 std::string get_cleaning_status_text() const;
121 void start_self_cleaning();
126 void set_control_method(HonControlMethod method) { this->control_method_ = method; };
127 void add_alarm_start_callback(std::function<void(uint8_t, const char *)> &&callback);
128 void add_alarm_end_callback(std::function<void(uint8_t, const char *)> &&callback);
129 float get_active_alarm_count() const { return this->active_alarm_count_; }
130
131 protected:
132 void set_handlers() override;
133 void process_phase(std::chrono::steady_clock::time_point now) override;
134 haier_protocol::HaierMessage get_control_message() override;
135 haier_protocol::HaierMessage get_power_message(bool state) override;
136 void initialization() override;
137 bool prepare_pending_action() override;
138 void process_protocol_reset() override;
140
141 // Answers handlers
142 haier_protocol::HandlerError get_device_version_answer_handler_(haier_protocol::FrameType request_type,
143 haier_protocol::FrameType message_type,
144 const uint8_t *data, size_t data_size);
145 haier_protocol::HandlerError get_device_id_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 status_handler_(haier_protocol::FrameType request_type,
149 haier_protocol::FrameType message_type, const uint8_t *data,
150 size_t data_size);
151 haier_protocol::HandlerError get_management_information_answer_handler_(haier_protocol::FrameType request_type,
152 haier_protocol::FrameType message_type,
153 const uint8_t *data, size_t data_size);
154 haier_protocol::HandlerError get_alarm_status_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 alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer,
158 size_t size);
159 // Helper functions
160 haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
161 void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new);
164
166 std::string protocol_version_;
167 std::string software_version_;
168 std::string hardware_version_;
169 std::string device_name_;
170 bool functions_[5];
171 };
172
178 uint8_t active_alarms_[8];
185 std::queue<haier_protocol::HaierMessage> control_messages_queue_;
186 CallbackManager<void(uint8_t, const char *)> alarm_start_callback_{};
187 CallbackManager<void(uint8_t, const char *)> alarm_end_callback_{};
189 std::chrono::steady_clock::time_point last_alarm_request_;
196};
197
198class HaierAlarmStartTrigger : public Trigger<uint8_t, const char *> {
199 public:
202 [this](uint8_t alarm_code, const char *alarm_message) { this->trigger(alarm_code, alarm_message); });
203 }
204};
205
206class HaierAlarmEndTrigger : public Trigger<uint8_t, const char *> {
207 public:
210 [this](uint8_t alarm_code, const char *alarm_message) { this->trigger(alarm_code, alarm_message); });
211 }
212};
213
214} // namespace haier
215} // namespace esphome
Base class for all binary_sensor-type classes.
HaierAlarmEndTrigger(HonClimate *parent)
HaierAlarmStartTrigger(HonClimate *parent)
void set_quiet_mode_switch(switch_::Switch *sw)
esphome::optional< hon_protocol::VerticalSwingMode > get_vertical_airflow() const
void add_alarm_end_callback(std::function< void(uint8_t, const char *)> &&callback)
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:94
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:63
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)
void add_alarm_start_callback(std::function< void(uint8_t, const char *)> &&callback)
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 set_extra_control_packet_bytes_size(size_t size)
void update_sub_text_sensor_(SubTextSensorType type, const std::string &value)
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:80
haier_protocol::HandlerError alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer, size_t size)
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
esphome::optional< hon_protocol::HorizontalSwingMode > pending_horizontal_direction_
bool get_quiet_mode_state() const
switch_::Switch * quiet_mode_switch_
HonClimate(const HonClimate &)=delete
std::string get_cleaning_status_text() const
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 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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
size_t size
Definition helpers.h:854
hon_protocol::HorizontalSwingMode last_horizontal_swing
Definition hon_climate.h:34
hon_protocol::VerticalSwingMode last_vertiacal_swing
Definition hon_climate.h:33