mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 05:12:21 +01:00
Allow entity names to be set to None (#4607)
* Allow entity names to be set to None so they take on the device friendly_name automatically * Use empty
This commit is contained in:
@@ -1514,6 +1514,8 @@ def _entity_base_validator(config):
|
||||
config[CONF_NAME] = id.id
|
||||
config[CONF_INTERNAL] = True
|
||||
return config
|
||||
if config[CONF_NAME] is None:
|
||||
config[CONF_NAME] = ""
|
||||
return config
|
||||
|
||||
|
||||
@@ -1573,6 +1575,23 @@ def validate_registry_entry(name, registry):
|
||||
return validator
|
||||
|
||||
|
||||
def none(value):
|
||||
if value in ("none", "None"):
|
||||
return None
|
||||
if boolean(value) is False:
|
||||
return None
|
||||
raise Invalid("Must be none")
|
||||
|
||||
|
||||
def requires_friendly_name(message):
|
||||
def validate(value):
|
||||
if CORE.friendly_name is None:
|
||||
raise Invalid(message)
|
||||
return value
|
||||
|
||||
return validate
|
||||
|
||||
|
||||
def validate_registry(name, registry):
|
||||
return ensure_list(validate_registry_entry(name, registry))
|
||||
|
||||
@@ -1632,7 +1651,15 @@ MQTT_COMMAND_COMPONENT_SCHEMA = MQTT_COMPONENT_SCHEMA.extend(
|
||||
|
||||
ENTITY_BASE_SCHEMA = Schema(
|
||||
{
|
||||
Optional(CONF_NAME): string,
|
||||
Optional(CONF_NAME): Any(
|
||||
All(
|
||||
none,
|
||||
requires_friendly_name(
|
||||
"Name cannot be None when esphome->friendly_name is not set!"
|
||||
),
|
||||
),
|
||||
string,
|
||||
),
|
||||
Optional(CONF_INTERNAL): boolean,
|
||||
Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean,
|
||||
Optional(CONF_ICON): icon,
|
||||
|
Reference in New Issue
Block a user