1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 08:41:59 +00:00

[wifi] Fix ESP8266 disconnect callback order to set error flag before notifying listeners (#13189)

This commit is contained in:
J. Nick Koston
2026-01-13 11:33:36 -10:00
committed by GitHub
parent 733f57da50
commit a060d1d044

View File

@@ -543,7 +543,12 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
}
s_sta_connected = false;
s_sta_connecting = false;
// IMPORTANT: Set error flag BEFORE notifying listeners.
// This ensures is_connected() returns false during listener callbacks,
// which is critical for proper reconnection logic (e.g., roaming).
global_wifi_component->error_from_callback_ = true;
#ifdef USE_WIFI_LISTENERS
// Notify listeners AFTER setting error flag so they see correct state
static constexpr uint8_t EMPTY_BSSID[6] = {};
for (auto *listener : global_wifi_component->connect_state_listeners_) {
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
@@ -635,10 +640,6 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
break;
}
if (event->event == EVENT_STAMODE_DISCONNECTED) {
global_wifi_component->error_from_callback_ = true;
}
WiFiMockClass::_event_callback(event);
}