mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Don't raise when registering entity service with invalid schema (#125057)
* Don't raise when registering entity service with invalid schema * Update homeassistant/helpers/service.py Co-authored-by: Robert Resch <robert@resch.dev> --------- Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
fbfd8c48aa
commit
114e254aa6
@ -1268,7 +1268,16 @@ def async_register_entity_service(
|
|||||||
# the check could be extended to require All/Any to have sub schema(s)
|
# the check could be extended to require All/Any to have sub schema(s)
|
||||||
# with all entity service fields
|
# with all entity service fields
|
||||||
elif not cv.is_entity_service_schema(schema):
|
elif not cv.is_entity_service_schema(schema):
|
||||||
raise HomeAssistantError("The schema is not an entity service schema")
|
# pylint: disable-next=import-outside-toplevel
|
||||||
|
from .frame import report
|
||||||
|
|
||||||
|
report(
|
||||||
|
(
|
||||||
|
"registers an entity service with a non entity service schema "
|
||||||
|
"which will stop working in HA Core 2025.9"
|
||||||
|
),
|
||||||
|
error_if_core=False,
|
||||||
|
)
|
||||||
|
|
||||||
service_func: str | HassJob[..., Any]
|
service_func: str | HassJob[..., Any]
|
||||||
service_func = func if isinstance(func, str) else HassJob(func)
|
service_func = func if isinstance(func, str) else HassJob(func)
|
||||||
|
@ -557,21 +557,22 @@ async def test_register_entity_service(
|
|||||||
|
|
||||||
|
|
||||||
async def test_register_entity_service_non_entity_service_schema(
|
async def test_register_entity_service_non_entity_service_schema(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test attempting to register a service with a non entity service schema."""
|
"""Test attempting to register a service with a non entity service schema."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||||
|
expected_message = "registers an entity service with a non entity service schema"
|
||||||
|
|
||||||
for schema in (
|
for idx, schema in enumerate(
|
||||||
|
(
|
||||||
vol.Schema({"some": str}),
|
vol.Schema({"some": str}),
|
||||||
vol.All(vol.Schema({"some": str})),
|
vol.All(vol.Schema({"some": str})),
|
||||||
vol.Any(vol.Schema({"some": str})),
|
vol.Any(vol.Schema({"some": str})),
|
||||||
|
)
|
||||||
):
|
):
|
||||||
with pytest.raises(
|
component.async_register_entity_service(f"hello_{idx}", schema, Mock())
|
||||||
HomeAssistantError,
|
assert expected_message in caplog.text
|
||||||
match=("The schema is not an entity service schema"),
|
caplog.clear()
|
||||||
):
|
|
||||||
component.async_register_entity_service("hello", schema, Mock())
|
|
||||||
|
|
||||||
for idx, schema in enumerate(
|
for idx, schema in enumerate(
|
||||||
(
|
(
|
||||||
@ -581,6 +582,7 @@ async def test_register_entity_service_non_entity_service_schema(
|
|||||||
)
|
)
|
||||||
):
|
):
|
||||||
component.async_register_entity_service(f"test_service_{idx}", schema, Mock())
|
component.async_register_entity_service(f"test_service_{idx}", schema, Mock())
|
||||||
|
assert expected_message not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_register_entity_service_response_data(hass: HomeAssistant) -> None:
|
async def test_register_entity_service_response_data(hass: HomeAssistant) -> None:
|
||||||
|
@ -1811,23 +1811,24 @@ async def test_register_entity_service_none_schema(
|
|||||||
|
|
||||||
|
|
||||||
async def test_register_entity_service_non_entity_service_schema(
|
async def test_register_entity_service_non_entity_service_schema(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test attempting to register a service with a non entity service schema."""
|
"""Test attempting to register a service with a non entity service schema."""
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, domain="mock_integration", platform_name="mock_platform", platform=None
|
hass, domain="mock_integration", platform_name="mock_platform", platform=None
|
||||||
)
|
)
|
||||||
|
expected_message = "registers an entity service with a non entity service schema"
|
||||||
|
|
||||||
for schema in (
|
for idx, schema in enumerate(
|
||||||
|
(
|
||||||
vol.Schema({"some": str}),
|
vol.Schema({"some": str}),
|
||||||
vol.All(vol.Schema({"some": str})),
|
vol.All(vol.Schema({"some": str})),
|
||||||
vol.Any(vol.Schema({"some": str})),
|
vol.Any(vol.Schema({"some": str})),
|
||||||
|
)
|
||||||
):
|
):
|
||||||
with pytest.raises(
|
entity_platform.async_register_entity_service(f"hello_{idx}", schema, Mock())
|
||||||
HomeAssistantError,
|
assert expected_message in caplog.text
|
||||||
match="The schema is not an entity service schema",
|
caplog.clear()
|
||||||
):
|
|
||||||
entity_platform.async_register_entity_service("hello", schema, Mock())
|
|
||||||
|
|
||||||
for idx, schema in enumerate(
|
for idx, schema in enumerate(
|
||||||
(
|
(
|
||||||
@ -1839,6 +1840,7 @@ async def test_register_entity_service_non_entity_service_schema(
|
|||||||
entity_platform.async_register_entity_service(
|
entity_platform.async_register_entity_service(
|
||||||
f"test_service_{idx}", schema, Mock()
|
f"test_service_{idx}", schema, Mock()
|
||||||
)
|
)
|
||||||
|
assert expected_message not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("update_before_add", [True, False])
|
@pytest.mark.parametrize("update_before_add", [True, False])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user