From d98484c283ea481ed2b0872bcb8325b0b735fc62 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Aug 2026 18:39:23 -0500 Subject: [PATCH] [uart] Report no data available while the bus is not ready A stale peeked byte was still counted by available() while the read paths refused to deliver it, so a caller looping on available() would spin forever. --- esphome/components/uart/uart_component_esp_idf.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esphome/components/uart/uart_component_esp_idf.cpp b/esphome/components/uart/uart_component_esp_idf.cpp index 923b1b3772..4e88295bf4 100644 --- a/esphome/components/uart/uart_component_esp_idf.cpp +++ b/esphome/components/uart/uart_component_esp_idf.cpp @@ -371,7 +371,10 @@ size_t IDFUARTComponent::available() { if (!this->is_ready()) { // The driver is not installed yet (or the bus failed); asking the driver // would fail and mark the whole bus failed, so report no data instead. - return this->has_peek_ ? 1 : 0; + // A stale peeked byte must not be counted either: the read paths refuse + // to deliver it while the bus is not ready, so advertising it would make + // the common `while (available()) read()` pattern spin forever. + return 0; } err = uart_get_buffered_data_len(this->uart_num_, &available);