diff --git a/esphome/core/entity_helpers.py b/esphome/core/entity_helpers.py index 447c894495..e1b2a8264b 100644 --- a/esphome/core/entity_helpers.py +++ b/esphome/core/entity_helpers.py @@ -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( diff --git a/tests/unit_tests/core/test_entity_helpers.py b/tests/unit_tests/core/test_entity_helpers.py index 005728dca8..9ba5367413 100644 --- a/tests/unit_tests/core/test_entity_helpers.py +++ b/tests/unit_tests/core/test_entity_helpers.py @@ -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)