Allow system and helper integrations to provide entity_component icons (#109045)

This commit is contained in:
Paul Bottein 2024-01-29 19:26:55 +01:00 committed by GitHub
parent be4631cbf8
commit 4170a447fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 15 deletions

View File

@ -0,0 +1,18 @@
{
"entity_component": {
"_": {
"default": "mdi:robot",
"state": {
"off": "mdi:robot-off",
"unavailable": "mdi:robot-confused"
}
}
},
"services": {
"turn_on": "mdi:robot",
"turn_off": "mdi:robot-off",
"toggle": "mdi:robot",
"trigger": "mdi:robot",
"reload": "mdi:robot"
}
}

View File

@ -70,14 +70,14 @@ def icon_schema(integration_type: str) -> vol.Schema:
), ),
} }
base_schema = vol.Schema( schema = vol.Schema(
{ {
vol.Optional("services"): state_validator, vol.Optional("services"): state_validator,
} }
) )
if integration_type == "entity": if integration_type in ("entity", "helper", "system"):
return base_schema.extend( schema = schema.extend(
{ {
vol.Required("entity_component"): vol.All( vol.Required("entity_component"): vol.All(
cv.schema_with_slug_keys( cv.schema_with_slug_keys(
@ -89,20 +89,22 @@ def icon_schema(integration_type: str) -> vol.Schema:
) )
} }
) )
return base_schema.extend( if integration_type not in ("entity", "system"):
{ schema = schema.extend(
vol.Optional("entity"): vol.All( {
cv.schema_with_slug_keys( vol.Optional("entity"): vol.All(
cv.schema_with_slug_keys( cv.schema_with_slug_keys(
icon_schema_slug(vol.Optional), cv.schema_with_slug_keys(
slug_validator=translation_key_validator, icon_schema_slug(vol.Optional),
slug_validator=translation_key_validator,
),
slug_validator=cv.slug,
), ),
slug_validator=cv.slug, ensure_not_same_as_default,
), )
ensure_not_same_as_default, }
) )
} return schema
)
def validate_icon_file(config: Config, integration: Integration) -> None: # noqa: C901 def validate_icon_file(config: Config, integration: Integration) -> None: # noqa: C901