Fix media_player Toggle when in idle (#78192)

* Remove idle as off state

* Fix merge mistake

* Fix merge mistake

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Michel van de Wetering 2025-03-14 17:24:39 +01:00 committed by GitHub
parent 2951eb5cc8
commit 160b98bd28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -1031,7 +1031,6 @@ class MediaPlayerEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
if self.state in {
MediaPlayerState.OFF,
MediaPlayerState.IDLE,
MediaPlayerState.STANDBY,
}:
await self.async_turn_on()

View File

@ -69,6 +69,10 @@ class SimpleMediaPlayer(mp.MediaPlayerEntity):
"""Put device in standby."""
self._state = STATE_STANDBY
def idle(self):
"""Put device in idle."""
self._state = STATE_IDLE
class ExtendedMediaPlayer(SimpleMediaPlayer):
"""Media player test class."""
@ -92,7 +96,7 @@ class ExtendedMediaPlayer(SimpleMediaPlayer):
def toggle(self):
"""Toggle the power on the media player."""
if self._state in [STATE_OFF, STATE_IDLE, STATE_STANDBY]:
if self._state in [STATE_OFF, STATE_STANDBY]:
self._state = STATE_ON
else:
self._state = STATE_OFF
@ -187,3 +191,7 @@ async def test_toggle(player) -> None:
assert player.state == STATE_STANDBY
await player.async_toggle()
assert player.state == STATE_ON
player.idle()
assert player.state == STATE_IDLE
await player.async_toggle()
assert player.state == STATE_OFF