From 431316cd2f5ae563dbb72b9b0a7bfe52b8182823 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 6 Jun 2025 01:42:10 +0100 Subject: [PATCH] remove batch --- esphome/components/api/api_connection.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index bcdb5c6242..897aa2aa78 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1687,6 +1687,24 @@ void APIConnection::process_batch_() { return; } + // Fast path for single message + if (this->deferred_batch_.items.size() == 1) { + const auto &item = this->deferred_batch_.items[0]; + auto message = item.creator(item.entity); + if (message) { + if (this->send_message(*message)) { + this->deferred_batch_.clear(); + } else { + // Message couldn't be sent, keep it for retry + // Batch is still scheduled, will retry later + } + } else { + this->deferred_batch_.clear(); // Creator failed, remove item + } + return; + } + + // Multiple messages - use batching // Single pass: create messages, calculate sizes and check what fits struct MessageData { std::unique_ptr message;