Fix entity name validation to allow "Off" and "On" (#7821)

This commit is contained in:
Jesse Hills 2024-11-26 22:50:16 +13:00 committed by GitHub
parent 841d278224
commit 6e50e2aa65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1839,8 +1839,6 @@ def validate_registry_entry(name, registry):
def none(value): def none(value):
if value in ("none", "None"): if value in ("none", "None"):
return None return None
if boolean(value) is False:
return None
raise Invalid("Must be none") raise Invalid("Must be none")
@ -1912,17 +1910,23 @@ MQTT_COMMAND_COMPONENT_SCHEMA = MQTT_COMPONENT_SCHEMA.extend(
} }
) )
ENTITY_BASE_SCHEMA = Schema(
{ def _validate_entity_name(value):
Optional(CONF_NAME): Any( value = string(value)
All( try:
none, value = none(value) # pylint: disable=assignment-from-none
except Invalid:
pass
else:
requires_friendly_name( requires_friendly_name(
"Name cannot be None when esphome->friendly_name is not set!" "Name cannot be None when esphome->friendly_name is not set!"
), )(value)
), return value
string,
),
ENTITY_BASE_SCHEMA = Schema(
{
Optional(CONF_NAME): _validate_entity_name,
Optional(CONF_INTERNAL): boolean, Optional(CONF_INTERNAL): boolean,
Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean, Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean,
Optional(CONF_ICON): icon, Optional(CONF_ICON): icon,