Skip to content

Commit

Permalink
Use roku media state to detect paused media (home-assistant#36980)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington authored Jun 22, 2020
1 parent edad387 commit 6aba87f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 13 additions & 4 deletions homeassistant/components/roku/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
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
Expand Down Expand Up @@ -81,7 +87,10 @@ def state(self) -> str:
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
Expand Down Expand Up @@ -174,13 +183,13 @@ async def async_turn_off(self) -> None:
@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
Expand Down
16 changes: 16 additions & 0 deletions tests/components/roku/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
SERVICE_VOLUME_UP,
STATE_HOME,
STATE_IDLE,
STATE_PAUSED,
STATE_PLAYING,
STATE_STANDBY,
STATE_UNAVAILABLE,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6aba87f

Please sign in to comment.