From 645820304fa4cbf5f2ce85de35d5f10edfef8a55 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 6 Nov 2025 16:28:54 -0600 Subject: [PATCH] reduce complexity --- esphome/components/wifi/wifi_component.cpp | 6 +++--- esphome/components/wifi/wifi_component.h | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index a2d43b7d2e..fb7ca15a7a 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -343,7 +343,7 @@ void WiFiComponent::clear_sta() { this->selected_sta_index_ = -1; } -WiFiAP WiFiComponent::build_selected_ap_() const { +void WiFiComponent::start_connecting_to_selected_(bool two) { WiFiAP params; if (const WiFiAP *config = this->get_selected_sta_()) { @@ -384,7 +384,7 @@ WiFiAP WiFiComponent::build_selected_ap_() const { } } - return params; + this->start_connecting(params, two); } bool WiFiComponent::sync_selected_sta_to_best_scan_result_() { @@ -708,7 +708,7 @@ void WiFiComponent::check_scanning_finished() { // SYNCHRONIZATION POINT: Establish link between scan_result_[0] and selected_sta_index_ // After sorting, scan_result_[0] contains the best network. Now find which sta_[i] config // matches that network and record it in selected_sta_index_. This keeps the two indices - // synchronized so build_selected_ap_() can safely use both to build connection parameters. + // synchronized so start_connecting_to_selected_() can safely use both to build connection parameters. if (!this->sync_selected_sta_to_best_scan_result_()) { ESP_LOGW(TAG, "No matching network found"); this->retry_connect(); diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index ad879ef7d5..aba087c07b 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -339,7 +339,7 @@ class WiFiComponent : public Component { #endif // USE_WIFI_AP void print_connect_params_(); - WiFiAP build_selected_ap_() const; + void start_connecting_to_selected_(bool two); const WiFiAP *get_selected_sta_() const { if (this->selected_sta_index_ >= 0 && static_cast(this->selected_sta_index_) < this->sta_.size()) { @@ -372,11 +372,6 @@ class WiFiComponent : public Component { // Returns true if match found, false otherwise bool sync_selected_sta_to_best_scan_result_(); - void start_connecting_to_selected_(bool two) { - WiFiAP connection_params = this->build_selected_ap_(); - this->start_connecting(connection_params, two); - } - #ifdef USE_WIFI_FAST_CONNECT // 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)