Skip to content

Commit

Permalink
Add play/pause functionality to vizio integration
Browse files Browse the repository at this point in the history
Leverages existing pyvizio functionality. My impression is that it also
works for soundbars based on exiva/Vizio_SmartCast_API#19.
  • Loading branch information
NasaGeek committed Jan 26, 2024
1 parent 3f31a76 commit 6e081eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion homeassistant/components/vizio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
}

COMMON_SUPPORTED_COMMANDS = (
MediaPlayerEntityFeature.SELECT_SOURCE
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.VOLUME_MUTE
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/vizio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,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)
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 @@ -27,6 +27,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 @@ -438,6 +440,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

0 comments on commit 6e081eb

Please sign in to comment.