Use roku media state to detect paused media (#36980)

This commit is contained in:
Chris Talkington 2020-06-22 02:51:38 -05:00 committed by GitHub
parent edad387b12
commit 6aba87f3a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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: