1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add Entity.has_entity_name attribute (#73217)

This commit is contained in:
Erik Montnemery
2022-06-28 18:38:05 +02:00
committed by GitHub
parent c883aec711
commit 26a85c6644
9 changed files with 186 additions and 18 deletions

View File

@@ -1392,3 +1392,49 @@ class SlowEntity(MockEntity):
"""Make sure control is returned to the event loop on add."""
await asyncio.sleep(0.1)
await super().async_added_to_hass()
@pytest.mark.parametrize(
"has_entity_name, entity_name, expected_entity_id",
(
(False, "Entity Blu", "test_domain.entity_blu"),
(False, None, "test_domain.test_qwer"), # Set to <platform>_<unique_id>
(True, "Entity Blu", "test_domain.device_bla_entity_blu"),
(True, None, "test_domain.device_bla"),
),
)
async def test_entity_name_influences_entity_id(
hass, has_entity_name, entity_name, expected_entity_id
):
"""Test entity_id is influenced by entity name."""
registry = er.async_get(hass)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Mock setup entry method."""
async_add_entities(
[
MockEntity(
unique_id="qwer",
device_info={
"identifiers": {("hue", "1234")},
"connections": {(dr.CONNECTION_NETWORK_MAC, "abcd")},
"name": "Device Bla",
},
has_entity_name=has_entity_name,
name=entity_name,
),
]
)
return True
platform = MockPlatform(async_setup_entry=async_setup_entry)
config_entry = MockConfigEntry(entry_id="super-mock-id")
entity_platform = MockEntityPlatform(
hass, platform_name=config_entry.domain, platform=platform
)
assert await entity_platform.async_setup_entry(config_entry)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids()) == 1
assert registry.async_get(expected_entity_id) is not None