Add included_entities attribute to base Entity class

This commit is contained in:
jbouwh
2025-09-18 19:51:12 +00:00
parent 42a9d5d4e3
commit ee24acf52a
2 changed files with 56 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
@@ -926,6 +927,38 @@ async def test_attribution_attribute(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_ATTRIBUTION) == "Home Assistant"
async def test_included_entities_attribute(hass: HomeAssistant) -> None:
"""Test included_entities attribute."""
mock_entity = entity.Entity()
mock_entity.hass = hass
mock_entity.entity_id = "hello.world"
mock_entity._attr_included_entities = ["hello.oceans", "hello.continents"]
mock_entity.async_schedule_update_ha_state(True)
await hass.async_block_till_done()
state = hass.states.get(mock_entity.entity_id)
assert state.attributes.get(ATTR_ENTITY_ID) == ["hello.oceans", "hello.continents"]
async def test_included_entities_attribute_with_extra_state_attributes(
hass: HomeAssistant,
) -> None:
"""Test included_entities attribute."""
mock_entity = entity.Entity()
mock_entity.hass = hass
mock_entity.entity_id = "hello.world"
mock_entity._attr_included_entities = ["hello.oceans", "hello.continents"]
mock_entity._attr_extra_state_attributes = {"demo": "Home Assistant"}
mock_entity.async_schedule_update_ha_state(True)
await hass.async_block_till_done()
state = hass.states.get(mock_entity.entity_id)
assert state.attributes.get(ATTR_ENTITY_ID) == ["hello.oceans", "hello.continents"]
assert state.attributes.get("demo") == "Home Assistant"
async def test_entity_category_property(hass: HomeAssistant) -> None:
"""Test entity category property."""
mock_entity1 = entity.Entity()