Ensure icon translations aren't the same as the default (#108568)
This commit is contained in:
parent
ec15b0def2
commit
fa485513d5
4 changed files with 35 additions and 19 deletions
|
@ -27,17 +27,13 @@
|
||||||
"damper": {
|
"damper": {
|
||||||
"default": "mdi:circle",
|
"default": "mdi:circle",
|
||||||
"state": {
|
"state": {
|
||||||
"closed": "mdi:circle-slice-8",
|
"closed": "mdi:circle-slice-8"
|
||||||
"closing": "mdi:circle",
|
|
||||||
"opening": "mdi:circle"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"door": {
|
"door": {
|
||||||
"default": "mdi:door-open",
|
"default": "mdi:door-open",
|
||||||
"state": {
|
"state": {
|
||||||
"closed": "mdi:door-closed",
|
"closed": "mdi:door-closed"
|
||||||
"closing": "mdi:door-open",
|
|
||||||
"opening": "mdi:door-open"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"garage": {
|
"garage": {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"_": {
|
"_": {
|
||||||
"default": "mdi:cast",
|
"default": "mdi:cast",
|
||||||
"state": {
|
"state": {
|
||||||
"off": "mdi:cast",
|
"off": "mdi:cast-off",
|
||||||
"paused": "mdi:cast-connected",
|
"paused": "mdi:cast-connected",
|
||||||
"playing": "mdi:cast-connected"
|
"playing": "mdi:cast-connected"
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
"hail": "mdi:weather-hail",
|
"hail": "mdi:weather-hail",
|
||||||
"lightning": "mdi:weather-lightning",
|
"lightning": "mdi:weather-lightning",
|
||||||
"lightning-rainy": "mdi:weather-lightning-rainy",
|
"lightning-rainy": "mdi:weather-lightning-rainy",
|
||||||
"partlycloudy": "mdi:weather-partly-cloudy",
|
|
||||||
"pouring": "mdi:weather-pouring",
|
"pouring": "mdi:weather-pouring",
|
||||||
"rainy": "mdi:weather-rainy",
|
"rainy": "mdi:weather-rainy",
|
||||||
"snowy": "mdi:weather-snowy",
|
"snowy": "mdi:weather-snowy",
|
||||||
|
|
|
@ -32,6 +32,20 @@ def require_default_icon_validator(value: dict) -> dict:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_not_same_as_default(value: dict) -> dict:
|
||||||
|
"""Validate an icon isn't the same as its default icon."""
|
||||||
|
for translation_key, section in value.items():
|
||||||
|
if (default := section.get("default")) and (states := section.get("state")):
|
||||||
|
for state, icon in states.items():
|
||||||
|
if icon == default:
|
||||||
|
raise vol.Invalid(
|
||||||
|
f"The icon for state `{translation_key}.{state}` is the"
|
||||||
|
" same as the default icon and thus can be removed"
|
||||||
|
)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def icon_schema(integration_type: str) -> vol.Schema:
|
def icon_schema(integration_type: str) -> vol.Schema:
|
||||||
"""Create a icon schema."""
|
"""Create a icon schema."""
|
||||||
|
|
||||||
|
@ -44,12 +58,15 @@ def icon_schema(integration_type: str) -> vol.Schema:
|
||||||
return {
|
return {
|
||||||
marker("default"): icon_value_validator,
|
marker("default"): icon_value_validator,
|
||||||
vol.Optional("state"): state_validator,
|
vol.Optional("state"): state_validator,
|
||||||
vol.Optional("state_attributes"): cv.schema_with_slug_keys(
|
vol.Optional("state_attributes"): vol.All(
|
||||||
{
|
cv.schema_with_slug_keys(
|
||||||
marker("default"): icon_value_validator,
|
{
|
||||||
marker("state"): state_validator,
|
marker("default"): icon_value_validator,
|
||||||
},
|
marker("state"): state_validator,
|
||||||
slug_validator=translation_key_validator,
|
},
|
||||||
|
slug_validator=translation_key_validator,
|
||||||
|
),
|
||||||
|
ensure_not_same_as_default,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,18 +85,22 @@ def icon_schema(integration_type: str) -> vol.Schema:
|
||||||
slug_validator=vol.Any("_", cv.slug),
|
slug_validator=vol.Any("_", cv.slug),
|
||||||
),
|
),
|
||||||
require_default_icon_validator,
|
require_default_icon_validator,
|
||||||
|
ensure_not_same_as_default,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return base_schema.extend(
|
return base_schema.extend(
|
||||||
{
|
{
|
||||||
vol.Optional("entity"): 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,
|
||||||
),
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue