From 8f7f0d9d9b64b65686b74d7415c19529799e66a7 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Thu, 12 Oct 2023 19:08:44 +0200 Subject: [PATCH] Refactoring stage 3. Adjusting smartair2 initial phases to use retry mechanism --- components/haier/climate.py | 3 +- components/haier/haier_base.cpp | 32 ++++--- components/haier/haier_base.h | 10 +-- components/haier/hon_climate.cpp | 13 +-- components/haier/hon_climate.h | 2 - components/haier/smartair2_climate.cpp | 119 +++++++++---------------- components/haier/smartair2_climate.h | 8 +- 7 files changed, 71 insertions(+), 116 deletions(-) diff --git a/components/haier/climate.py b/components/haier/climate.py index c58f54a..97bd91c 100644 --- a/components/haier/climate.py +++ b/components/haier/climate.py @@ -446,5 +446,4 @@ async def to_code(config): if CONF_CONTROL_PACKET_SIZE in config: cg.add(var.set_extra_control_packet_bytes_size(config[CONF_CONTROL_PACKET_SIZE] - PROTOCOL_CONTROL_PACKET_SIZE)) # https://github.com/paveldn/HaierProtocol - #cg.add_library("pavlodn/HaierProtocol", "0.9.22") - cg.add_library(name="HaierProtocol", repository="https://github.com/paveldn/HaierProtocol", version="a1a2a56258da1e8a24473d37464a4e11c9f71b0e") + cg.add_library("pavlodn/HaierProtocol", "0.9.23") diff --git a/components/haier/haier_base.cpp b/components/haier/haier_base.cpp index 8ecf559..5a6eb7d 100644 --- a/components/haier/haier_base.cpp +++ b/components/haier/haier_base.cpp @@ -10,6 +10,7 @@ using namespace esphome::climate; using namespace esphome::uart; + namespace esphome { namespace haier { @@ -55,6 +56,12 @@ const char *HaierClimateBase::phase_to_string_(ProtocolPhases phase) { } #endif +bool check_timeout_(std::chrono::steady_clock::time_point now, + std::chrono::steady_clock::time_point tpoint, size_t timeout) { + return std::chrono::duration_cast(now - tpoint).count() > timeout; +} + + HaierClimateBase::HaierClimateBase() : haier_protocol_(*this), protocol_phase_(ProtocolPhases::SENDING_INIT_1), @@ -99,25 +106,20 @@ void HaierClimateBase::reset_to_idle_() { this->action_request_ = ActionRequest::NO_ACTION; } -bool HaierClimateBase::check_timeout_(std::chrono::steady_clock::time_point now, - std::chrono::steady_clock::time_point tpoint, size_t timeout) { - return std::chrono::duration_cast(now - tpoint).count() > timeout; -} - bool HaierClimateBase::is_message_interval_exceeded_(std::chrono::steady_clock::time_point now) { - return this->check_timeout_(now, this->last_request_timestamp_, DEFAULT_MESSAGES_INTERVAL_MS); + return check_timeout_(now, this->last_request_timestamp_, DEFAULT_MESSAGES_INTERVAL_MS); } bool HaierClimateBase::is_status_request_interval_exceeded_(std::chrono::steady_clock::time_point now) { - return this->check_timeout_(now, this->last_status_request_, STATUS_REQUEST_INTERVAL_MS); + return check_timeout_(now, this->last_status_request_, STATUS_REQUEST_INTERVAL_MS); } bool HaierClimateBase::is_control_message_interval_exceeded_(std::chrono::steady_clock::time_point now) { - return this->check_timeout_(now, this->last_request_timestamp_, CONTROL_MESSAGES_INTERVAL_MS); + return check_timeout_(now, this->last_request_timestamp_, CONTROL_MESSAGES_INTERVAL_MS); } bool HaierClimateBase::is_protocol_initialisation_interval_exceeded_(std::chrono::steady_clock::time_point now) { - return this->check_timeout_(now, this->last_request_timestamp_, PROTOCOL_INITIALIZATION_INTERVAL); + return check_timeout_(now, this->last_request_timestamp_, PROTOCOL_INITIALIZATION_INTERVAL); } #ifdef USE_WIFI @@ -202,6 +204,16 @@ haier_protocol::HandlerError HaierClimateBase::answer_preprocess_(haier_protocol return result; } +haier_protocol::HandlerError HaierClimateBase::report_network_status_answer_handler_(haier_protocol::FrameType request_type, + haier_protocol::FrameType message_type, + const uint8_t *data, size_t data_size) { + haier_protocol::HandlerError result = this->answer_preprocess_( + request_type, haier_protocol::FrameType::REPORT_NETWORK_STATUS, message_type, + haier_protocol::FrameType::CONFIRM, ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER); + this->set_phase(ProtocolPhases::IDLE); + return result; +} + haier_protocol::HandlerError HaierClimateBase::timeout_default_handler_(haier_protocol::FrameType request_type) { #if (HAIER_LOG_LEVEL > 4) ESP_LOGW(TAG, "Answer timeout for command %02X, phase %s", request_type, phase_to_string_(this->protocol_phase_)); @@ -221,9 +233,9 @@ void HaierClimateBase::setup() { // Set timestamp here to give AC time to boot this->last_request_timestamp_ = std::chrono::steady_clock::now(); this->set_phase(ProtocolPhases::SENDING_INIT_1); - this->set_handlers(); this->haier_protocol_.set_default_timeout_handler( std::bind(&esphome::haier::HaierClimateBase::timeout_default_handler_, this, std::placeholders::_1)); + this->set_handlers(); } void HaierClimateBase::dump_config() { diff --git a/components/haier/haier_base.h b/components/haier/haier_base.h index 3c02da0..cc113b5 100644 --- a/components/haier/haier_base.h +++ b/components/haier/haier_base.h @@ -33,7 +33,6 @@ class HaierClimateBase : public esphome::Component, void control(const esphome::climate::ClimateCall &call) override; void dump_config() override; float get_setup_priority() const override { return esphome::setup_priority::HARDWARE; } - void set_fahrenheit(bool fahrenheit); void set_display_state(bool state); bool get_display_state() const; void set_health_mode(bool state); @@ -93,18 +92,18 @@ class HaierClimateBase : public esphome::Component, virtual haier_protocol::HaierMessage get_control_message() = 0; virtual void process_pending_action(); esphome::climate::ClimateTraits traits() override; - // Answers handlers + // Answer handlers 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); + 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); // Timeout handler haier_protocol::HandlerError timeout_default_handler_(haier_protocol::FrameType request_type); // Helper functions void send_message_(const haier_protocol::HaierMessage &command, bool use_crc, uint8_t num_retries = 0, std::chrono::milliseconds interval = std::chrono::milliseconds::zero()); virtual void set_phase(ProtocolPhases phase); void reset_to_idle_(); - bool check_timeout_(std::chrono::steady_clock::time_point now, std::chrono::steady_clock::time_point tpoint, - size_t timeout); bool is_message_interval_exceeded_(std::chrono::steady_clock::time_point now); bool is_status_request_interval_exceeded_(std::chrono::steady_clock::time_point now); bool is_control_message_interval_exceeded_(std::chrono::steady_clock::time_point now); @@ -119,10 +118,7 @@ class HaierClimateBase : public esphome::Component, esphome::optional swing_mode; esphome::optional target_temperature; esphome::optional preset; - esphome::optional display; - esphome::optional health; bool valid; - bool force_update; HvacSettings() : valid(false){}; HvacSettings(const HvacSettings&) = default; HvacSettings& operator=(const HvacSettings&) = default; diff --git a/components/haier/hon_climate.cpp b/components/haier/hon_climate.cpp index 65befb6..fb44909 100644 --- a/components/haier/hon_climate.cpp +++ b/components/haier/hon_climate.cpp @@ -238,16 +238,6 @@ haier_protocol::HandlerError HonClimate::get_management_information_answer_handl } } -haier_protocol::HandlerError HonClimate::report_network_status_answer_handler_(haier_protocol::FrameType request_type, - haier_protocol::FrameType message_type, - const uint8_t *data, size_t data_size) { - haier_protocol::HandlerError result = - this->answer_preprocess_(request_type, haier_protocol::FrameType::REPORT_NETWORK_STATUS, message_type, - haier_protocol::FrameType::CONFIRM, ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER); - this->set_phase(ProtocolPhases::IDLE); - return result; -} - haier_protocol::HandlerError HonClimate::get_alarm_status_answer_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_size) { if (request_type == haier_protocol::FrameType::GET_ALARM_STATUS) { @@ -430,7 +420,6 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) { : ProtocolPhases::WAITING_POWER_OFF_ANSWER); } break; - case ProtocolPhases::WAITING_INIT_1_ANSWER: case ProtocolPhases::WAITING_INIT_2_ANSWER: case ProtocolPhases::WAITING_FIRST_STATUS_ANSWER: @@ -555,7 +544,7 @@ haier_protocol::HaierMessage HonClimate::get_control_message() { } if (climate_control.target_temperature.has_value()) { float target_temp = climate_control.target_temperature.value(); - out_data->set_point = ((int) target_temp) - 16; // set the temperature at our offset, subtract 16. + out_data->set_point = ((int) target_temp) - 16; // set the temperature with offset 16 out_data->half_degree = (target_temp - ((int) target_temp) >= 0.49) ? 1 : 0; } if (out_data->ac_power == 0) { diff --git a/components/haier/hon_climate.h b/components/haier/hon_climate.h index 215d989..601a34a 100644 --- a/components/haier/hon_climate.h +++ b/components/haier/hon_climate.h @@ -72,8 +72,6 @@ class HonClimate : public HaierClimateBase { size_t data_size); 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); - 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); 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); // Helper functions diff --git a/components/haier/smartair2_climate.cpp b/components/haier/smartair2_climate.cpp index 975e2ec..17428ff 100644 --- a/components/haier/smartair2_climate.cpp +++ b/components/haier/smartair2_climate.cpp @@ -14,8 +14,10 @@ static const char *const TAG = "haier.climate"; constexpr size_t SIGNAL_LEVEL_UPDATE_INTERVAL_MS = 10000; constexpr uint8_t CONTROL_MESSAGE_RETRIES = 5; constexpr std::chrono::milliseconds CONTROL_MESSAGE_RETRIES_INTERVAL = std::chrono::milliseconds(500); +constexpr uint8_t INIT_REQUESTS_RETRY = 2; +constexpr std::chrono::milliseconds INIT_REQUESTS_RETRY_INTERVAL = std::chrono::milliseconds(2000); -Smartair2Climate::Smartair2Climate(): timeouts_counter_(0) { +Smartair2Climate::Smartair2Climate() { last_status_message_ = std::unique_ptr(new uint8_t[sizeof(smartair2_protocol::HaierPacketControl)]); } @@ -29,7 +31,9 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(haier_protocol::F if (result != haier_protocol::HandlerError::HANDLER_OK) { ESP_LOGW(TAG, "Error %d while parsing Status packet", (int) result); this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE - : ProtocolPhases::SENDING_FIRST_STATUS_REQUEST); + : ProtocolPhases::SENDING_INIT_1); + this->action_request_ = ActionRequest::NO_ACTION; + this->force_send_control_ = false; } else { if (data_size >= sizeof(smartair2_protocol::HaierPacketControl) + 2) { memcpy(this->last_status_message_.get(), data + 2, sizeof(smartair2_protocol::HaierPacketControl)); @@ -40,7 +44,9 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(haier_protocol::F if (this->protocol_phase_ == ProtocolPhases::WAITING_FIRST_STATUS_ANSWER) { ESP_LOGI(TAG, "First HVAC status received"); this->set_phase(ProtocolPhases::IDLE); - } else if (this->protocol_phase_ == ProtocolPhases::WAITING_STATUS_ANSWER) { + } else if ((this->protocol_phase_ == ProtocolPhases::WAITING_STATUS_ANSWER) || + (this->protocol_phase_ == ProtocolPhases::WAITING_POWER_ON_ANSWER) || + (this->protocol_phase_ == ProtocolPhases::WAITING_POWER_OFF_ANSWER)) { this->set_phase(ProtocolPhases::IDLE); } else if (this->protocol_phase_ == ProtocolPhases::WAITING_CONTROL_ANSWER) { this->set_phase(ProtocolPhases::IDLE); @@ -51,8 +57,10 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(haier_protocol::F } return result; } else { + this->action_request_ = ActionRequest::NO_ACTION; + this->force_send_control_ = false; this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE - : ProtocolPhases::SENDING_FIRST_STATUS_REQUEST); + : ProtocolPhases::SENDING_INIT_1); return result; } } @@ -75,32 +83,14 @@ haier_protocol::HandlerError Smartair2Climate::get_device_version_answer_handler return haier_protocol::HandlerError::HANDLER_OK; } -haier_protocol::HandlerError Smartair2Climate::report_network_status_answer_handler_(haier_protocol::FrameType request_type, - haier_protocol::FrameType message_type, - const uint8_t *data, - size_t data_size) { - haier_protocol::HandlerError result = this->answer_preprocess_( - request_type, haier_protocol::FrameType::REPORT_NETWORK_STATUS, message_type, - haier_protocol::FrameType::CONFIRM, ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER); - this->set_phase(ProtocolPhases::IDLE); - return result; -} - -haier_protocol::HandlerError Smartair2Climate::initial_messages_timeout_handler_(haier_protocol::FrameType message_type) { +haier_protocol::HandlerError Smartair2Climate::messages_timeout_handler_with_cycle_for_init_(haier_protocol::FrameType message_type) { if (this->protocol_phase_ >= ProtocolPhases::IDLE) return HaierClimateBase::timeout_default_handler_(message_type); - this->timeouts_counter_++; - ESP_LOGI(TAG, "Answer timeout for command %02X, phase %d, timeout counter %d", message_type, - (int) this->protocol_phase_, this->timeouts_counter_); - if (this->timeouts_counter_ >= 3) { - ProtocolPhases new_phase = (ProtocolPhases) ((int) this->protocol_phase_ + 1); - if (new_phase >= ProtocolPhases::SENDING_ALARM_STATUS_REQUEST) - new_phase = ProtocolPhases::SENDING_INIT_1; - this->set_phase(new_phase); - } else { - // Returning to the previous state to try again - this->set_phase((ProtocolPhases) ((int) this->protocol_phase_ - 1)); - } + ESP_LOGI(TAG, "Answer timeout for command %02X, phase %d", (uint8_t) message_type, (int) this->protocol_phase_); + ProtocolPhases new_phase = (ProtocolPhases) ((int) this->protocol_phase_ + 1); + if (new_phase >= ProtocolPhases::SENDING_ALARM_STATUS_REQUEST) + new_phase = ProtocolPhases::SENDING_INIT_1; + this->set_phase(new_phase); return haier_protocol::HandlerError::HANDLER_OK; } @@ -118,15 +108,7 @@ void Smartair2Climate::set_handlers() { haier_protocol::FrameType::REPORT_NETWORK_STATUS, std::bind(&Smartair2Climate::report_network_status_answer_handler_, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); - this->haier_protocol_.set_timeout_handler( - haier_protocol::FrameType::GET_DEVICE_ID, - std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1)); - this->haier_protocol_.set_timeout_handler( - haier_protocol::FrameType::GET_DEVICE_VERSION, - std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1)); - this->haier_protocol_.set_timeout_handler( - haier_protocol::FrameType::CONTROL, - std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1)); + this->haier_protocol_.set_default_timeout_handler(std::bind(&Smartair2Climate::messages_timeout_handler_with_cycle_for_init_, this, std::placeholders::_1)); } void Smartair2Climate::dump_config() { @@ -137,9 +119,7 @@ void Smartair2Climate::dump_config() { void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) { switch (this->protocol_phase_) { case ProtocolPhases::SENDING_INIT_1: - if (this->can_send_message() && - (((this->timeouts_counter_ == 0) && (this->is_protocol_initialisation_interval_exceeded_(now))) || - ((this->timeouts_counter_ > 0) && (this->is_message_interval_exceeded_(now))))) { + if (this->can_send_message() && this->is_protocol_initialisation_interval_exceeded_(now)) { // Indicate device capabilities: // bit 0 - if 1 module support interactive mode // bit 1 - if 1 module support controller-device mode @@ -148,9 +128,8 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) // bit 4..bit 15 - not used uint8_t module_capabilities[2] = {0b00000000, 0b00000111}; static const haier_protocol::HaierMessage DEVICE_VERSION_REQUEST( - haier_protocol::FrameType::GET_DEVICE_VERSION, module_capabilities, - sizeof(module_capabilities)); - this->send_message_(DEVICE_VERSION_REQUEST, false); + haier_protocol::FrameType::GET_DEVICE_VERSION, module_capabilities, sizeof(module_capabilities)); + this->send_message_(DEVICE_VERSION_REQUEST, this->use_crc_, INIT_REQUESTS_RETRY, INIT_REQUESTS_RETRY_INTERVAL); this->set_phase(ProtocolPhases::WAITING_INIT_1_ANSWER); } break; @@ -163,7 +142,11 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) if (this->can_send_message() && this->is_message_interval_exceeded_(now)) { static const haier_protocol::HaierMessage STATUS_REQUEST(haier_protocol::FrameType::CONTROL, 0x4D01); - this->send_message_(STATUS_REQUEST, false); + + if (this->protocol_phase_ == ProtocolPhases::SENDING_FIRST_STATUS_REQUEST) + this->send_message_(STATUS_REQUEST, this->use_crc_, INIT_REQUESTS_RETRY, INIT_REQUESTS_RETRY_INTERVAL); + else + this->send_message_(STATUS_REQUEST, this->use_crc_); this->last_status_request_ = now; this->set_phase((ProtocolPhases) ((uint8_t) this->protocol_phase_ + 1)); } @@ -171,10 +154,10 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) #ifdef USE_WIFI case ProtocolPhases::SENDING_SIGNAL_LEVEL: if (this->can_send_message() && this->is_message_interval_exceeded_(now)) { - this->send_message_( - this->get_wifi_signal_message_(haier_protocol::FrameType::REPORT_NETWORK_STATUS), false); - this->last_signal_request_ = now; + this->send_message_(this->get_wifi_signal_message_(haier_protocol::FrameType::REPORT_NETWORK_STATUS), + this->use_crc_); this->set_phase(ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER); + this->last_signal_request_ = now; } break; case ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER: @@ -194,21 +177,18 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) this->set_phase(ProtocolPhases::SENDING_INIT_1); break; case ProtocolPhases::SENDING_CONTROL: - if (this->can_send_message() && this->is_control_message_interval_exceeded_(now)) - { - haier_protocol::HaierMessage control_message = get_control_message(); - this->send_message_(control_message, false, CONTROL_MESSAGE_RETRIES, CONTROL_MESSAGE_RETRIES_INTERVAL); - ESP_LOGI(TAG, "Control packet sent"); + if (this->can_send_message() && this->is_control_message_interval_exceeded_(now)) { + ESP_LOGI(TAG, "Sending control packet"); + this->send_message_(get_control_message(), this->use_crc_, CONTROL_MESSAGE_RETRIES, CONTROL_MESSAGE_RETRIES_INTERVAL); this->set_phase(ProtocolPhases::WAITING_CONTROL_ANSWER); } break; case ProtocolPhases::SENDING_POWER_ON_COMMAND: case ProtocolPhases::SENDING_POWER_OFF_COMMAND: if (this->can_send_message() && this->is_message_interval_exceeded_(now)) { - haier_protocol::HaierMessage power_cmd( - haier_protocol::FrameType::CONTROL, + haier_protocol::HaierMessage power_cmd(haier_protocol::FrameType::CONTROL, this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND ? 0x4D02 : 0x4D03); - this->send_message_(power_cmd, false); + this->send_message_(power_cmd, this->use_crc_); this->set_phase(this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND ? ProtocolPhases::WAITING_POWER_ON_ANSWER : ProtocolPhases::WAITING_POWER_OFF_ANSWER); @@ -258,31 +238,26 @@ haier_protocol::HaierMessage Smartair2Climate::get_control_message() { case CLIMATE_MODE_OFF: out_data->ac_power = 0; break; - case CLIMATE_MODE_HEAT_COOL: out_data->ac_power = 1; out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::AUTO; out_data->fan_mode = this->other_modes_fan_speed_; break; - case CLIMATE_MODE_HEAT: out_data->ac_power = 1; out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::HEAT; out_data->fan_mode = this->other_modes_fan_speed_; break; - case CLIMATE_MODE_DRY: out_data->ac_power = 1; out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::DRY; out_data->fan_mode = this->other_modes_fan_speed_; break; - case CLIMATE_MODE_FAN_ONLY: out_data->ac_power = 1; out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::FAN; out_data->fan_mode = this->fan_mode_speed_; // Auto doesn't work in fan only mode break; - case CLIMATE_MODE_COOL: out_data->ac_power = 1; out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::COOL; @@ -358,7 +333,7 @@ haier_protocol::HaierMessage Smartair2Climate::get_control_message() { } if (climate_control.target_temperature.has_value()) { float target_temp = climate_control.target_temperature.value(); - out_data->set_point = target_temp - 16; // set the temperature with offset 16 + out_data->set_point = ((int) target_temp) - 16; // set the temperature with offset 16 out_data->half_degree = (target_temp - ((int) target_temp) >= 0.49) ? 1 : 0; } if (out_data->ac_power == 0) { @@ -472,6 +447,12 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin } } } + { + // Health mode + bool old_health_mode = this->health_mode_; + this->health_mode_ = packet.control.health_mode == 1; + should_publish = should_publish || (old_health_mode != this->health_mode_); + } { // Climate mode ClimateMode old_mode = this->mode; @@ -499,12 +480,6 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin } should_publish = should_publish || (old_mode != this->mode); } - { - // Health mode - bool old_health_mode = this->health_mode_; - this->health_mode_ = packet.control.health_mode == 1; - should_publish = should_publish || (old_health_mode != this->health_mode_); - } { // Swing mode ClimateSwingMode old_swing_mode = this->swing_mode; @@ -567,16 +542,6 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin return haier_protocol::HandlerError::HANDLER_OK; } -void Smartair2Climate::set_phase(HaierClimateBase::ProtocolPhases phase) { - int old_phase = (int) this->protocol_phase_; - int new_phase = (int) phase; - int min_p = std::min(old_phase, new_phase); - int max_p = std::max(old_phase, new_phase); - if ((min_p % 2 != 0) || (max_p - min_p > 1)) - this->timeouts_counter_ = 0; - HaierClimateBase::set_phase(phase); -} - void Smartair2Climate::set_alternative_swing_control(bool swing_control) { this->use_alternative_swing_control_ = swing_control; } diff --git a/components/haier/smartair2_climate.h b/components/haier/smartair2_climate.h index 14f071c..f42bb6d 100644 --- a/components/haier/smartair2_climate.h +++ b/components/haier/smartair2_climate.h @@ -19,20 +19,16 @@ class Smartair2Climate : public HaierClimateBase { void set_handlers() override; void process_phase(std::chrono::steady_clock::time_point now) override; haier_protocol::HaierMessage get_control_message() override; - void set_phase(HaierClimateBase::ProtocolPhases phase) override; - // Answer and timeout handlers + // Answer handlers haier_protocol::HandlerError status_handler_(haier_protocol::FrameType request_type, haier_protocol::FrameType message_type, const uint8_t *data, size_t data_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); 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); - 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); - haier_protocol::HandlerError initial_messages_timeout_handler_(haier_protocol::FrameType message_type); + haier_protocol::HandlerError messages_timeout_handler_with_cycle_for_init_(haier_protocol::FrameType message_type); // Helper functions haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size); - unsigned int timeouts_counter_; bool use_alternative_swing_control_; };