# Buggy code
async def async_play_media(self, media_type, media_id, enqueue=None, **kwargs):
    # pylint: disable=unused-argument
    """Send the play_media command to the media player."""
    if media_type == "music":
        await self.async_send_tts(
            "Sorry, text to speech can only be called"
            " with the notify.alexa_media service."
            " Please see the alexa_media wiki for details."
        )
        _LOGGER.warning(
            "Sorry, text to speech can only be called"
            " with the notify.alexa_media service."
            " Please see the alexa_media wiki for details."
            "https://github.com/custom-components/alexa_media_player/wiki/Configuration%3A-Notification-Component#use-the-notifyalexa_media-service"
        )
    elif media_type == "sequence":
        await self.alexa_api.send_sequence(
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    elif media_type == "routine":
        await self.alexa_api.run_routine(
            media_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
        )
    elif media_type == "sound":
        await self.alexa_api.play_sound(
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    elif media_type == "skill":
        await self.alexa_api.run_skill(
            media_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
        )
    else:
        await self.alexa_api.play_music(
            media_type,
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    if not (
        self.hass.data[DATA_ALEXAMEDIA]["accounts"][self._login.email]["websocket"]
    ):
        await self.async_update()


# Traceback (RuntimeError)
2020-06-21 12:36:29 ERROR (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0xa8cddbd0>,), {}): An error occured accessing AlexaAPI: An exception of type RuntimeError occurred. Arguments:
('Session is closed',)
2020-06-21 12:36:29 ERROR (MainThread) [homeassistant.util.logging] Exception in _handle_event when dispatching 'alexa_media_a******e@g*******m': ({'player_state': {'destinationUserId': 'XXX', 'dopplerId': {'deviceType': 'AB72C64C86AW2', 'deviceSerialNumber': 'XXX'}, 'audioPlayerState': 'PLAYING', 'quality': None, 'error': False, 'errorMessage': None, 'mediaReferenceId': '78e56ac3-4ab4-4c85-86b4-3d9bb3f5ae60:6'}},)
Traceback (most recent call last):
File "/config/custom_components/alexa_media/media_player.py", line 369, in _handle_event
await self.async_update()
File "/config/custom_components/alexa_media/helpers.py", line 148, in wrapper
result = await func(*args, **kwargs)
File "/config/custom_components/alexa_media/media_player.py", line 802, in async_update
device, no_throttle=True
File "/config/custom_components/alexa_media/helpers.py", line 148, in wrapper
result = await func(*args, **kwargs)
File "/config/custom_components/alexa_media/media_player.py", line 545, in refresh
session = await self.alexa_api.get_state()
File "/usr/local/lib/python3.7/site-packages/alexapy/helpers.py", line 69, in wrapper
return await func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 761, in get_state
+ "&amp;screenWidth=2560"
File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 122, in _get_request
return await self._request("get", uri, data)
File "/usr/local/lib/python3.7/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 93, in _request
ssl=self._login._ssl,
File "/usr/local/lib/python3.7/site-packages/alexapy/aiohttp/client.py", line 377, in _request
raise RuntimeError("Session is closed")
RuntimeError: Session is closed

# Fixed code
async def async_play_media(self, media_type, media_id, enqueue=None, **kwargs):
    # pylint: disable=unused-argument
    """Send the play_media command to the media player."""
    self.check_login_changes()
    if media_type == "music":
        await self.async_send_tts(
            "Sorry, text to speech can only be called"
            " with the notify.alexa_media service."
            " Please see the alexa_media wiki for details."
        )
        _LOGGER.warning(
            "Sorry, text to speech can only be called"
            " with the notify.alexa_media service."
            " Please see the alexa_media wiki for details."
            "https://github.com/custom-components/alexa_media_player/wiki/Configuration%3A-Notification-Component#use-the-notifyalexa_media-service"
        )
    elif media_type == "sequence":
        await self.alexa_api.send_sequence(
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    elif media_type == "routine":
        await self.alexa_api.run_routine(
            media_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
        )
    elif media_type == "sound":
        await self.alexa_api.play_sound(
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    elif media_type == "skill":
        await self.alexa_api.run_skill(
            media_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
        )
    else:
        await self.alexa_api.play_music(
            media_type,
            media_id,
            customer_id=self._customer_id,
            queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][self.email][
                "options"
            ].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
            **kwargs,
        )
    if not (
        self.hass.data[DATA_ALEXAMEDIA]["accounts"][self._login.email]["websocket"]
    ):
        await self.async_update()