mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Make media_player.toggle turn on a standby device (#74221)
This commit is contained in:
parent
d38e8e213a
commit
de700e7859
@ -52,6 +52,7 @@ from homeassistant.const import (
|
|||||||
STATE_IDLE,
|
STATE_IDLE,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_PLAYING,
|
STATE_PLAYING,
|
||||||
|
STATE_STANDBY,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -888,7 +889,7 @@ class MediaPlayerEntity(Entity):
|
|||||||
await self.hass.async_add_executor_job(self.toggle)
|
await self.hass.async_add_executor_job(self.toggle)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.state in (STATE_OFF, STATE_IDLE):
|
if self.state in (STATE_OFF, STATE_IDLE, STATE_STANDBY):
|
||||||
await self.async_turn_on()
|
await self.async_turn_on()
|
||||||
else:
|
else:
|
||||||
await self.async_turn_off()
|
await self.async_turn_off()
|
||||||
|
@ -8,6 +8,7 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_PAUSED,
|
STATE_PAUSED,
|
||||||
STATE_PLAYING,
|
STATE_PLAYING,
|
||||||
|
STATE_STANDBY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -79,9 +80,13 @@ class ExtendedMediaPlayer(mp.MediaPlayerEntity):
|
|||||||
"""Turn off state."""
|
"""Turn off state."""
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
|
|
||||||
|
def standby(self):
|
||||||
|
"""Put device in standby."""
|
||||||
|
self._state = STATE_STANDBY
|
||||||
|
|
||||||
def toggle(self):
|
def toggle(self):
|
||||||
"""Toggle the power on the media player."""
|
"""Toggle the power on the media player."""
|
||||||
if self._state in [STATE_OFF, STATE_IDLE]:
|
if self._state in [STATE_OFF, STATE_IDLE, STATE_STANDBY]:
|
||||||
self._state = STATE_ON
|
self._state = STATE_ON
|
||||||
else:
|
else:
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
@ -138,6 +143,10 @@ class SimpleMediaPlayer(mp.MediaPlayerEntity):
|
|||||||
"""Turn off state."""
|
"""Turn off state."""
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
|
|
||||||
|
def standby(self):
|
||||||
|
"""Put device in standby."""
|
||||||
|
self._state = STATE_STANDBY
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=[ExtendedMediaPlayer, SimpleMediaPlayer])
|
@pytest.fixture(params=[ExtendedMediaPlayer, SimpleMediaPlayer])
|
||||||
def player(hass, request):
|
def player(hass, request):
|
||||||
@ -188,3 +197,7 @@ async def test_toggle(player):
|
|||||||
assert player.state == STATE_ON
|
assert player.state == STATE_ON
|
||||||
await player.async_toggle()
|
await player.async_toggle()
|
||||||
assert player.state == STATE_OFF
|
assert player.state == STATE_OFF
|
||||||
|
player.standby()
|
||||||
|
assert player.state == STATE_STANDBY
|
||||||
|
await player.async_toggle()
|
||||||
|
assert player.state == STATE_ON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user