From 1fb2eaa90582aafcda7bdfb1c5e29a071af493ee Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 7 Jan 2026 16:24:46 -1000 Subject: [PATCH] fixes --- esphome/components/wifi/wifi_component.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 3645f9e37f..cbd56800ec 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -1305,14 +1305,17 @@ void WiFiComponent::check_connecting_finished(uint32_t now) { // Reset roaming state on successful connection this->roaming_last_check_ = now; - // Only reset attempts if this wasn't a roaming-triggered connection - // (CONNECTING = roam attempt, RECONNECTING = failed roam, reconnecting) + // Only preserve attempts if reconnecting after a failed roam attempt // This prevents ping-pong between APs when a roam target is unreachable if (this->roaming_state_ == RoamingState::CONNECTING) { + // Successful roam to better AP - reset attempts so we can roam again later ESP_LOGD(TAG, "Roam successful"); + this->roaming_attempts_ = 0; } else if (this->roaming_state_ == RoamingState::RECONNECTING) { + // Failed roam, reconnected via normal recovery - keep attempts to prevent ping-pong ESP_LOGD(TAG, "Reconnected after failed roam (attempt %u/%u)", this->roaming_attempts_, ROAMING_MAX_ATTEMPTS); } else { + // Normal connection (boot, credentials changed, etc.) this->roaming_attempts_ = 0; } this->roaming_state_ = RoamingState::IDLE;