mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix media_player grouping while media_player is off (#58070)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
8017a1e141
commit
a3dbe8e1e7
@ -896,11 +896,14 @@ class MediaPlayerEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self.state == STATE_OFF:
|
|
||||||
return None
|
|
||||||
|
|
||||||
state_attr = {}
|
state_attr = {}
|
||||||
|
|
||||||
|
if self.support_grouping:
|
||||||
|
state_attr[ATTR_GROUP_MEMBERS] = self.group_members
|
||||||
|
|
||||||
|
if self.state == STATE_OFF:
|
||||||
|
return state_attr
|
||||||
|
|
||||||
for attr in ATTR_TO_PROPERTY:
|
for attr in ATTR_TO_PROPERTY:
|
||||||
value = getattr(self, attr)
|
value = getattr(self, attr)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
@ -909,9 +912,6 @@ class MediaPlayerEntity(Entity):
|
|||||||
if self.media_image_remotely_accessible:
|
if self.media_image_remotely_accessible:
|
||||||
state_attr["entity_picture_local"] = self.media_image_local
|
state_attr["entity_picture_local"] = self.media_image_local
|
||||||
|
|
||||||
if self.support_grouping:
|
|
||||||
state_attr[ATTR_GROUP_MEMBERS] = self.group_members
|
|
||||||
|
|
||||||
return state_attr
|
return state_attr
|
||||||
|
|
||||||
async def async_browse_media(
|
async def async_browse_media(
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from homeassistant.components import media_player
|
from homeassistant.components import media_player
|
||||||
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
@ -183,3 +184,27 @@ async def test_media_browse(hass, hass_ws_client):
|
|||||||
assert msg["type"] == TYPE_RESULT
|
assert msg["type"] == TYPE_RESULT
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
assert msg["result"] == {"bla": "yo"}
|
assert msg["result"] == {"bla": "yo"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_group_members_available_when_off(hass):
|
||||||
|
"""Test that group_members are still available when media_player is off."""
|
||||||
|
await async_setup_component(
|
||||||
|
hass, "media_player", {"media_player": {"platform": "demo"}}
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Fake group support for DemoYoutubePlayer
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.demo.media_player.YOUTUBE_PLAYER_SUPPORT",
|
||||||
|
media_player.SUPPORT_GROUPING | media_player.SUPPORT_TURN_OFF,
|
||||||
|
):
|
||||||
|
await hass.services.async_call(
|
||||||
|
"media_player",
|
||||||
|
"turn_off",
|
||||||
|
{ATTR_ENTITY_ID: "media_player.bedroom"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
state = hass.states.get("media_player.bedroom")
|
||||||
|
assert state.state == STATE_OFF
|
||||||
|
assert "group_members" in state.attributes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user