From f027b32c184763c81b016a90de96442afc3de347 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Jan 2026 17:00:43 -1000 Subject: [PATCH] fix events --- esphome/components/api/api_connection.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 247348d356..6491546860 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1887,14 +1887,17 @@ void APIConnection::DeferredBatch::add_item(EntityBase *entity, uint8_t message_ // Check if we already have a message of this type for this entity // This provides deduplication per entity/message_type combination // O(n) but optimized for RAM and not performance. - for (auto &item : items) { - if (item.entity == entity && item.message_type == message_type) { - // Update aux_data_index for events (allows updating event type) - item.aux_data_index = aux_data_index; - return; + // Skip deduplication for events - they are edge-triggered, every occurrence matters +#ifdef USE_EVENT + if (message_type != EventResponse::MESSAGE_TYPE) +#endif + { + for (const auto &item : items) { + if (item.entity == entity && item.message_type == message_type) + return; // Already queued } } - // No existing item found, add new one + // No existing item found (or event), add new one items.push_back({entity, message_type, estimated_size, aux_data_index}); }