1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

revert copilot suggestion .. we will never have more then 5 anyways

This commit is contained in:
J. Nick Koston
2025-11-06 15:53:48 -06:00
parent 8eb509f8f0
commit 47874ef516

View File

@@ -841,6 +841,7 @@ void WiFiComponent::retry_connect() {
this->selected_sta_index_ = 0; // Retry from the first configured AP this->selected_sta_index_ = 0; // Retry from the first configured AP
this->reset_for_next_ap_attempt_(); this->reset_for_next_ap_attempt_();
} else if (this->selected_sta_index_ >= static_cast<int>(this->sta_.size()) - 1) { } else if (this->selected_sta_index_ >= static_cast<int>(this->sta_.size()) - 1) {
// Cast size to int (not int8_t which overflows at 127, not size_t which wraps negative indices)
// Exhausted all configured APs, restart adapter and cycle back to first // Exhausted all configured APs, restart adapter and cycle back to first
// Restart clears any stuck WiFi driver state // Restart clears any stuck WiFi driver state
// Each AP is tried with config data only (SSID + optional BSSID/channel if user configured them) // Each AP is tried with config data only (SSID + optional BSSID/channel if user configured them)
@@ -944,6 +945,8 @@ bool WiFiComponent::load_fast_connect_settings_() {
void WiFiComponent::save_fast_connect_settings_() { void WiFiComponent::save_fast_connect_settings_() {
bssid_t bssid = wifi_bssid(); bssid_t bssid = wifi_bssid();
uint8_t channel = get_wifi_channel(); uint8_t channel = get_wifi_channel();
// selected_sta_index_ is always valid here (called only after successful connection)
// Fallback to 0 is defensive programming for robustness
int8_t ap_index = this->selected_sta_index_ >= 0 ? this->selected_sta_index_ : 0; int8_t ap_index = this->selected_sta_index_ >= 0 ? this->selected_sta_index_ : 0;
// Skip save if settings haven't changed (compare with previously saved settings to reduce flash wear) // Skip save if settings haven't changed (compare with previously saved settings to reduce flash wear)