From 6aba87f3a60616576b6313fd767ef374791fffc2 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 22 Jun 2020 02:51:38 -0500 Subject: [PATCH] Use roku media state to detect paused media (#36980) --- homeassistant/components/roku/media_player.py | 17 +++++++++++++---- tests/components/roku/test_media_player.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/roku/media_player.py b/homeassistant/components/roku/media_player.py index 168d4a4a6fe..463a77a1e55 100644 --- a/homeassistant/components/roku/media_player.py +++ b/homeassistant/components/roku/media_player.py @@ -17,7 +17,13 @@ from homeassistant.components.media_player.const import ( SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP, ) -from homeassistant.const import STATE_HOME, STATE_IDLE, STATE_PLAYING, STATE_STANDBY +from homeassistant.const import ( + STATE_HOME, + STATE_IDLE, + STATE_PAUSED, + STATE_PLAYING, + STATE_STANDBY, +) from . import RokuDataUpdateCoordinator, RokuEntity, roku_exception_handler from .const import DOMAIN @@ -81,7 +87,10 @@ class RokuMediaPlayer(RokuEntity, MediaPlayerEntity): if self.coordinator.data.app.name == "Roku": return STATE_HOME - if self.coordinator.data.app.name is not None: + if self.coordinator.data.media and self.coordinator.data.media.paused: + return STATE_PAUSED + + if self.coordinator.data.app.name: return STATE_PLAYING return None @@ -174,13 +183,13 @@ class RokuMediaPlayer(RokuEntity, MediaPlayerEntity): @roku_exception_handler async def async_media_pause(self) -> None: """Send pause command.""" - if self.state != STATE_STANDBY: + if self.state not in (STATE_STANDBY, STATE_PAUSED): await self.coordinator.roku.remote("play") @roku_exception_handler async def async_media_play(self) -> None: """Send play command.""" - if self.state != STATE_STANDBY: + if self.state not in (STATE_STANDBY, STATE_PLAYING): await self.coordinator.roku.remote("play") @roku_exception_handler diff --git a/tests/components/roku/test_media_player.py b/tests/components/roku/test_media_player.py index 9ac758585e9..467e81b957f 100644 --- a/tests/components/roku/test_media_player.py +++ b/tests/components/roku/test_media_player.py @@ -42,6 +42,7 @@ from homeassistant.const import ( SERVICE_VOLUME_UP, STATE_HOME, STATE_IDLE, + STATE_PAUSED, STATE_PLAYING, STATE_STANDBY, STATE_UNAVAILABLE, @@ -213,6 +214,21 @@ async def test_attributes_app( assert state.attributes.get(ATTR_INPUT_SOURCE) == "Netflix" +async def test_attributes_app_media_paused( + hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker +) -> None: + """Test attributes for app with paused media.""" + await setup_integration(hass, aioclient_mock, app="pluto", media_state="pause") + + state = hass.states.get(MAIN_ENTITY_ID) + assert state.state == STATE_PAUSED + + assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_APP + assert state.attributes.get(ATTR_APP_ID) == "74519" + assert state.attributes.get(ATTR_APP_NAME) == "Pluto TV - It's Free TV" + assert state.attributes.get(ATTR_INPUT_SOURCE) == "Pluto TV - It's Free TV" + + async def test_attributes_screensaver( hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker ) -> None: