entity services without a correct schema now fails

This commit is contained in:
G Johansson
2025-08-25 17:08:34 +00:00
parent c0b1536cd8
commit 55dbc2fa67
3 changed files with 11 additions and 19 deletions

View File

@@ -1134,13 +1134,7 @@ def async_register_entity_service(
if schema is None or isinstance(schema, dict):
schema = cv.make_entity_service_schema(schema)
elif not cv.is_entity_service_schema(schema):
from .frame import ReportBehavior, report_usage # noqa: PLC0415
report_usage(
"registers an entity service with a non entity service schema",
core_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.9",
)
raise HomeAssistantError("The schema is not an entity service schema")
service_func: str | HassJob[..., Any]
service_func = func if isinstance(func, str) else HassJob(func)

View File

@@ -560,11 +560,11 @@ async def test_register_entity_service(
async def test_register_entity_service_non_entity_service_schema(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
hass: HomeAssistant,
) -> None:
"""Test attempting to register a service with a non entity service schema."""
component = EntityComponent(_LOGGER, DOMAIN, hass)
expected_message = "registers an entity service with a non entity service schema"
expected_message = "The schema is not an entity service schema"
for idx, schema in enumerate(
(
@@ -573,9 +573,8 @@ async def test_register_entity_service_non_entity_service_schema(
vol.Any(vol.Schema({"some": str})),
)
):
with pytest.raises(HomeAssistantError, match=expected_message):
component.async_register_entity_service(f"hello_{idx}", schema, Mock())
assert expected_message in caplog.text
caplog.clear()
for idx, schema in enumerate(
(
@@ -585,7 +584,6 @@ async def test_register_entity_service_non_entity_service_schema(
)
):
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:

View File

@@ -1878,13 +1878,13 @@ async def test_register_entity_service_none_schema(
async def test_register_entity_service_non_entity_service_schema(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
hass: HomeAssistant,
) -> 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"
expected_message = "The schema is not an entity service schema"
for idx, schema in enumerate(
(
@@ -1893,9 +1893,10 @@ async def test_register_entity_service_non_entity_service_schema(
vol.Any(vol.Schema({"some": str})),
)
):
entity_platform.async_register_entity_service(f"hello_{idx}", schema, Mock())
assert expected_message in caplog.text
caplog.clear()
with pytest.raises(HomeAssistantError, match=expected_message):
entity_platform.async_register_entity_service(
f"hello_{idx}", schema, Mock()
)
for idx, schema in enumerate(
(
@@ -1907,7 +1908,6 @@ 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])