This commit is contained in:
G Johansson
2025-08-27 18:09:01 +00:00
parent 55dbc2fa67
commit 2432104f5f
3 changed files with 7 additions and 3 deletions

View File

@@ -1134,7 +1134,9 @@ def async_register_entity_service(
if schema is None or isinstance(schema, dict): if schema is None or isinstance(schema, dict):
schema = cv.make_entity_service_schema(schema) schema = cv.make_entity_service_schema(schema)
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") raise HomeAssistantError(
f"The {domain}.{name} service registers an entity service with a non entity service schema"
)
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)

View File

@@ -564,7 +564,6 @@ async def test_register_entity_service_non_entity_service_schema(
) -> 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 = "The schema is not an entity service schema"
for idx, schema in enumerate( for idx, schema in enumerate(
( (
@@ -573,6 +572,7 @@ async def test_register_entity_service_non_entity_service_schema(
vol.Any(vol.Schema({"some": str})), vol.Any(vol.Schema({"some": str})),
) )
): ):
expected_message = f"The test_domain.hello_{idx} service registers an entity service with a non entity service schema"
with pytest.raises(HomeAssistantError, match=expected_message): with pytest.raises(HomeAssistantError, match=expected_message):
component.async_register_entity_service(f"hello_{idx}", schema, Mock()) component.async_register_entity_service(f"hello_{idx}", schema, Mock())
@@ -583,6 +583,7 @@ async def test_register_entity_service_non_entity_service_schema(
vol.All(cv.make_entity_service_schema({"some": str})), vol.All(cv.make_entity_service_schema({"some": str})),
) )
): ):
expected_message = f"The test_domain.hello_{idx} service registers an entity service with a 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())

View File

@@ -1884,7 +1884,6 @@ async def test_register_entity_service_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 = "The schema is not an entity service schema"
for idx, schema in enumerate( for idx, schema in enumerate(
( (
@@ -1893,6 +1892,7 @@ async def test_register_entity_service_non_entity_service_schema(
vol.Any(vol.Schema({"some": str})), vol.Any(vol.Schema({"some": str})),
) )
): ):
expected_message = f"The mock_platform.hello_{idx} service registers an entity service with a non entity service schema"
with pytest.raises(HomeAssistantError, match=expected_message): with pytest.raises(HomeAssistantError, match=expected_message):
entity_platform.async_register_entity_service( entity_platform.async_register_entity_service(
f"hello_{idx}", schema, Mock() f"hello_{idx}", schema, Mock()
@@ -1905,6 +1905,7 @@ async def test_register_entity_service_non_entity_service_schema(
vol.All(cv.make_entity_service_schema({"some": str})), vol.All(cv.make_entity_service_schema({"some": str})),
) )
): ):
expected_message = f"The mock_platform.hello_{idx} service registers an entity service with a 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()
) )