From 67034c966d8b01b44f9b104b0fccc001e273f190 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Feb 2026 08:14:37 -0600 Subject: [PATCH] no widen --- esphome/components/api/proto.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index ee2fd8be7f..bb8cad7b70 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -119,12 +119,23 @@ class ProtoVarInt { return ProtoVarInt(result32); } } - // 64-bit phase for values > 28 bits (BLE addresses etc.) + // Byte 4: handles uint32 values >= 2^28 that need 5 varint bytes + // Only lower 4 bits contribute to bits 28-31 of the uint32 result + if (len > 4) { + uint8_t val = buffer[4]; + result32 |= uint32_t(val & 0x0F) << 28; + if ((val & 0x80) == 0) { + *consumed = 5; + return ProtoVarInt(result32); + } + // Varint continues past byte 4 — needs 64-bit (BLE addresses etc.) #ifdef USE_API_VARINT64 - return parse_wide(buffer, len, consumed, result32); + return parse_wide(buffer, len, consumed, result32); #else - return {}; + return {}; #endif + } + return {}; } #ifdef USE_API_VARINT64