diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 5d17c0c46b1..6f4647030dd 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -235,8 +235,11 @@ class RegistryEntry: display_dict["ec"] = ENTITY_CATEGORY_VALUE_TO_INDEX[category] if self.hidden_by is not None: display_dict["hb"] = True - if not self.name and self.has_entity_name: - display_dict["en"] = self.original_name + if self.has_entity_name: + display_dict["hn"] = True + name = self.name or self.original_name + if name is not None: + display_dict["en"] = name if self.domain == "sensor" and (sensor_options := self.options.get("sensor")): if (precision := sensor_options.get("display_precision")) is not None or ( precision := sensor_options.get("suggested_display_precision") diff --git a/tests/components/config/test_entity_registry.py b/tests/components/config/test_entity_registry.py index 60657d4a77b..bfbd69ec9bd 100644 --- a/tests/components/config/test_entity_registry.py +++ b/tests/components/config/test_entity_registry.py @@ -245,6 +245,7 @@ async def test_list_entities_for_display( "ec": 1, "ei": "test_domain.test", "en": "Hello World", + "hn": True, "ic": "mdi:icon", "lb": [], "pl": "test_platform", @@ -254,7 +255,7 @@ async def test_list_entities_for_display( "ai": "area52", "di": "device123", "ei": "test_domain.nameless", - "en": None, + "hn": True, "lb": [], "pl": "test_platform", }, @@ -262,6 +263,8 @@ async def test_list_entities_for_display( "ai": "area52", "di": "device123", "ei": "test_domain.renamed", + "en": "User name", + "hn": True, "lb": [], "pl": "test_platform", }, @@ -326,6 +329,7 @@ async def test_list_entities_for_display( "ai": "area52", "di": "device123", "ei": "test_domain.test", + "hn": True, "lb": [], "en": "Hello World", "pl": "test_platform",