[wifi] Use numeric scheduler ids instead of string names (#20357)

This commit is contained in:
J. Nick Koston
2026-10-09 07:20:59 -10:00
committed by GitHub
parent f5ce33a8de
commit 0701329ea7
2 changed files with 9 additions and 5 deletions
+7 -4
View File
@@ -76,13 +76,13 @@ template<typename... Ts> class WiFiConfigureAction final : public Action<Ts...>,
// Enable WiFi
global_wifi_component->enable();
// Set timeout for the connection
this->set_timeout("wifi-connect-timeout", this->connection_timeout_.value(x...), [this, x...]() {
this->set_timeout(CONNECT_TIMEOUT_ID, this->connection_timeout_.value(x...), [this, x...]() {
// If the timeout is reached, stop connecting and revert to the old AP
global_wifi_component->disable();
global_wifi_component->save_wifi_sta(old_sta_.get_ssid(), old_sta_.get_password());
global_wifi_component->enable();
// Start a timeout for the fallback if the connection to the old AP fails
this->set_timeout("wifi-fallback-timeout", this->connection_timeout_.value(x...), [this]() {
this->set_timeout(FALLBACK_TIMEOUT_ID, this->connection_timeout_.value(x...), [this]() {
this->connecting_ = false;
this->error_trigger_.trigger();
});
@@ -97,8 +97,8 @@ template<typename... Ts> class WiFiConfigureAction final : public Action<Ts...>,
return;
if (global_wifi_component->is_connected()) {
// The WiFi is connected, stop the timeout and reset the connecting flag
this->cancel_timeout("wifi-connect-timeout");
this->cancel_timeout("wifi-fallback-timeout");
this->cancel_timeout(CONNECT_TIMEOUT_ID);
this->cancel_timeout(FALLBACK_TIMEOUT_ID);
this->connecting_ = false;
char ssid_buf[SSID_BUFFER_SIZE];
if (strcmp(global_wifi_component->wifi_ssid_to(ssid_buf), this->new_sta_.get_ssid().c_str()) == 0) {
@@ -112,6 +112,9 @@ template<typename... Ts> class WiFiConfigureAction final : public Action<Ts...>,
}
protected:
static constexpr uint32_t CONNECT_TIMEOUT_ID = 0;
static constexpr uint32_t FALLBACK_TIMEOUT_ID = 1;
bool connecting_{false};
WiFiAP new_sta_;
WiFiAP old_sta_;
+2 -1
View File
@@ -398,6 +398,7 @@ static constexpr uint32_t WIFI_AP_EXCLUSIVE_DWELL_MS = 300000;
/// disconnect event cannot keep the networks from being tried for good.
static constexpr uint32_t WIFI_AP_EXCLUSIVE_MAX_DWELL_MS = 3 * WIFI_AP_EXCLUSIVE_DWELL_MS;
static constexpr uint32_t WIFI_AP_EXCLUSIVE_HANDOVER_MS = 1000;
static constexpr uint32_t AP_HANDOVER_TIMEOUT_ID = 0;
#endif
/// Cooldown duration when fallback AP is active and captive portal may be running
@@ -1222,7 +1223,7 @@ void WiFiComponent::connect_soon_() {
// New credentials from the portal: the AP pauses for them once its answer
// is out, and the STA state machine picks them up from there.
if (this->ap_setup_) {
this->set_timeout("wifi-ap-handover", WIFI_AP_EXCLUSIVE_HANDOVER_MS, [this]() {
this->set_timeout(AP_HANDOVER_TIMEOUT_ID, WIFI_AP_EXCLUSIVE_HANDOVER_MS, [this]() {
if (this->ap_setup_)
this->pause_exclusive_ap_();
});