diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index fae50f97a33..38f0b628b2c 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -34,7 +34,7 @@ from homeassistant.components.network import async_get_source_ip from homeassistant.const import EVENT_HOMEASSISTANT_STOP, SERVER_PORT from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import storage +from homeassistant.helpers import frame, storage import homeassistant.helpers.config_validation as cv from homeassistant.helpers.http import ( KEY_ALLOW_CONFIGURED_CORS, @@ -480,6 +480,16 @@ class HomeAssistantHTTP: self, url_path: str, path: str, cache_headers: bool = True ) -> None: """Register a folder or file to serve as a static path.""" + frame.report( + "calls hass.http.register_static_path which is deprecated because " + "it does blocking I/O in the event loop, instead " + "call `await hass.http.async_register_static_path(" + f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`; ' + "This function will be removed in 2025.7", + exclude_integrations={"http"}, + error_if_core=False, + error_if_integration=False, + ) configs = [StaticPathConfig(url_path, path, cache_headers)] resources = self._make_static_resources(configs) self._async_register_static_paths(configs, resources) diff --git a/tests/components/http/test_init.py b/tests/components/http/test_init.py index 489be0878b3..995be3954d9 100644 --- a/tests/components/http/test_init.py +++ b/tests/components/http/test_init.py @@ -526,3 +526,24 @@ async def test_logging( response = await client.get("/api/states/logging.entity") assert response.status == HTTPStatus.OK assert "GET /api/states/logging.entity" not in caplog.text + + +async def test_register_static_paths( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + caplog: pytest.LogCaptureFixture, +) -> None: + """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 ( + "Detected code that calls hass.http.register_static_path " + "which is deprecated because it does blocking I/O in the " + "event loop, instead call " + "`await hass.http.async_register_static_path" + ) in caplog.text