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,21 +1253,19 @@ 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. vol.Remove("metadata"): dict,
vol.Remove("metadata"): dict, **schema,
**schema, **ENTITY_SERVICE_FIELDS,
**ENTITY_SERVICE_FIELDS, },
}, extra=extra,
extra=extra, ),
), _HAS_ENTITY_SERVICE_FIELD,
_HAS_ENTITY_SERVICE_FIELD,
)
) )
@ -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