Simplify cv._make_entity_service_schema (#124046)

This commit is contained in:
Erik Montnemery 2024-08-16 14:09:09 +02:00 committed by GitHub
parent 69943af68a
commit f1b7847d1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1253,10 +1253,9 @@ TARGET_SERVICE_FIELDS = {
_HAS_ENTITY_SERVICE_FIELD = has_at_least_one_key(*ENTITY_SERVICE_FIELDS) _HAS_ENTITY_SERVICE_FIELD = has_at_least_one_key(*ENTITY_SERVICE_FIELDS)
def _make_entity_service_schema(schema: dict, extra: int) -> vol.Schema: def _make_entity_service_schema(schema: dict, extra: int) -> VolSchemaType:
"""Create an entity service schema.""" """Create an entity service schema."""
return vol.Schema( return vol.All(
vol.All(
vol.Schema( vol.Schema(
{ {
# The frontend stores data here. Don't use in core. # The frontend stores data here. Don't use in core.
@ -1268,7 +1267,6 @@ def _make_entity_service_schema(schema: dict, extra: int) -> vol.Schema:
), ),
_HAS_ENTITY_SERVICE_FIELD, _HAS_ENTITY_SERVICE_FIELD,
) )
)
BASE_ENTITY_SCHEMA = _make_entity_service_schema({}, vol.PREVENT_EXTRA) BASE_ENTITY_SCHEMA = _make_entity_service_schema({}, vol.PREVENT_EXTRA)
@ -1276,7 +1274,7 @@ BASE_ENTITY_SCHEMA = _make_entity_service_schema({}, vol.PREVENT_EXTRA)
def make_entity_service_schema( def make_entity_service_schema(
schema: dict | None, *, extra: int = vol.PREVENT_EXTRA schema: dict | None, *, extra: int = vol.PREVENT_EXTRA
) -> vol.Schema: ) -> VolSchemaType:
"""Create an entity service schema.""" """Create an entity service schema."""
if not schema and extra == vol.PREVENT_EXTRA: if not schema and extra == vol.PREVENT_EXTRA:
# If the schema is empty and we don't allow extra keys, we can return # If the schema is empty and we don't allow extra keys, we can return