From f0decc4716941139d3ee94220df2eba6847ca4ca Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 13 Aug 2025 22:42:08 -0500 Subject: [PATCH] tweak --- esphome/components/api/api_connection.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 9c0d47bca1..64abcf2e26 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -311,10 +311,15 @@ uint16_t APIConnection::encode_message_to_buffer(ProtoMessage &msg, uint8_t mess size_t size_before_encode = shared_buf.size(); msg.encode(buffer); + // Calculate actual encoded size (not including header that was already added) size_t actual_payload_size = shared_buf.size() - size_before_encode; - assert(calculated_size == actual_payload_size); - return static_cast(total_size); + // Return actual total size (header + actual payload + footer) + size_t actual_total_size = header_padding + actual_payload_size + footer_size; + + // Verify that calculate_size() returned the correct value + assert(calculated_size == actual_payload_size); + return static_cast(actual_total_size); } #ifdef USE_BINARY_SENSOR