Update media_player to use async_add_executor_job (#41459)

This commit is contained in:
J. Nick Koston 2020-10-08 02:22:37 -05:00 committed by GitHub
parent dfc656a2c6
commit 740d15e41d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -523,7 +523,7 @@ class MediaPlayerEntity(Entity):
async def async_turn_on(self): async def async_turn_on(self):
"""Turn the media player on.""" """Turn the media player on."""
await self.hass.async_add_job(self.turn_on) await self.hass.async_add_executor_job(self.turn_on)
def turn_off(self): def turn_off(self):
"""Turn the media player off.""" """Turn the media player off."""
@ -531,7 +531,7 @@ class MediaPlayerEntity(Entity):
async def async_turn_off(self): async def async_turn_off(self):
"""Turn the media player off.""" """Turn the media player off."""
await self.hass.async_add_job(self.turn_off) await self.hass.async_add_executor_job(self.turn_off)
def mute_volume(self, mute): def mute_volume(self, mute):
"""Mute the volume.""" """Mute the volume."""
@ -539,7 +539,7 @@ class MediaPlayerEntity(Entity):
async def async_mute_volume(self, mute): async def async_mute_volume(self, mute):
"""Mute the volume.""" """Mute the volume."""
await self.hass.async_add_job(self.mute_volume, mute) await self.hass.async_add_executor_job(self.mute_volume, mute)
def set_volume_level(self, volume): def set_volume_level(self, volume):
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""
@ -547,7 +547,7 @@ class MediaPlayerEntity(Entity):
async def async_set_volume_level(self, volume): async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""
await self.hass.async_add_job(self.set_volume_level, volume) await self.hass.async_add_executor_job(self.set_volume_level, volume)
def media_play(self): def media_play(self):
"""Send play command.""" """Send play command."""
@ -555,7 +555,7 @@ class MediaPlayerEntity(Entity):
async def async_media_play(self): async def async_media_play(self):
"""Send play command.""" """Send play command."""
await self.hass.async_add_job(self.media_play) await self.hass.async_add_executor_job(self.media_play)
def media_pause(self): def media_pause(self):
"""Send pause command.""" """Send pause command."""
@ -563,7 +563,7 @@ class MediaPlayerEntity(Entity):
async def async_media_pause(self): async def async_media_pause(self):
"""Send pause command.""" """Send pause command."""
await self.hass.async_add_job(self.media_pause) await self.hass.async_add_executor_job(self.media_pause)
def media_stop(self): def media_stop(self):
"""Send stop command.""" """Send stop command."""
@ -571,7 +571,7 @@ class MediaPlayerEntity(Entity):
async def async_media_stop(self): async def async_media_stop(self):
"""Send stop command.""" """Send stop command."""
await self.hass.async_add_job(self.media_stop) await self.hass.async_add_executor_job(self.media_stop)
def media_previous_track(self): def media_previous_track(self):
"""Send previous track command.""" """Send previous track command."""
@ -579,7 +579,7 @@ class MediaPlayerEntity(Entity):
async def async_media_previous_track(self): async def async_media_previous_track(self):
"""Send previous track command.""" """Send previous track command."""
await self.hass.async_add_job(self.media_previous_track) await self.hass.async_add_executor_job(self.media_previous_track)
def media_next_track(self): def media_next_track(self):
"""Send next track command.""" """Send next track command."""
@ -587,7 +587,7 @@ class MediaPlayerEntity(Entity):
async def async_media_next_track(self): async def async_media_next_track(self):
"""Send next track command.""" """Send next track command."""
await self.hass.async_add_job(self.media_next_track) await self.hass.async_add_executor_job(self.media_next_track)
def media_seek(self, position): def media_seek(self, position):
"""Send seek command.""" """Send seek command."""
@ -595,7 +595,7 @@ class MediaPlayerEntity(Entity):
async def async_media_seek(self, position): async def async_media_seek(self, position):
"""Send seek command.""" """Send seek command."""
await self.hass.async_add_job(self.media_seek, position) await self.hass.async_add_executor_job(self.media_seek, position)
def play_media(self, media_type, media_id, **kwargs): def play_media(self, media_type, media_id, **kwargs):
"""Play a piece of media.""" """Play a piece of media."""
@ -603,7 +603,7 @@ class MediaPlayerEntity(Entity):
async def async_play_media(self, media_type, media_id, **kwargs): async def async_play_media(self, media_type, media_id, **kwargs):
"""Play a piece of media.""" """Play a piece of media."""
await self.hass.async_add_job( await self.hass.async_add_executor_job(
ft.partial(self.play_media, media_type, media_id, **kwargs) ft.partial(self.play_media, media_type, media_id, **kwargs)
) )
@ -613,7 +613,7 @@ class MediaPlayerEntity(Entity):
async def async_select_source(self, source): async def async_select_source(self, source):
"""Select input source.""" """Select input source."""
await self.hass.async_add_job(self.select_source, source) await self.hass.async_add_executor_job(self.select_source, source)
def select_sound_mode(self, sound_mode): def select_sound_mode(self, sound_mode):
"""Select sound mode.""" """Select sound mode."""
@ -621,7 +621,7 @@ class MediaPlayerEntity(Entity):
async def async_select_sound_mode(self, sound_mode): async def async_select_sound_mode(self, sound_mode):
"""Select sound mode.""" """Select sound mode."""
await self.hass.async_add_job(self.select_sound_mode, sound_mode) await self.hass.async_add_executor_job(self.select_sound_mode, sound_mode)
def clear_playlist(self): def clear_playlist(self):
"""Clear players playlist.""" """Clear players playlist."""
@ -629,7 +629,7 @@ class MediaPlayerEntity(Entity):
async def async_clear_playlist(self): async def async_clear_playlist(self):
"""Clear players playlist.""" """Clear players playlist."""
await self.hass.async_add_job(self.clear_playlist) await self.hass.async_add_executor_job(self.clear_playlist)
def set_shuffle(self, shuffle): def set_shuffle(self, shuffle):
"""Enable/disable shuffle mode.""" """Enable/disable shuffle mode."""
@ -637,7 +637,7 @@ class MediaPlayerEntity(Entity):
async def async_set_shuffle(self, shuffle): async def async_set_shuffle(self, shuffle):
"""Enable/disable shuffle mode.""" """Enable/disable shuffle mode."""
await self.hass.async_add_job(self.set_shuffle, shuffle) await self.hass.async_add_executor_job(self.set_shuffle, shuffle)
# No need to overwrite these. # No need to overwrite these.
@property @property
@ -709,7 +709,7 @@ class MediaPlayerEntity(Entity):
"""Toggle the power on the media player.""" """Toggle the power on the media player."""
if hasattr(self, "toggle"): if hasattr(self, "toggle"):
# pylint: disable=no-member # pylint: disable=no-member
await self.hass.async_add_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]:
@ -724,7 +724,7 @@ class MediaPlayerEntity(Entity):
""" """
if hasattr(self, "volume_up"): if hasattr(self, "volume_up"):
# pylint: disable=no-member # pylint: disable=no-member
await self.hass.async_add_job(self.volume_up) await self.hass.async_add_executor_job(self.volume_up)
return return
if self.volume_level < 1 and self.supported_features & SUPPORT_VOLUME_SET: if self.volume_level < 1 and self.supported_features & SUPPORT_VOLUME_SET:
@ -737,7 +737,7 @@ class MediaPlayerEntity(Entity):
""" """
if hasattr(self, "volume_down"): if hasattr(self, "volume_down"):
# pylint: disable=no-member # pylint: disable=no-member
await self.hass.async_add_job(self.volume_down) await self.hass.async_add_executor_job(self.volume_down)
return return
if self.volume_level > 0 and self.supported_features & SUPPORT_VOLUME_SET: if self.volume_level > 0 and self.supported_features & SUPPORT_VOLUME_SET:
@ -747,7 +747,7 @@ class MediaPlayerEntity(Entity):
"""Play or pause the media player.""" """Play or pause the media player."""
if hasattr(self, "media_play_pause"): if hasattr(self, "media_play_pause"):
# pylint: disable=no-member # pylint: disable=no-member
await self.hass.async_add_job(self.media_play_pause) await self.hass.async_add_executor_job(self.media_play_pause)
return return
if self.state == STATE_PLAYING: if self.state == STATE_PLAYING: