From 78f98fa08fbbf8f64c5ca72cafb916298c93d20a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Feb 2026 02:51:27 -0600 Subject: [PATCH] [hlk_fm22x] Drain exact frame bytes on oversize response Discard exactly length+1 (payload + checksum) instead of flushing the entire RX buffer, which could eat bytes from the next frame. --- esphome/components/hlk_fm22x/hlk_fm22x.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/hlk_fm22x/hlk_fm22x.cpp b/esphome/components/hlk_fm22x/hlk_fm22x.cpp index 8a12c5e772..fb79113181 100644 --- a/esphome/components/hlk_fm22x/hlk_fm22x.cpp +++ b/esphome/components/hlk_fm22x/hlk_fm22x.cpp @@ -135,7 +135,8 @@ void HlkFm22xComponent::recv_command_() { if (length > HLK_FM22X_MAX_RESPONSE_SIZE) { ESP_LOGE(TAG, "Response too large: %u bytes", length); - while (this->available()) + // Discard exactly the remaining payload and checksum for this frame + for (uint16_t i = 0; i < length + 1 && this->available(); ++i) this->read(); return; }