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

Add play/pause functionality for Vizio Smartcast media_player entities #108896

Merged
merged 3 commits into from
Apr 25, 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
4 changes: 3 additions & 1 deletion homeassistant/components/vizio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
DOMAIN = "vizio"

COMMON_SUPPORTED_COMMANDS = (
MediaPlayerEntityFeature.SELECT_SOURCE
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.VOLUME_MUTE
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/vizio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __init__(
)
self._device = device
self._max_volume = float(device.get_max_volume())
self._attr_assumed_state = True
Copy link
Contributor

@emontnemery emontnemery Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed? Is it to ensure the Play/Pause buttons always show in the frontend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this gives us separate play/pause buttons rather than a single dynamic button (which won't actually work correctly because the Vizio API doesn't provide a playing/paused/idle status).


# Entity class attributes that will change with each update (we only include
# the ones that are initialized differently from the defaults)
Expand Down Expand Up @@ -483,3 +484,11 @@ async def async_set_volume_level(self, volume: float) -> None:
num = int(self._max_volume * (self._attr_volume_level - volume))
await self._device.vol_down(num=num, log_api_exception=False)
self._attr_volume_level = volume

async def async_media_play(self) -> None:
"""Play whatever media is currently active."""
await self._device.play(log_api_exception=False)

async def async_media_pause(self) -> None:
"""Pause whatever media is currently active."""
await self._device.pause(log_api_exception=False)
emontnemery marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions tests/components/vizio/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
ATTR_SOUND_MODE,
DOMAIN as MP_DOMAIN,
SERVICE_MEDIA_NEXT_TRACK,
SERVICE_MEDIA_PAUSE,
SERVICE_MEDIA_PLAY,
SERVICE_MEDIA_PREVIOUS_TRACK,
SERVICE_SELECT_SOUND_MODE,
SERVICE_SELECT_SOURCE,
Expand Down Expand Up @@ -443,6 +445,8 @@ async def test_services(
"eq",
"Music",
)
await _test_service(hass, MP_DOMAIN, "play", SERVICE_MEDIA_PLAY, None)
await _test_service(hass, MP_DOMAIN, "pause", SERVICE_MEDIA_PAUSE, None)


async def test_options_update(
Expand Down