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:
Erik Montnemery 2024-09-02 14:20:50 +02:00 committed by GitHub
parent fbfd8c48aa
commit 114e254aa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 21 deletions

View file

@ -1811,23 +1811,24 @@ async def test_register_entity_service_none_schema(
async def test_register_entity_service_non_entity_service_schema(
hass: HomeAssistant,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test attempting to register a service with a non entity service schema."""
entity_platform = MockEntityPlatform(
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 (
vol.Schema({"some": str}),
vol.All(vol.Schema({"some": str})),
vol.Any(vol.Schema({"some": str})),
for idx, schema in enumerate(
(
vol.Schema({"some": str}),
vol.All(vol.Schema({"some": str})),
vol.Any(vol.Schema({"some": str})),
)
):
with pytest.raises(
HomeAssistantError,
match="The schema is not an entity service schema",
):
entity_platform.async_register_entity_service("hello", schema, Mock())
entity_platform.async_register_entity_service(f"hello_{idx}", schema, Mock())
assert expected_message in caplog.text
caplog.clear()
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(
f"test_service_{idx}", schema, Mock()
)
assert expected_message not in caplog.text
@pytest.mark.parametrize("update_before_add", [True, False])