Avoid compiling entity service schema when passed defaults (#112099)

* Avoid compiling entity service schema when passed defaults

* dry
This commit is contained in:
J. Nick Koston 2024-03-03 07:50:04 -10:00 committed by GitHub
parent 0a462071c8
commit da6eca7b68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1235,9 +1235,7 @@ TARGET_SERVICE_FIELDS = {
} }
def make_entity_service_schema( def _make_entity_service_schema(schema: dict, extra: int) -> vol.Schema:
schema: dict, *, extra: int = vol.PREVENT_EXTRA
) -> vol.Schema:
"""Create an entity service schema.""" """Create an entity service schema."""
return vol.Schema( return vol.Schema(
vol.All( vol.All(
@ -1255,6 +1253,21 @@ def make_entity_service_schema(
) )
BASE_ENTITY_SCHEMA = _make_entity_service_schema({}, vol.PREVENT_EXTRA)
def make_entity_service_schema(
schema: dict, *, extra: int = vol.PREVENT_EXTRA
) -> vol.Schema:
"""Create an entity service schema."""
if not schema and extra == vol.PREVENT_EXTRA:
# If the schema is empty and we don't allow extra keys, we can return
# the base schema and avoid compiling a new schema which is the case
# for ~50% of services.
return BASE_ENTITY_SCHEMA
return _make_entity_service_schema(schema, extra)
SCRIPT_CONVERSATION_RESPONSE_SCHEMA = vol.Any(template, None) SCRIPT_CONVERSATION_RESPONSE_SCHEMA = vol.Any(template, None)