mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 19:09:32 +00:00
Improve validation of entity service schemas (#124102)
* Improve validation of entity service schemas * Update tests/helpers/test_entity_platform.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
@@ -23,7 +23,7 @@ from homeassistant.core import (
|
||||
callback,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError, PlatformNotReady
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers import config_validation as cv, discovery
|
||||
from homeassistant.helpers.entity_component import EntityComponent, async_update_entity
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
@@ -559,28 +559,28 @@ async def test_register_entity_service(
|
||||
async def test_register_entity_service_non_entity_service_schema(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test attempting to register a service with an incomplete schema."""
|
||||
"""Test attempting to register a service with a non entity service schema."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=(
|
||||
"The schema does not include all required keys: entity_id, device_id, area_id, "
|
||||
"floor_id, label_id"
|
||||
),
|
||||
for schema in (
|
||||
vol.Schema({"some": str}),
|
||||
vol.All(vol.Schema({"some": str})),
|
||||
vol.Any(vol.Schema({"some": str})),
|
||||
):
|
||||
component.async_register_entity_service(
|
||||
"hello", vol.Schema({"some": str}), Mock()
|
||||
)
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=("The schema is not an entity service schema"),
|
||||
):
|
||||
component.async_register_entity_service("hello", schema, Mock())
|
||||
|
||||
# The check currently does not recurse into vol.All or vol.Any allowing these
|
||||
# non-compliant schemas to pass
|
||||
component.async_register_entity_service(
|
||||
"hello", vol.All(vol.Schema({"some": str})), Mock()
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
"hello", vol.Any(vol.Schema({"some": str})), Mock()
|
||||
)
|
||||
for idx, schema in enumerate(
|
||||
(
|
||||
cv.make_entity_service_schema({"some": str}),
|
||||
vol.Schema(cv.make_entity_service_schema({"some": str})),
|
||||
vol.All(cv.make_entity_service_schema({"some": str})),
|
||||
)
|
||||
):
|
||||
component.async_register_entity_service(f"test_service_{idx}", schema, Mock())
|
||||
|
||||
|
||||
async def test_register_entity_service_response_data(hass: HomeAssistant) -> None:
|
||||
|
||||
Reference in New Issue
Block a user