Add entity list to light and cover group attributes (#36477)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Thomas Lovén 2020-06-06 06:23:52 +02:00 committed by GitHub
parent 492874c4a0
commit bdc098645b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View File

@ -200,6 +200,11 @@ class CoverGroup(CoverEntity):
"""Return current tilt position for all covers."""
return self._tilt_position
@property
def device_state_attributes(self):
"""Return the state attributes for the cover group."""
return {ATTR_ENTITY_ID: self._entities}
async def async_open_cover(self, **kwargs):
"""Move the covers up."""
data = {ATTR_ENTITY_ID: self._covers[KEY_OPEN_CLOSE]}

View File

@ -183,6 +183,11 @@ class LightGroup(light.LightEntity):
"""No polling needed for a light group."""
return False
@property
def device_state_attributes(self):
"""Return the state attributes for the light group."""
return {ATTR_ENTITY_ID: self._entity_ids}
async def async_turn_on(self, **kwargs):
"""Forward the turn_on command to all lights in the light group."""
data = {ATTR_ENTITY_ID: self._entity_ids}

View File

@ -86,6 +86,12 @@ async def test_attributes(hass, setup_comp):
state = hass.states.get(COVER_GROUP)
assert state.state == STATE_CLOSED
assert state.attributes[ATTR_FRIENDLY_NAME] == DEFAULT_NAME
assert state.attributes[ATTR_ENTITY_ID] == [
DEMO_COVER,
DEMO_COVER_POS,
DEMO_COVER_TILT,
DEMO_TILT,
]
assert ATTR_ASSUMED_STATE not in state.attributes
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
assert ATTR_CURRENT_POSITION not in state.attributes

View File

@ -34,17 +34,25 @@ from tests.async_mock import MagicMock
async def test_default_state(hass):
"""Test light group default state."""
hass.states.async_set("light.kitchen", "on")
await async_setup_component(
hass,
LIGHT_DOMAIN,
{LIGHT_DOMAIN: {"platform": DOMAIN, "entities": [], "name": "Bedroom Group"}},
{
LIGHT_DOMAIN: {
"platform": DOMAIN,
"entities": ["light.kitchen", "light.bedroom"],
"name": "Bedroom Group",
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.bedroom_group")
assert state is not None
assert state.state == STATE_UNAVAILABLE
assert state.state == STATE_ON
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
assert state.attributes.get(ATTR_ENTITY_ID) == ["light.kitchen", "light.bedroom"]
assert state.attributes.get(ATTR_BRIGHTNESS) is None
assert state.attributes.get(ATTR_HS_COLOR) is None
assert state.attributes.get(ATTR_COLOR_TEMP) is None