diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 9e2a59b7e6..8612cfb459 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -299,15 +299,8 @@ APIError APINoiseFrameHelper::try_read_frame_(ParsedFrame *frame) { } // Only check for available data when starting a new frame read - if (rx_header_buf_len_ == 0) { - ssize_t available = socket_->available(); - if (available == 0) { - return APIError::WOULD_BLOCK; - } else if (available == -1) { - state_ = State::FAILED; - HELPER_LOG("Socket available failed with errno %d", errno); - return APIError::SOCKET_READ_FAILED; - } + if (rx_header_buf_len_ == 0 && socket_->available() == 0) { + return APIError::WOULD_BLOCK; } // read header @@ -828,15 +821,8 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) { } // Only check for available data when starting a new frame read - if (rx_header_buf_pos_ == 0) { - ssize_t available = socket_->available(); - if (available == 0) { - return APIError::WOULD_BLOCK; - } else if (available == -1) { - state_ = State::FAILED; - HELPER_LOG("Socket read_available failed with errno %d", errno); - return APIError::SOCKET_READ_FAILED; - } + if (rx_header_buf_pos_ == 0 && socket_->available() == 0) { + return APIError::WOULD_BLOCK; } // read header