diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 70f4fc8628..02ce4e69e4 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -261,7 +261,7 @@ APIConnection::EncodedMessage APIConnection::encode_message_to_buffer(ProtoMessa // Calculate overhead for this message uint16_t overhead = conn->helper_->calculate_packet_overhead(message_type, static_cast(size)); - uint32_t total_size = size + overhead; + uint16_t total_size = static_cast(size) + overhead; // Check if it fits if (total_size > remaining_size) { @@ -274,7 +274,7 @@ APIConnection::EncodedMessage APIConnection::encode_message_to_buffer(ProtoMessa // Encode directly into buffer msg.encode(buffer); - return {static_cast(size), static_cast(total_size)}; + return {static_cast(size), total_size}; } #ifdef USE_BINARY_SENSOR