From 13ee597ce04daf215f72a1687cdfc13cea21f4f4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 6 Nov 2025 11:17:17 -0600 Subject: [PATCH] preen --- esphome/components/wifi/wifi_component.cpp | 20 ++++++++------------ esphome/components/wifi/wifi_component.h | 4 ++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 2ede813289..96dc421e7f 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -915,26 +915,22 @@ void WiFiComponent::save_fast_connect_settings_() { bssid_t bssid = wifi_bssid(); uint8_t channel = get_wifi_channel(); - // Check if we need to save (compare with current scan result if available) - bool should_save = true; + // Skip save if settings haven't changed (compare with current scan result if available) if (this->selected_scan_index_ >= 0 && this->selected_scan_index_ < this->scan_result_.size()) { const WiFiScanResult &scan = this->scan_result_[this->selected_scan_index_]; if (bssid == scan.get_bssid() && channel == scan.get_channel()) { - should_save = false; + return; // No change, nothing to save } } - if (should_save) { - SavedWifiFastConnectSettings fast_connect_save{}; + SavedWifiFastConnectSettings fast_connect_save{}; + memcpy(fast_connect_save.bssid, bssid.data(), 6); + fast_connect_save.channel = channel; + fast_connect_save.ap_index = this->selected_ap_index_ >= 0 ? this->selected_ap_index_ : 0; - memcpy(fast_connect_save.bssid, bssid.data(), 6); - fast_connect_save.channel = channel; - fast_connect_save.ap_index = this->selected_ap_index_ >= 0 ? this->selected_ap_index_ : 0; + this->fast_connect_pref_.save(&fast_connect_save); - this->fast_connect_pref_.save(&fast_connect_save); - - ESP_LOGD(TAG, "Saved fast_connect settings"); - } + ESP_LOGD(TAG, "Saved fast_connect settings"); } #endif diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index ca500a5246..155c1f419e 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -426,7 +426,11 @@ class WiFiComponent : public Component { WiFiComponentState state_{WIFI_COMPONENT_STATE_OFF}; WiFiPowerSaveMode power_save_{WIFI_POWER_SAVE_NONE}; uint8_t num_retried_{0}; + // Index into sta_ array for the currently selected AP configuration (-1 = none selected) + // Used to access password, manual_ip, priority, EAP settings, and hidden flag int8_t selected_ap_index_{-1}; + // Index into scan_result_ array for the currently selected scan result (-1 = no scan data) + // Used to access scanned SSID, BSSID, and channel. Also used for fast connect (synthetic scan result) int8_t selected_scan_index_{-1}; #if USE_NETWORK_IPV6 uint8_t num_ipv6_addresses_{0};