[tests] Add unit test coverage for web_port property#11811
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #11811 +/- ##
==========================================
+ Coverage 72.38% 72.43% +0.05%
==========================================
Files 53 53
Lines 11134 11134
Branches 1504 1504
==========================================
+ Hits 8059 8065 +6
+ Misses 2684 2677 -7
- Partials 391 392 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive unit test coverage for the web_port property in the EsphomeCore class. The tests validate the correct behavior of web port detection and specifically address Dashboard Issue #766 regarding the distinction between the OTA web_server platform and the full web_server component.
- Added tests for
web_portproperty covering multiple scenarios - Included critical test case for OTA web_server platform edge case
- Comprehensive documentation explaining the Dashboard Issue #766 context
balloob
approved these changes
Nov 10, 2025
Member
Author
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
Adds unit test coverage for the
CORE.web_portproperty to prevent future regressions that would break the Dashboard's VISIT button functionality.Background
The Dashboard PR esphome/dashboard#826 fixes Dashboard Issue esphome/dashboard#766 by changing the VISIT button visibility logic from checking
loaded_integrationsto checkingweb_port:The issue occurred because
captive_portalauto-loadsota.web_serverplatform, causing"web_server"to appear inloaded_integrationseven when no web UI is configured.What This PR Does
This PR adds 4 unit tests in
tests/unit_tests/test_core.pyto ensure theweb_portproperty behavior remains correct:test_web_port__none- ReturnsNonewhen no web_server configuredtest_web_port__explicit_web_server_default_port- Returns80when web_server configured without porttest_web_port__explicit_web_server_custom_port- Returns custom port when explicitly settest_web_port__ota_web_server_platform_only- Critical - ReturnsNonewhen onlyota.web_serverplatform is loaded (not full web_server component)The critical test (
#4) ensures thatweb_portstaysNoneeven when:"web_server"appears inloaded_integrations(due to platform load)"ota/web_server"appears inloaded_platformsCONF_WEB_SERVERis NOT in config (no web UI)This guarantees the Dashboard fix works correctly.
Implementation Details
The
web_portproperty (inesphome/core/__init__.py:652-662) correctly checksCONF_WEB_SERVER in self.config, which is the explicit user configuration, NOTloaded_integrations:These tests ensure this behavior never changes accidentally.
Types of changes
Related issue or feature (if applicable):
Test Environment
Not applicable - these are unit tests that run in CI for all platforms.
Example entry for
config.yaml:Not applicable - no user-facing changes.
Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: