Improve Universal media player toggle default behavior (#49395)
Before it could not be overridden and the default behavior meant nothing was called when all children were off, so it could not be used to turn on the media player. The new default behavior is to delegate to `turn_on` and `turn_off` instead, which is more likely to be the expected behavior.
This commit is contained in:
parent
65c6943784
commit
4f96f05a75
2 changed files with 7 additions and 2 deletions
|
@ -612,7 +612,11 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
|
||||
async def async_toggle(self):
|
||||
"""Toggle the power on the media player."""
|
||||
await self._async_call_service(SERVICE_TOGGLE, allow_override=True)
|
||||
if SERVICE_TOGGLE in self._cmds:
|
||||
await self._async_call_service(SERVICE_TOGGLE, allow_override=True)
|
||||
else:
|
||||
# Delegate to turn_on or turn_off by default
|
||||
await super().async_toggle()
|
||||
|
||||
async def async_update(self):
|
||||
"""Update state in HA."""
|
||||
|
|
|
@ -998,7 +998,8 @@ class TestMediaPlayer(unittest.TestCase):
|
|||
assert len(self.mock_mp_2.service_calls["shuffle_set"]) == 1
|
||||
|
||||
asyncio.run_coroutine_threadsafe(ump.async_toggle(), self.hass.loop).result()
|
||||
assert len(self.mock_mp_2.service_calls["toggle"]) == 1
|
||||
# Delegate to turn_off
|
||||
assert len(self.mock_mp_2.service_calls["turn_off"]) == 2
|
||||
|
||||
def test_service_call_to_command(self):
|
||||
"""Test service call to command."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue