Skip to content

Commit

Permalink
Fixed phase change while waiting for answer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Dudnytskyi authored and paveldn committed Oct 17, 2023
1 parent 364d920 commit c6b8700
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
20 changes: 9 additions & 11 deletions components/haier/haier_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool HaierClimateBase::is_protocol_initialisation_interval_exceeded_(std::chrono
}

#ifdef USE_WIFI
haier_protocol::HaierMessage HaierClimateBase::get_wifi_signal_message_(haier_protocol::FrameType message_type) {
haier_protocol::HaierMessage HaierClimateBase::get_wifi_signal_message_() {
static uint8_t wifi_status_data[4] = {0x00, 0x00, 0x00, 0x00};
if (wifi::global_wifi_component->is_connected()) {
wifi_status_data[1] = 0;
Expand All @@ -121,7 +121,7 @@ haier_protocol::HaierMessage HaierClimateBase::get_wifi_signal_message_(haier_pr
wifi_status_data[1] = 1;
wifi_status_data[3] = 0;
}
return haier_protocol::HaierMessage(message_type, wifi_status_data, sizeof(wifi_status_data));
return haier_protocol::HaierMessage(haier_protocol::FrameType::REPORT_NETWORK_STATUS, wifi_status_data, sizeof(wifi_status_data));
}
#endif

Expand Down Expand Up @@ -229,27 +229,25 @@ void HaierClimateBase::loop() {
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if ((std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_valid_status_timestamp_).count() >
COMMUNICATION_TIMEOUT_MS) ||
(this->reset_protocol_request_)) {
(this->reset_protocol_request_ && (!this->haier_protocol_.is_waiting_for_answer()))) {
this->last_valid_status_timestamp_ = now;
if (this->protocol_phase_ >= ProtocolPhases::IDLE) {
// No status too long, reseting protocol
// No need to reset protocol if we didn't pass initialization phase
if (this->reset_protocol_request_) {
this->reset_protocol_request_ = false;
ESP_LOGW(TAG, "Protocol reset requested");
} else {
ESP_LOGW(TAG, "Communication timeout, reseting protocol");
}
this->last_valid_status_timestamp_ = now;
this->process_protocol_reset();
return;
} else {
// No need to reset protocol if we didn't pass initialization phase
this->last_valid_status_timestamp_ = now;
}
};
if ((this->protocol_phase_ == ProtocolPhases::IDLE) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_STATUS_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_SIGNAL_LEVEL)) {
if ((this->protocol_phase_ == ProtocolPhases::IDLE) || (!this->haier_protocol_.is_waiting_for_answer() &&
((this->protocol_phase_ == ProtocolPhases::SENDING_STATUS_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_SIGNAL_LEVEL)))) {
// If control message or action is pending we should send it ASAP unless we are in initialisation
// procedure or waiting for an answer
if (this->action_request_ != ActionRequest::NO_ACTION) {
Expand Down
2 changes: 1 addition & 1 deletion components/haier/haier_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class HaierClimateBase : public esphome::Component,
bool is_control_message_interval_exceeded_(std::chrono::steady_clock::time_point now);
bool is_protocol_initialisation_interval_exceeded_(std::chrono::steady_clock::time_point now);
#ifdef USE_WIFI
haier_protocol::HaierMessage get_wifi_signal_message_(haier_protocol::FrameType message_type);
haier_protocol::HaierMessage get_wifi_signal_message_();
#endif

struct HvacSettings {
Expand Down
5 changes: 2 additions & 3 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
switch (this->protocol_phase_) {
case ProtocolPhases::SENDING_INIT_1:
if (this->can_send_message() && this->is_protocol_initialisation_interval_exceeded_(now)) {
this->hvac_hardware_info_.reset();
// Indicate device capabilities:
// bit 0 - if 1 module support interactive mode
// bit 1 - if 1 module support controller-device mode
Expand Down Expand Up @@ -348,8 +347,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
break;
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),
this->use_crc_);
this->send_message_(this->get_wifi_signal_message_(), this->use_crc_);
}
break;
#else
Expand Down Expand Up @@ -989,6 +987,7 @@ void HonClimate::process_protocol_reset() {
this->outdoor_sensor_->publish_state(NAN);
}
this->got_valid_outdoor_temp_ = false;
this->hvac_hardware_info_.reset();
}

} // namespace haier
Expand Down
3 changes: 1 addition & 2 deletions components/haier/smartair2_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ 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),
this->use_crc_);
this->send_message_(this->get_wifi_signal_message_(), this->use_crc_);
this->last_signal_request_ = now;
}
break;
Expand Down

0 comments on commit c6b8700

Please sign in to comment.