Add has_entity_name to entity display dict and fix name ()

* Add has_entity_name to entity display dict and fix name

* Fix tests
pull/126257/head
Paul Bottein 2024-09-19 11:35:44 +02:00 committed by GitHub
parent d90cdf24f5
commit b471a6e519
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions
homeassistant/helpers
tests/components/config

View File

@ -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")

View File

@ -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",