mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Use roku media state to detect paused media (#36980)
This commit is contained in:
parent
edad387b12
commit
6aba87f3a6
@ -17,7 +17,13 @@ from homeassistant.components.media_player.const import (
|
|||||||
SUPPORT_VOLUME_MUTE,
|
SUPPORT_VOLUME_MUTE,
|
||||||
SUPPORT_VOLUME_STEP,
|
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 . import RokuDataUpdateCoordinator, RokuEntity, roku_exception_handler
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -81,7 +87,10 @@ class RokuMediaPlayer(RokuEntity, MediaPlayerEntity):
|
|||||||
if self.coordinator.data.app.name == "Roku":
|
if self.coordinator.data.app.name == "Roku":
|
||||||
return STATE_HOME
|
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 STATE_PLAYING
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -174,13 +183,13 @@ class RokuMediaPlayer(RokuEntity, MediaPlayerEntity):
|
|||||||
@roku_exception_handler
|
@roku_exception_handler
|
||||||
async def async_media_pause(self) -> None:
|
async def async_media_pause(self) -> None:
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
if self.state != STATE_STANDBY:
|
if self.state not in (STATE_STANDBY, STATE_PAUSED):
|
||||||
await self.coordinator.roku.remote("play")
|
await self.coordinator.roku.remote("play")
|
||||||
|
|
||||||
@roku_exception_handler
|
@roku_exception_handler
|
||||||
async def async_media_play(self) -> None:
|
async def async_media_play(self) -> None:
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
if self.state != STATE_STANDBY:
|
if self.state not in (STATE_STANDBY, STATE_PLAYING):
|
||||||
await self.coordinator.roku.remote("play")
|
await self.coordinator.roku.remote("play")
|
||||||
|
|
||||||
@roku_exception_handler
|
@roku_exception_handler
|
||||||
|
@ -42,6 +42,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_VOLUME_UP,
|
SERVICE_VOLUME_UP,
|
||||||
STATE_HOME,
|
STATE_HOME,
|
||||||
STATE_IDLE,
|
STATE_IDLE,
|
||||||
|
STATE_PAUSED,
|
||||||
STATE_PLAYING,
|
STATE_PLAYING,
|
||||||
STATE_STANDBY,
|
STATE_STANDBY,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
@ -213,6 +214,21 @@ async def test_attributes_app(
|
|||||||
assert state.attributes.get(ATTR_INPUT_SOURCE) == "Netflix"
|
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(
|
async def test_attributes_screensaver(
|
||||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user