[wifi] Fix ESP8266 disconnect callback order to set error flag before notifying listeners - #13189
Conversation
… notifying listeners
… notifying listeners
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#13189
components: [wifi]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #13189 +/- ##
==========================================
+ Coverage 73.73% 73.76% +0.02%
==========================================
Files 53 53
Lines 11329 11329
Branches 1538 1538
==========================================
+ Hits 8354 8357 +3
+ Misses 2574 2572 -2
+ Partials 401 400 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
📊 Component Memory Breakdown
🔍 Symbol-Level Changes (click to expand)Changed Symbols
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
thanks |
What does this implement/fix?
Fix WiFi disconnect callback order on ESP8266 to set
error_from_callback_before notifying listeners, matching ESP-IDF and LibreTiny behavior.Previously,
error_from_callback_was set AFTER the switch statement, which meant listeners were called before the flag was set. If a listener checkedis_connected()during the disconnect callback, it would incorrectly returntruebecauseerror_from_callback_was stillfalse.This caused issues with WiFi roaming where the device would think it was still connected after a disconnect event, preventing proper reconnection logic from triggering.
Before (incorrect):
After (correct, matches ESP-IDF):
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed:
Additional Context
Bug Timeline
6682c43derror_from_callback_set after switch - latent bug (no callbacks yet)08c8fa2cerror_from_callback_for authmode downgrade, set correctly inside case2bc8a4a726e979d3The bug was latent for ~6 years but only became an actual problem in November 2025 when disconnect callbacks were added inside the switch case while
error_from_callback_ = trueremained after the switch.