From e2453dd5130b80ed9da4c187f87ab61d6984a1ef Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 14 May 2025 17:27:05 -0500 Subject: [PATCH] optimize --- esphome/components/api/api_connection.cpp | 2 +- esphome/components/api/api_connection.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 05fc223a06..cb3eef018e 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -153,7 +153,7 @@ void APIConnection::loop() { return; } - if (this->helper_->can_write_without_blocking()) { + if (!this->deferred_message_queue_.empty() && this->helper_->can_write_without_blocking()) { this->deferred_message_queue_.process_queue(); } diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 0c1f5461f3..dd24802e72 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -53,6 +53,7 @@ class DeferredMessageQueue { DeferredMessageQueue(APIConnection *api_connection) : api_connection_(api_connection) {} void process_queue(); void defer(void *source, send_message_t send_message); + bool empty() const { return deferred_queue_.empty(); } }; class APIConnection : public APIServerConnection {