From 703b1cf314c18dada13f349983d4613db588deb8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 6 Nov 2025 13:51:47 -0600 Subject: [PATCH] cleanup --- esphome/components/wifi/wifi_component.cpp | 4 ++-- esphome/components/wifi/wifi_component.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index f774f6b64a..da07f0eab7 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -821,7 +821,7 @@ void WiFiComponent::retry_connect() { if (this->trying_loaded_ap_) { this->trying_loaded_ap_ = false; this->selected_sta_index_ = 0; // Retry from the first configured AP - this->num_retried_ = 0; + this->reset_for_next_ap_attempt_(); } else if (this->selected_sta_index_ >= static_cast(this->sta_.size()) - 1) { // Exhausted all configured APs, fall back to full scan ESP_LOGW(TAG, "No more APs to try, starting scan"); @@ -831,7 +831,7 @@ void WiFiComponent::retry_connect() { } else { // Try next AP this->selected_sta_index_++; - this->num_retried_ = 0; + this->reset_for_next_ap_attempt_(); } #else if (this->num_retried_ > 5) { diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index 2e7a0728b4..739585c6fc 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -385,6 +385,13 @@ class WiFiComponent : public Component { this->start_connecting(connection_params, two); } + // Reset state for next fast connect AP attempt + // Clears old scan data so the new AP is tried with config only (SSID without specific BSSID/channel) + void reset_for_next_ap_attempt_() { + this->num_retried_ = 0; + this->scan_result_.clear(); + } + void wifi_loop_(); bool wifi_mode_(optional sta, optional ap); bool wifi_sta_pre_setup_();