ESPHome 2025.5.0
Loading...
Searching...
No Matches
hon_climate.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#ifdef USE_SENSOR
6#endif
7#ifdef USE_BINARY_SENSOR
9#endif
10#ifdef USE_TEXT_SENSOR
12#endif
13#ifdef USE_SWITCH
15#endif
17#include "haier_base.h"
18#include "hon_packet.h"
19
20namespace esphome {
21namespace 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 std::string &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;
118 std::string get_cleaning_status_text() const;
120 void start_self_cleaning();
125 void set_control_method(HonControlMethod method) { this->control_method_ = method; };
126 void add_alarm_start_callback(std::function<void(uint8_t, const char *)> &&callback);
127 void add_alarm_end_callback(std::function<void(uint8_t, const char *)> &&callback);
128 float get_active_alarm_count() const { return this->active_alarm_count_; }
129
130 protected:
131 void set_handlers() override;
132 void process_phase(std::chrono::steady_clock::time_point now) override;
133 haier_protocol::HaierMessage get_control_message() override;
134 haier_protocol::HaierMessage get_power_message(bool state) override;
135 void initialization() override;
136 bool prepare_pending_action() override;
137 void process_protocol_reset() override;
139
140 // Answers handlers
141 haier_protocol::HandlerError get_device_version_answer_handler_(haier_protocol::FrameType request_type,
142 haier_protocol::FrameType message_type,
143 const uint8_t *data, size_t data_size);
144 haier_protocol::HandlerError get_device_id_answer_handler_(haier_protocol::FrameType request_type,
145 haier_protocol::FrameType message_type,
146 const uint8_t *data, size_t data_size);
147 haier_protocol::HandlerError status_handler_(haier_protocol::FrameType request_type,
148 haier_protocol::FrameType message_type, const uint8_t *data,
149 size_t data_size);
150 haier_protocol::HandlerError get_management_information_answer_handler_(haier_protocol::FrameType request_type,
151 haier_protocol::FrameType message_type,
152 const uint8_t *data, size_t data_size);
153 haier_protocol::HandlerError get_alarm_status_answer_handler_(haier_protocol::FrameType request_type,
154 haier_protocol::FrameType message_type,
155 const uint8_t *data, size_t data_size);
156 haier_protocol::HandlerError alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer,
157 size_t size);
158 // Helper functions
159 haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
160 void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new);
163
165 std::string protocol_version_;
166 std::string software_version_;
167 std::string hardware_version_;
168 std::string device_name_;
169 bool functions_[5];
170 };
171
177 uint8_t active_alarms_[8];
184 std::queue<haier_protocol::HaierMessage> control_messages_queue_;
185 CallbackManager<void(uint8_t, const char *)> alarm_start_callback_{};
186 CallbackManager<void(uint8_t, const char *)> alarm_end_callback_{};
188 std::chrono::steady_clock::time_point last_alarm_request_;
195};
196
197class HaierAlarmStartTrigger : public Trigger<uint8_t, const char *> {
198 public:
201 [this](uint8_t alarm_code, const char *alarm_message) { this->trigger(alarm_code, alarm_message); });
202 }
203};
204
205class HaierAlarmEndTrigger : public Trigger<uint8_t, const char *> {
206 public:
209 [this](uint8_t alarm_code, const char *alarm_message) { this->trigger(alarm_code, alarm_message); });
210 }
211};
212
213} // namespace haier
214} // 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: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)
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:79
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:57
Base class for all switches.
Definition switch.h:39
uint8_t type
FanDirection direction
Definition fan.h:3
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
hon_protocol::HorizontalSwingMode last_horizontal_swing
Definition hon_climate.h:33
hon_protocol::VerticalSwingMode last_vertiacal_swing
Definition hon_climate.h:32