diff --git a/esphome/components/web_server/__init__.py b/esphome/components/web_server/__init__.py index 3f6df7e044..112162adf6 100644 --- a/esphome/components/web_server/__init__.py +++ b/esphome/components/web_server/__init__.py @@ -400,10 +400,10 @@ def _final_validate_ap_mode(config: ConfigType) -> None: if captive else "", ) - elif captive and not wifi_is_ap_only(wifi_config): + elif captive: _LOGGER.info( - "web_server will act as a captive portal while the fallback access point " - "is active." + "web_server will act as a captive portal while the %saccess point is active.", + "" if wifi_is_ap_only(wifi_config) else "fallback ", ) if not wifi_is_ap_only(wifi_config): return diff --git a/tests/unit_tests/components/test_web_server.py b/tests/unit_tests/components/test_web_server.py index bf52b737d5..efa79d5707 100644 --- a/tests/unit_tests/components/test_web_server.py +++ b/tests/unit_tests/components/test_web_server.py @@ -127,15 +127,24 @@ def test_final_validate_ap_mode_port_warning_uses_manual_ip( assert "http://10.0.0.1:8080/" in caplog.text -def test_final_validate_ap_mode_informs_fallback_captive( - caplog: pytest.LogCaptureFixture, +@pytest.mark.parametrize( + ("wifi_config", "expected"), + [ + # Explicit local: true on a fallback AP: announce the captive fallback role. + (AP_FALLBACK, "fallback access point"), + # Explicit local: true on AP only skips the implied-local info; still announce. + (AP_ONLY, "captive portal while the access point"), + ], +) +def test_final_validate_ap_mode_informs_explicit_local_captive( + wifi_config: dict, expected: str, caplog: pytest.LogCaptureFixture ) -> None: - """Explicit local: true on a fallback AP logs that web_server becomes captive.""" + """Explicit local: true logs that web_server becomes the captive portal.""" config = {CONF_VERSION: 2, CONF_PORT: 80, CONF_LOCAL: True} - token = fv.full_config.set({"web_server": config, CONF_WIFI: AP_FALLBACK}) + token = fv.full_config.set({"web_server": config, CONF_WIFI: wifi_config}) try: with caplog.at_level(logging.INFO): _final_validate_ap_mode(config) finally: fv.full_config.reset(token) - assert "fallback access point" in caplog.text + assert expected in caplog.text