1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 03:12:20 +01:00
This commit is contained in:
J. Nick Koston
2025-08-20 12:15:54 -05:00
parent d182ce8bf6
commit 86c3812174
2 changed files with 22 additions and 2 deletions

View File

@@ -238,12 +238,12 @@ def entity_duplicate_validator(platform: str) -> Callable[[ConfigType], ConfigTy
# Show both original names and their ASCII-only versions if they differ
sanitized_msg = ""
if entity_name != name_key or existing_name != name_key:
if entity_name != existing_name:
sanitized_msg = (
f"\n Original names: '{entity_name}' and '{existing_name}'"
f"\n Both convert to ASCII ID: '{name_key}'"
"\n To fix: Add unique ASCII characters (e.g., '1', '2', or 'A', 'B')"
"\n to distinguish them"
"\n to distinguish them"
)
raise cv.Invalid(

View File

@@ -730,3 +730,23 @@ def test_entity_duplicate_validator_non_ascii_names() -> None:
),
):
validator(config2)
def test_entity_duplicate_validator_same_name_no_enhanced_message() -> None:
"""Test that identical names don't show the enhanced message."""
# Create validator for sensor platform
validator = entity_duplicate_validator("sensor")
# First entity should pass
config1 = {CONF_NAME: "Temperature"}
validated1 = validator(config1)
assert validated1 == config1
# Second entity with exact same name should fail without enhanced message
config2 = {CONF_NAME: "Temperature"}
with pytest.raises(
Invalid,
match=r"Duplicate sensor entity with name 'Temperature' found.*"
r"Each entity on a device must have a unique name within its platform\.$",
):
validator(config2)