mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Fix Shelly media player availability (#170319)
This commit is contained in:
@@ -191,6 +191,14 @@ class ShellyRpcMediaPlayer(ShellyRpcAttributeEntity, MediaPlayerEntity):
|
||||
|
||||
return self._last_media_position_updated_at
|
||||
|
||||
@property
|
||||
def entity_picture(self) -> str | None:
|
||||
"""Return image of the media playing."""
|
||||
if not self.available:
|
||||
return None
|
||||
|
||||
return super().entity_picture
|
||||
|
||||
@property
|
||||
def media_image_url(self) -> str | None:
|
||||
"""Return the image URL of current playing media."""
|
||||
|
||||
@@ -36,6 +36,7 @@ from homeassistant.const import (
|
||||
STATE_BUFFERING,
|
||||
STATE_IDLE,
|
||||
STATE_PLAYING,
|
||||
STATE_UNAVAILABLE,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -631,3 +632,27 @@ async def test_rpc_media_player_no_media_meta(
|
||||
assert state.attributes.get(ATTR_MEDIA_ALBUM_NAME) is None
|
||||
assert state.attributes.get(ATTR_MEDIA_DURATION) is None
|
||||
assert state.attributes.get(ATTR_MEDIA_POSITION) is None
|
||||
|
||||
|
||||
async def test_rpc_media_player_unavailable(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test media player entity handles device going offline without raising."""
|
||||
status = deepcopy(mock_rpc_device.status)
|
||||
status["media"] = STATUS_AUDIO_FILE
|
||||
monkeypatch.setattr(mock_rpc_device, "status", status)
|
||||
|
||||
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
|
||||
|
||||
assert (state := hass.states.get(ENTITY_ID))
|
||||
assert state.state == STATE_PLAYING
|
||||
|
||||
monkeypatch.setattr(mock_rpc_device, "connected", False)
|
||||
monkeypatch.setattr(mock_rpc_device, "initialized", False)
|
||||
mock_rpc_device.mock_disconnected()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get(ENTITY_ID))
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
Reference in New Issue
Block a user