From c602a0e279ded182f9a374c7a39e29b279a8f901 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Thu, 19 Jun 2025 13:14:42 +0200 Subject: [PATCH] Deprecated hass.http.register_static_path now raises error (#147039) --- homeassistant/components/http/__init__.py | 8 +++++--- tests/components/http/test_cors.py | 5 ++++- tests/components/http/test_init.py | 13 +++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 8ee27039441..2c4b67e6c99 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -511,12 +511,14 @@ class HomeAssistantHTTP: ) -> None: """Register a folder or file to serve as a static path.""" frame.report_usage( - "calls hass.http.register_static_path which is deprecated because " - "it does blocking I/O in the event loop, instead " + "calls hass.http.register_static_path which " + "does blocking I/O in the event loop, instead " "call `await hass.http.async_register_static_paths(" f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`', exclude_integrations={"http"}, - core_behavior=frame.ReportBehavior.LOG, + core_behavior=frame.ReportBehavior.ERROR, + core_integration_behavior=frame.ReportBehavior.ERROR, + custom_integration_behavior=frame.ReportBehavior.ERROR, breaks_in_ha_version="2025.7", ) configs = [StaticPathConfig(url_path, path, cache_headers)] diff --git a/tests/components/http/test_cors.py b/tests/components/http/test_cors.py index 0581c7bac2a..bddd66a7e81 100644 --- a/tests/components/http/test_cors.py +++ b/tests/components/http/test_cors.py @@ -16,6 +16,7 @@ from aiohttp.hdrs import ( from aiohttp.test_utils import TestClient import pytest +from homeassistant.components.http import StaticPathConfig from homeassistant.components.http.cors import setup_cors from homeassistant.core import HomeAssistant from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS, HomeAssistantView @@ -157,7 +158,9 @@ async def test_cors_on_static_files( assert await async_setup_component( hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}} ) - hass.http.register_static_path("/something", str(Path(__file__).parent)) + await hass.http.async_register_static_paths( + [StaticPathConfig("/something", str(Path(__file__).parent))] + ) client = await hass_client() resp = await client.options( diff --git a/tests/components/http/test_init.py b/tests/components/http/test_init.py index 2937e673946..7858bbc123d 100644 --- a/tests/components/http/test_init.py +++ b/tests/components/http/test_init.py @@ -530,17 +530,14 @@ async def test_register_static_paths( """Test registering a static path with old api.""" assert await async_setup_component(hass, "frontend", {}) path = str(Path(__file__).parent) - hass.http.register_static_path("/something", path) - client = await hass_client() - resp = await client.get("/something/__init__.py") - assert resp.status == HTTPStatus.OK - assert ( + match_error = ( "Detected code that calls hass.http.register_static_path " - "which is deprecated because it does blocking I/O in the " - "event loop, instead call " + "which does blocking I/O in the event loop, instead call " "`await hass.http.async_register_static_paths" - ) in caplog.text + ) + with pytest.raises(RuntimeError, match=match_error): + hass.http.register_static_path("/something", path) async def test_ssl_issue_if_no_urls_configured(