23PROGMEM_STRING_TABLE(ProtocolPhaseStrings,
"SENDING_INIT_1",
"SENDING_INIT_2",
"SENDING_FIRST_STATUS_REQUEST",
24 "SENDING_FIRST_ALARM_STATUS_REQUEST",
"IDLE",
"SENDING_STATUS_REQUEST",
25 "SENDING_UPDATE_SIGNAL_REQUEST",
"SENDING_SIGNAL_LEVEL",
"SENDING_CONTROL",
26 "SENDING_ACTION_COMMAND",
"SENDING_ALARM_STATUS_REQUEST",
"UNKNOWN");
30 "ProtocolPhaseStrings must match the enum ProtocolPhases, with UNKNOWN last");
32 return ProtocolPhaseStrings::get_log_str(
static_cast<uint8_t
>(phase), ProtocolPhaseStrings::LAST_INDEX);
35bool check_timeout(std::chrono::steady_clock::time_point now, std::chrono::steady_clock::time_point tpoint,
37 return std::chrono::duration_cast<std::chrono::milliseconds>(now - tpoint).count() > timeout;
41 : haier_protocol_(*this),
43 force_send_control_(false),
44 forced_request_status_(false),
45 reset_protocol_request_(false),
46 send_wifi_signal_(true),
101 static uint8_t wifi_status_data[4] = {0x00, 0x00, 0x00, 0x00};
103 wifi_status_data[1] = 0;
105 wifi_status_data[3] = uint8_t((128 + rssi) / 1.28f);
106 ESP_LOGD(TAG,
"WiFi signal is: %ddBm => %d%%", rssi, wifi_status_data[3]);
108 ESP_LOGD(TAG,
"WiFi is not connected");
109 wifi_status_data[1] = 1;
110 wifi_status_data[3] = 0;
112 return haier_protocol::HaierMessage(haier_protocol::FrameType::REPORT_NETWORK_STATUS, wifi_status_data,
113 sizeof(wifi_status_data));
120 ESP_LOGW(TAG,
"Failed to save settings");
179 if (!presets.
empty())
188 haier_protocol::FrameType request_message_type, haier_protocol::FrameType expected_request_message_type,
189 haier_protocol::FrameType answer_message_type, haier_protocol::FrameType expected_answer_message_type,
191 haier_protocol::HandlerError result = haier_protocol::HandlerError::HANDLER_OK;
192 if ((expected_request_message_type != haier_protocol::FrameType::UNKNOWN_FRAME_TYPE) &&
193 (request_message_type != expected_request_message_type))
194 result = haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
195 if ((expected_answer_message_type != haier_protocol::FrameType::UNKNOWN_FRAME_TYPE) &&
196 (answer_message_type != expected_answer_message_type))
197 result = haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
200 result = haier_protocol::HandlerError::UNEXPECTED_MESSAGE;
201 if (answer_message_type == haier_protocol::FrameType::INVALID)
202 result = haier_protocol::HandlerError::INVALID_ANSWER;
207 haier_protocol::FrameType request_type, haier_protocol::FrameType message_type,
const uint8_t *data,
209 haier_protocol::HandlerError result =
210 this->
answer_preprocess_(request_type, haier_protocol::FrameType::REPORT_NETWORK_STATUS, message_type,
217 ESP_LOGW(TAG,
"Answer timeout for command %02X, phase %s", (uint8_t) request_type,
224 return haier_protocol::HandlerError::HANDLER_OK;
238 LOG_CLIMATE(
"",
"Haier Climate",
this);
239 ESP_LOGCONFIG(TAG,
" Device communication status: %s",
240 this->
valid_connection() ? LOG_STR_LITERAL(
"established") : LOG_STR_LITERAL(
"none"));
244 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
246 COMMUNICATION_TIMEOUT_MS) ||
254 ESP_LOGW(TAG,
"Protocol reset requested");
256 ESP_LOGW(TAG,
"Communication timeout, reseting protocol");
269 if (this->
action_request_.has_value() && this->prepare_pending_action()) {
272 ESP_LOGV(TAG,
"Control packet is pending");
325 ESP_LOGW(TAG,
"Unsupported action: %d", (uint8_t) request.
action);
337 constexpr uint32_t restore_settings_version = 0xA77D21EF;
341 recovered = {
false,
true};
352 ESP_LOGD(
"Control",
"Control call");
354 ESP_LOGW(TAG,
"Can't send control packet, first poll answer not received");
358 ESP_LOGW(TAG,
"New settings come faster then processed!");
361 if (
call.get_mode().has_value())
363 if (
call.get_fan_mode().has_value())
365 if (
call.get_swing_mode().has_value())
367 if (
call.get_target_temperature().has_value())
369 if (
call.get_preset().has_value())
401 std::chrono::milliseconds interval) {
402 this->
haier_protocol_.send_message(command, use_crc, num_repeats, interval);
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
constexpr bool empty() const
Check if the set is empty.
This class is used to encode all control actions on a climate device.
const optional< ClimateSwingMode > & get_swing_mode() const
const optional< float > & get_target_temperature() const
const optional< ClimatePreset > & get_preset() const
const optional< ClimateFanMode > & get_fan_mode() const
const optional< ClimateMode > & get_mode() const
ClimateMode mode
The active mode of the climate device.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
float target_temperature
The target temperature of the climate device.
float current_temperature
The current temperature of the climate device, as reported from the integration.
void publish_state()
Publish the state of the climate device, to be called from integrations.
optional< ClimatePreset > preset
The active preset of the climate device.
void add_feature_flags(uint32_t feature_flags)
void add_supported_preset(ClimatePreset preset)
void set_supported_presets(ClimatePresetMask presets)
void set_supported_swing_modes(ClimateSwingModeMask modes)
void set_supported_modes(ClimateModeMask modes)
void add_supported_mode(ClimateMode mode)
void set_supported_fan_modes(ClimateFanModeMask modes)
void add_supported_swing_mode(ClimateSwingMode mode)
const LogString * phase_to_string_(ProtocolPhases phase)
bool reset_protocol_request_
virtual haier_protocol::HaierMessage get_power_message(bool state)=0
ProtocolPhases protocol_phase_
SwitchState display_status_
void set_supported_modes(esphome::climate::ClimateModeMask modes)
esphome::climate::ClimateTraits traits_
bool get_health_mode() const
ESPPreferenceObject base_rtc_
void send_power_on_command()
void set_supported_presets(esphome::climate::ClimatePresetMask presets)
bool is_message_interval_exceeded_(std::chrono::steady_clock::time_point now)
bool forced_request_status_
bool is_protocol_initialisation_interval_exceeded_(std::chrono::steady_clock::time_point now)
bool is_status_request_interval_exceeded_(std::chrono::steady_clock::time_point now)
esphome::climate::ClimateTraits traits() override
haier_protocol::HandlerError answer_preprocess_(haier_protocol::FrameType request_message_type, haier_protocol::FrameType expected_request_message_type, haier_protocol::FrameType answer_message_type, haier_protocol::FrameType expected_answer_message_type, ProtocolPhases expected_phase)
virtual void initialization()
virtual void save_settings()
haier_protocol::ProtocolHandler haier_protocol_
void set_health_mode(bool state)
virtual void process_protocol_reset()
std::chrono::steady_clock::time_point last_request_timestamp_
@ SENDING_UPDATE_SIGNAL_REQUEST
void send_message_(const haier_protocol::HaierMessage &command, bool use_crc, uint8_t num_repeats=0, std::chrono::milliseconds interval=std::chrono::milliseconds::zero())
haier_protocol::HandlerError report_network_status_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size)
void control(const esphome::climate::ClimateCall &call) override
virtual void process_phase(std::chrono::steady_clock::time_point now)=0
virtual bool prepare_pending_action()
bool get_display_state() const
void set_supported_swing_modes(esphome::climate::ClimateSwingModeMask modes)
void set_health_mode_switch(switch_::Switch *sw)
std::chrono::steady_clock::time_point last_valid_status_timestamp_
haier_protocol::HaierMessage get_wifi_signal_message_()
haier_protocol::HandlerError timeout_default_handler_(haier_protocol::FrameType request_type)
bool is_control_message_interval_exceeded_(std::chrono::steady_clock::time_point now)
switch_::Switch * health_mode_switch_
bool valid_connection() const
esphome::optional< PendingAction > action_request_
void set_answer_timeout(uint32_t timeout)
std::chrono::steady_clock::time_point last_status_request_
HvacSettings current_hvac_settings_
HvacSettings next_hvac_settings_
void set_display_switch(switch_::Switch *sw)
void dump_config() override
void set_display_state(bool state)
void send_power_off_command()
virtual void set_handlers()=0
virtual void set_phase(ProtocolPhases phase)
void send_custom_command(const haier_protocol::HaierMessage &message)
switch_::Switch * display_switch_
Base class for all switches.
bool state
The current reported state of the binary sensor.
void publish_state(bool state)
Publish a state to the front-end from the back-end.
const LogString * message
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
constexpr size_t STATUS_REQUEST_INTERVAL_MS
bool check_timeout(std::chrono::steady_clock::time_point now, std::chrono::steady_clock::time_point tpoint, size_t timeout)
constexpr size_t PROTOCOL_INITIALIZATION_INTERVAL
constexpr size_t DEFAULT_MESSAGES_INTERVAL_MS
constexpr size_t COMMUNICATION_TIMEOUT_MS
ESPHOME_LOG_TAG(TAG, "haier.climate")
constexpr size_t CONTROL_MESSAGES_INTERVAL_MS
PROGMEM_STRING_TABLE(ProtocolPhaseStrings, "SENDING_INIT_1", "SENDING_INIT_2", "SENDING_FIRST_STATUS_REQUEST", "SENDING_FIRST_ALARM_STATUS_REQUEST", "IDLE", "SENDING_STATUS_REQUEST", "SENDING_UPDATE_SIGNAL_REQUEST", "SENDING_SIGNAL_LEVEL", "SENDING_CONTROL", "SENDING_ACTION_COMMAND", "SENDING_ALARM_STATUS_REQUEST", "UNKNOWN")
WiFiComponent * global_wifi_component
esphome::optional< esphome::climate::ClimateFanMode > fan_mode
esphome::optional< esphome::climate::ClimateSwingMode > swing_mode
esphome::optional< esphome::climate::ClimateMode > mode
esphome::optional< esphome::climate::ClimatePreset > preset
esphome::optional< float > target_temperature
esphome::optional< haier_protocol::HaierMessage > message