Fix service schema to allow for services without any fields/properties (#96346)

This commit is contained in:
Franck Nijhof 2023-07-11 19:33:07 +02:00 committed by GitHub
parent 50442c5688
commit f25d5a157a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -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"]