mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Deprecated hass.http.register_static_path now raises error (#147039)
This commit is contained in:
parent
513045e489
commit
c602a0e279
@ -511,12 +511,14 @@ class HomeAssistantHTTP:
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Register a folder or file to serve as a static path."""
|
"""Register a folder or file to serve as a static path."""
|
||||||
frame.report_usage(
|
frame.report_usage(
|
||||||
"calls hass.http.register_static_path which is deprecated because "
|
"calls hass.http.register_static_path which "
|
||||||
"it does blocking I/O in the event loop, instead "
|
"does blocking I/O in the event loop, instead "
|
||||||
"call `await hass.http.async_register_static_paths("
|
"call `await hass.http.async_register_static_paths("
|
||||||
f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`',
|
f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`',
|
||||||
exclude_integrations={"http"},
|
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",
|
breaks_in_ha_version="2025.7",
|
||||||
)
|
)
|
||||||
configs = [StaticPathConfig(url_path, path, cache_headers)]
|
configs = [StaticPathConfig(url_path, path, cache_headers)]
|
||||||
|
@ -16,6 +16,7 @@ from aiohttp.hdrs import (
|
|||||||
from aiohttp.test_utils import TestClient
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.http import StaticPathConfig
|
||||||
from homeassistant.components.http.cors import setup_cors
|
from homeassistant.components.http.cors import setup_cors
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS, HomeAssistantView
|
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(
|
assert await async_setup_component(
|
||||||
hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}}
|
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()
|
client = await hass_client()
|
||||||
resp = await client.options(
|
resp = await client.options(
|
||||||
|
@ -530,17 +530,14 @@ async def test_register_static_paths(
|
|||||||
"""Test registering a static path with old api."""
|
"""Test registering a static path with old api."""
|
||||||
assert await async_setup_component(hass, "frontend", {})
|
assert await async_setup_component(hass, "frontend", {})
|
||||||
path = str(Path(__file__).parent)
|
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 "
|
"Detected code that calls hass.http.register_static_path "
|
||||||
"which is deprecated because it does blocking I/O in the "
|
"which does blocking I/O in the event loop, instead call "
|
||||||
"event loop, instead call "
|
|
||||||
"`await hass.http.async_register_static_paths"
|
"`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(
|
async def test_ssl_issue_if_no_urls_configured(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user