diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index e911ece7eb..fea24aa32a 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1538,10 +1538,9 @@ void APIConnection::subscribe_home_assistant_states(const SubscribeHomeAssistant bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { if (this->remove_) return false; - if (this->helper_->can_write_without_blocking()) { - delay(0); + if (this->helper_->can_write_without_blocking()) return true; - } + delay(0); APIError err = this->helper_->loop(); if (err != APIError::OK) { on_fatal_error(); @@ -1549,9 +1548,8 @@ bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { api_error_to_str(err), errno); return false; } - if (this->helper_->can_write_without_blocking()) { + if (this->helper_->can_write_without_blocking()) return true; - } if (log_out_of_space) { ESP_LOGV(TAG, "Cannot send message because of TCP buffer space"); }