From 592a95c56510c1d85ea00d3f17cdb34aa40fe2ae Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 May 2025 02:58:15 -0500 Subject: [PATCH] dry --- esphome/components/api/api_frame_helper.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 094a5dca2d..73efc55824 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -281,13 +281,9 @@ APIError APINoiseFrameHelper::loop() { return APIError::OK; if (err != APIError::OK) return err; - if (!this->tx_buf_.empty() && state_ != State::CLOSED) { - err = try_send_tx_buf_(); - if (err != APIError::OK) { - return err; - } - } - return APIError::OK; + if (this->tx_buf_.empty()) + return APIError::OK; + return try_send_tx_buf_(); } /** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter @@ -804,14 +800,9 @@ APIError APIPlaintextFrameHelper::loop() { if (state_ != State::DATA) { return APIError::BAD_STATE; } - // try send pending TX data - if (!this->tx_buf_.empty() && state_ != State::CLOSED) { - APIError err = try_send_tx_buf_(); - if (err != APIError::OK) { - return err; - } - } - return APIError::OK; + if (this->tx_buf_.empty()) + return APIError::OK; + return try_send_tx_buf_(); } /** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter