ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
hon_climate.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <chrono>
5#include <queue>
6#ifdef USE_SENSOR
8#endif
9#ifdef USE_BINARY_SENSOR
11#endif
12#ifdef USE_TEXT_SENSOR
14#endif
15#ifdef USE_SWITCH
17#endif
18#ifdef USE_SELECT
20#endif
22#include "esphome/core/hal.h"
23#include "haier_base.h"
24#include "hon_packet.h"
25
26namespace esphome::haier {
27
28#ifdef USE_SELECT
29// Positions in the order the select platform lists them; in flash on ESP8266, so read with airflow_order_at()
36inline constexpr std::array<hon_protocol::HorizontalSwingMode, 5> HORIZONTAL_SWING_MODES_ORDER PROGMEM{
40};
41
42template<typename Mode, size_t N> Mode airflow_order_at(const std::array<Mode, N> &order, size_t index) {
43 static_assert(sizeof(Mode) == 1);
44 return static_cast<Mode>(progmem_read_byte(reinterpret_cast<const uint8_t *>(order.data() + index)));
45}
46#endif
47
48enum class CleaningState : uint8_t {
49 NO_CLEANING = 0,
50 SELF_CLEAN = 1,
51 STERI_CLEAN = 2,
52};
53
55
62
63class HonClimate final : public HaierClimateBase {
64#ifdef USE_SENSOR
65 public:
84
85 protected:
86 void update_sub_sensor_(SubSensorType type, float value);
88#endif
89#ifdef USE_BINARY_SENSOR
90 public:
101
102 protected:
105#endif
106#ifdef USE_TEXT_SENSOR
107 public:
115
116 protected:
117 void update_sub_text_sensor_(SubTextSensorType type, const char *value);
119#endif
120#ifdef USE_SWITCH
121 public:
124
125 protected:
128#endif
129#ifdef USE_SELECT
130 public:
133
134 protected:
138#endif
139 public:
140 HonClimate();
141 HonClimate(const HonClimate &) = delete;
142 HonClimate &operator=(const HonClimate &) = delete;
143 ~HonClimate();
144 void dump_config() override;
145 void set_beeper_state(bool state);
146 bool get_beeper_state() const;
147 void set_quiet_mode_state(bool state);
148 bool get_quiet_mode_state() const;
149 esphome::optional<hon_protocol::VerticalSwingMode> get_vertical_airflow() const;
151 esphome::optional<hon_protocol::HorizontalSwingMode> get_horizontal_airflow() const;
153 const char *get_cleaning_status_text() const;
155 void start_self_cleaning();
160 void set_control_method(HonControlMethod method) { this->control_method_ = method; };
161 template<typename F> void add_alarm_start_callback(F &&callback) {
162 this->alarm_start_callback_.add(std::forward<F>(callback));
163 }
164 template<typename F> void add_alarm_end_callback(F &&callback) {
165 this->alarm_end_callback_.add(std::forward<F>(callback));
166 }
167 float get_active_alarm_count() const { return this->active_alarm_count_; }
168
169 protected:
170 void set_handlers() override;
171 void process_phase(std::chrono::steady_clock::time_point now) override;
172 haier_protocol::HaierMessage get_control_message() override;
173 haier_protocol::HaierMessage get_power_message(bool state) override;
174 void initialization() override;
175 bool prepare_pending_action() override;
176 void process_protocol_reset() override;
178
179 // Answers handlers
180 haier_protocol::HandlerError get_device_version_answer_handler_(haier_protocol::FrameType request_type,
181 haier_protocol::FrameType message_type,
182 const uint8_t *data, size_t data_size);
183 haier_protocol::HandlerError get_device_id_answer_handler_(haier_protocol::FrameType request_type,
184 haier_protocol::FrameType message_type,
185 const uint8_t *data, size_t data_size);
186 haier_protocol::HandlerError status_handler_(haier_protocol::FrameType request_type,
187 haier_protocol::FrameType message_type, const uint8_t *data,
188 size_t data_size);
189 haier_protocol::HandlerError get_management_information_answer_handler_(haier_protocol::FrameType request_type,
190 haier_protocol::FrameType message_type,
191 const uint8_t *data, size_t data_size);
192 haier_protocol::HandlerError get_alarm_status_answer_handler_(haier_protocol::FrameType request_type,
193 haier_protocol::FrameType message_type,
194 const uint8_t *data, size_t data_size);
195 haier_protocol::HandlerError alarm_status_message_handler_(haier_protocol::FrameType type, const uint8_t *buffer,
196 size_t size);
197 // Helper functions
198 haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
199 void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new);
202
203 static constexpr size_t HARDWARE_INFO_STR_SIZE = 9;
211
214 esphome::optional<hon_protocol::VerticalSwingMode> pending_vertical_direction_{};
215 esphome::optional<hon_protocol::HorizontalSwingMode> pending_horizontal_direction_{};
216 esphome::optional<HardwareInfo> hvac_hardware_info_{};
217 uint8_t active_alarms_[8];
224 std::queue<haier_protocol::HaierMessage> control_messages_queue_;
225 CallbackManager<void(uint8_t, const char *)> alarm_start_callback_{};
226 CallbackManager<void(uint8_t, const char *)> alarm_end_callback_{};
228 std::chrono::steady_clock::time_point last_alarm_request_;
231 esphome::optional<hon_protocol::VerticalSwingMode> current_vertical_swing_{};
232 esphome::optional<hon_protocol::HorizontalSwingMode> current_horizontal_swing_{};
233 // millis() of the last user-set position per axis, 0 when none
239};
240
241} // 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)
select::Select * vertical_airflow_select_
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
void set_horizontal_airflow_select(select::Select *sel)
text_sensor::TextSensor * sub_text_sensors_[(size_t) SubTextSensorType::SUB_TEXT_SENSOR_TYPE_COUNT]
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:87
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)
uint32_t horizontal_direction_set_time_
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]
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)
select::Select * horizontal_airflow_select_
esphome::optional< hon_protocol::HorizontalSwingMode > pending_horizontal_direction_
static constexpr size_t HARDWARE_INFO_STR_SIZE
switch_::Switch * quiet_mode_switch_
HonClimate(const HonClimate &)=delete
void set_vertical_airflow_select(select::Select *sel)
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 selects.
Definition select.h:28
Base-class for all sensors.
Definition sensor.h:47
Base class for all switches.
Definition switch.h:43
uint8_t type
FanDirection direction
Definition fan.h:5
bool state
Definition fan.h:2
uint32_t buffer
Definition gif.cpp:50
Mode airflow_order_at(const std::array< Mode, N > &order, size_t index)
Definition hon_climate.h:42
constexpr std::array< hon_protocol::VerticalSwingMode, 7 > VERTICAL_SWING_MODES_ORDER PROGMEM
Definition hon_climate.h:30
uint16_t size
Definition helpers.cpp:34
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:51
static void uint32_t
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:58
hon_protocol::VerticalSwingMode last_vertiacal_swing
Definition hon_climate.h:57