1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 14:55:50 +00:00

defensive to make bot happy

This commit is contained in:
J. Nick Koston
2025-11-06 15:40:32 -06:00
parent b74f415509
commit b366bc8dba
2 changed files with 22 additions and 20 deletions

View File

@@ -396,6 +396,27 @@ WiFiAP WiFiComponent::build_selected_ap_() const {
return params;
}
bool WiFiComponent::sync_selected_sta_to_best_scan_result_() {
if (this->scan_result_.empty())
return false;
const WiFiScanResult &scan_res = this->scan_result_[0];
if (!scan_res.get_matches())
return false;
for (size_t i = 0; i < this->sta_.size(); i++) {
if (scan_res.matches(this->sta_[i])) {
if (i > std::numeric_limits<int8_t>::max()) {
ESP_LOGE(TAG, "AP index %zu too large", i);
return false;
}
this->selected_sta_index_ = static_cast<int8_t>(i); // Links scan_result_[0] with sta_[i]
return true;
}
}
return false;
}
WiFiAP WiFiComponent::get_sta() {
const WiFiAP *config = this->get_selected_sta_();
return config ? *config : WiFiAP{};

View File

@@ -365,26 +365,7 @@ class WiFiComponent : public Component {
// Find which sta_[i] matches scan_result_[0] and set selected_sta_index_ (scan done path)
// Returns true if match found, false otherwise
bool sync_selected_sta_to_best_scan_result_() {
if (this->scan_result_.empty())
return false;
const WiFiScanResult &scan_res = this->scan_result_[0];
if (!scan_res.get_matches())
return false;
for (size_t i = 0; i < this->sta_.size(); i++) {
if (scan_res.matches(this->sta_[i])) {
if (i > std::numeric_limits<int8_t>::max()) {
ESP_LOGE(TAG, "AP index %zu too large", i);
continue;
}
this->selected_sta_index_ = static_cast<int8_t>(i); // Links scan_result_[0] with sta_[i]
return true;
}
}
return false;
}
bool sync_selected_sta_to_best_scan_result_();
void start_connecting_to_selected_(bool two) {
WiFiAP connection_params = this->build_selected_ap_();