Migrate media_player tests from coroutine to async/await (#30387)

This commit is contained in:
Franck Nijhof 2020-01-02 21:23:35 +01:00 committed by Andrew Sayre
parent b9fcb87d2c
commit 4e6d415541

View File

@ -44,28 +44,23 @@ class AsyncMediaPlayer(mp.MediaPlayerDevice):
| mp.const.SUPPORT_TURN_ON | mp.const.SUPPORT_TURN_ON
) )
@asyncio.coroutine async def async_set_volume_level(self, volume):
def async_set_volume_level(self, volume):
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""
self._volume = volume self._volume = volume
@asyncio.coroutine async def async_media_play(self):
def async_media_play(self):
"""Send play command.""" """Send play command."""
self._state = STATE_PLAYING self._state = STATE_PLAYING
@asyncio.coroutine async def async_media_pause(self):
def async_media_pause(self):
"""Send pause command.""" """Send pause command."""
self._state = STATE_PAUSED self._state = STATE_PAUSED
@asyncio.coroutine async def async_turn_on(self):
def async_turn_on(self):
"""Turn the media player on.""" """Turn the media player on."""
self._state = STATE_ON self._state = STATE_ON
@asyncio.coroutine async def async_turn_off(self):
def async_turn_off(self):
"""Turn the media player off.""" """Turn the media player off."""
self._state = STATE_OFF self._state = STATE_OFF
@ -129,21 +124,19 @@ class SyncMediaPlayer(mp.MediaPlayerDevice):
else: else:
self._state = STATE_OFF self._state = STATE_OFF
@asyncio.coroutine async def async_media_play_pause(self):
def async_media_play_pause(self):
"""Create a coroutine to wrap the future returned by ABC. """Create a coroutine to wrap the future returned by ABC.
This allows the run_coroutine_threadsafe helper to be used. This allows the run_coroutine_threadsafe helper to be used.
""" """
yield from super().async_media_play_pause() await super().async_media_play_pause()
@asyncio.coroutine async def async_toggle(self):
def async_toggle(self):
"""Create a coroutine to wrap the future returned by ABC. """Create a coroutine to wrap the future returned by ABC.
This allows the run_coroutine_threadsafe helper to be used. This allows the run_coroutine_threadsafe helper to be used.
""" """
yield from super().async_toggle() await super().async_toggle()
class TestAsyncMediaPlayer(unittest.TestCase): class TestAsyncMediaPlayer(unittest.TestCase):