Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report webOS media player state #113774

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions homeassistant/components/webostv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ def _update_states(self) -> None:
name=self._device_name,
)

self._attr_assumed_state = True
if (
rale marked this conversation as resolved.
Show resolved Hide resolved
self._client.media_state is not None
and self._client.media_state.get("foregroundAppInfo") is not None
):
thecode marked this conversation as resolved.
Show resolved Hide resolved
self._attr_assumed_state = False
for entry in self._client.media_state.get("foregroundAppInfo"):
if entry.get("playState") == "playing":
self._attr_state = MediaPlayerState.PLAYING
elif entry.get("playState") == "paused":
self._attr_state = MediaPlayerState.PAUSED
elif entry.get("playState") == "unloaded":
self._attr_state = MediaPlayerState.IDLE

if self._client.system_info is not None or self.state != MediaPlayerState.OFF:
maj_v = self._client.software_info.get("major_ver")
min_v = self._client.software_info.get("minor_ver")
Expand Down
21 changes: 21 additions & 0 deletions tests/components/webostv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
SERVICE_SELECT_SOURCE,
MediaPlayerDeviceClass,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
)
from homeassistant.components.webostv.const import (
Expand Down Expand Up @@ -811,3 +812,23 @@ async def test_reauth_reconnect(hass: HomeAssistant, client, monkeypatch) -> Non
assert "context" in flow
assert flow["context"].get("source") == SOURCE_REAUTH
assert flow["context"].get("entry_id") == entry.entry_id


async def test_update_media_state(hass: HomeAssistant, client, monkeypatch) -> None:
"""Test updating media state."""
await setup_webostv(hass)

data = {"foregroundAppInfo": [{"playState": "playing"}]}
monkeypatch.setattr(client, "media_state", data)
await client.mock_state_update()
assert hass.states.get(ENTITY_ID).state == MediaPlayerState.PLAYING

data = {"foregroundAppInfo": [{"playState": "paused"}]}
monkeypatch.setattr(client, "media_state", data)
await client.mock_state_update()
assert hass.states.get(ENTITY_ID).state == MediaPlayerState.PAUSED

data = {"foregroundAppInfo": [{"playState": "unloaded"}]}
monkeypatch.setattr(client, "media_state", data)
await client.mock_state_update()
assert hass.states.get(ENTITY_ID).state == MediaPlayerState.IDLE