Skip to content

Commit c602a0e

Browse files
Deprecated hass.http.register_static_path now raises error (home-assistant#147039)
1 parent 513045e commit c602a0e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

homeassistant/components/http/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,14 @@ def register_static_path(
511511
) -> None:
512512
"""Register a folder or file to serve as a static path."""
513513
frame.report_usage(
514-
"calls hass.http.register_static_path which is deprecated because "
515-
"it does blocking I/O in the event loop, instead "
514+
"calls hass.http.register_static_path which "
515+
"does blocking I/O in the event loop, instead "
516516
"call `await hass.http.async_register_static_paths("
517517
f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`',
518518
exclude_integrations={"http"},
519-
core_behavior=frame.ReportBehavior.LOG,
519+
core_behavior=frame.ReportBehavior.ERROR,
520+
core_integration_behavior=frame.ReportBehavior.ERROR,
521+
custom_integration_behavior=frame.ReportBehavior.ERROR,
520522
breaks_in_ha_version="2025.7",
521523
)
522524
configs = [StaticPathConfig(url_path, path, cache_headers)]

tests/components/http/test_cors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from aiohttp.test_utils import TestClient
1717
import pytest
1818

19+
from homeassistant.components.http import StaticPathConfig
1920
from homeassistant.components.http.cors import setup_cors
2021
from homeassistant.core import HomeAssistant
2122
from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS, HomeAssistantView
@@ -157,7 +158,9 @@ async def test_cors_on_static_files(
157158
assert await async_setup_component(
158159
hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}}
159160
)
160-
hass.http.register_static_path("/something", str(Path(__file__).parent))
161+
await hass.http.async_register_static_paths(
162+
[StaticPathConfig("/something", str(Path(__file__).parent))]
163+
)
161164

162165
client = await hass_client()
163166
resp = await client.options(

tests/components/http/test_init.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,14 @@ async def test_register_static_paths(
530530
"""Test registering a static path with old api."""
531531
assert await async_setup_component(hass, "frontend", {})
532532
path = str(Path(__file__).parent)
533-
hass.http.register_static_path("/something", path)
534-
client = await hass_client()
535-
resp = await client.get("/something/__init__.py")
536-
assert resp.status == HTTPStatus.OK
537533

538-
assert (
534+
match_error = (
539535
"Detected code that calls hass.http.register_static_path "
540-
"which is deprecated because it does blocking I/O in the "
541-
"event loop, instead call "
536+
"which does blocking I/O in the event loop, instead call "
542537
"`await hass.http.async_register_static_paths"
543-
) in caplog.text
538+
)
539+
with pytest.raises(RuntimeError, match=match_error):
540+
hass.http.register_static_path("/something", path)
544541

545542

546543
async def test_ssl_issue_if_no_urls_configured(

0 commit comments

Comments
 (0)