From f25d5a157a9d38e605da290ac45d88bdf1275a8d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 11 Jul 2023 19:33:07 +0200 Subject: [PATCH] Fix service schema to allow for services without any fields/properties (#96346) --- homeassistant/helpers/service.py | 4 ++-- script/hassfest/services.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 1a418a68fd1..946340ea69c 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -633,8 +633,8 @@ async def async_get_all_descriptions( # service.async_set_service_schema for the dynamic # service - yaml_description = domain_yaml.get( # type: ignore[union-attr] - service_name, {} + yaml_description = ( + domain_yaml.get(service_name) or {} # type: ignore[union-attr] ) # Don't warn for missing services, because it triggers false diff --git a/script/hassfest/services.py b/script/hassfest/services.py index 2f8e20939db..b3f59ab66a3 100644 --- a/script/hassfest/services.py +++ b/script/hassfest/services.py @@ -46,13 +46,18 @@ FIELD_SCHEMA = vol.Schema( } ) -SERVICE_SCHEMA = vol.Schema( - { - vol.Optional("description"): str, - vol.Optional("name"): str, - vol.Optional("target"): vol.Any(selector.TargetSelector.CONFIG_SCHEMA, None), - vol.Optional("fields"): vol.Schema({str: FIELD_SCHEMA}), - } +SERVICE_SCHEMA = vol.Any( + vol.Schema( + { + vol.Optional("description"): str, + vol.Optional("name"): str, + vol.Optional("target"): vol.Any( + selector.TargetSelector.CONFIG_SCHEMA, None + ), + vol.Optional("fields"): vol.Schema({str: FIELD_SCHEMA}), + } + ), + None, ) SERVICES_SCHEMA = vol.Schema({cv.slug: SERVICE_SCHEMA}) @@ -116,6 +121,8 @@ def validate_services(config: Config, integration: Integration) -> None: # For each service in the integration, check if the description if set, # if not, check if it's in the strings file. If not, add an error. for service_name, service_schema in services.items(): + if service_schema is None: + continue if "name" not in service_schema: try: strings["services"][service_name]["name"]