From 60d6144574308b578394d0786de81286d6f11af1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 6 Nov 2025 12:02:18 -0600 Subject: [PATCH] preen --- esphome/components/wifi/wifi_component.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 76797f4a7d..ee4a27e4d4 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -367,7 +367,11 @@ WiFiAP WiFiComponent::build_selected_ap_() const { } // Overlay scan result data (if available) - // Scan results are sorted, so index 0 is always the best network + // SYNCHRONIZATION: selected_sta_index_ and scan_result_[0] are kept in sync: + // - wifi_scan_done() sorts all scan results by priority/RSSI (best first) + // - It then finds which sta_[i] config matches scan_result_[0] + // - Sets selected_sta_index_ = i to record that matching config + // Therefore scan_result_[0] is guaranteed to match sta_[selected_sta_index_] if (!this->scan_result_.empty()) { const WiFiScanResult &scan = this->scan_result_[0];