# Buggy code
async def async_update(self):
    """Update Guard state."""
    try:
        if not self.enabled:
            return
    except AttributeError:
        pass
    import json

    if self._login.session.closed:
        return
    _LOGGER.debug("%s: Refreshing %s", self.account, self.name)
    state = None
    state_json = await self.alexa_api.get_guard_state(self._login, self._appliance_id)
    # _LOGGER.debug("%s: state_json %s", self.account, state_json)
    if state_json and "deviceStates" in state_json and state_json["deviceStates"]:
        cap = state_json["deviceStates"][0]["capabilityStates"]
        # _LOGGER.debug("%s: cap %s", self.account, cap)
        for item_json in cap:
            item = json.loads(item_json)
            # _LOGGER.debug("%s: item %s", self.account, item)
            if item["name"] == "armState":
                state = item["value"]
                # _LOGGER.debug("%s: state %s", self.account, state)
    elif state_json["errors"]:
        _LOGGER.debug(
            "%s: Error refreshing alarm_control_panel %s: %s",
            self.account,
            self.name,
            json.dumps(state_json["errors"]) if state_json else None,
        )
    if state is None:
        return
    if state == "ARMED_AWAY":
        self._state = STATE_ALARM_ARMED_AWAY
    elif state == "ARMED_STAY":
        self._state = STATE_ALARM_DISARMED
    else:
        self._state = STATE_ALARM_DISARMED
    _LOGGER.debug("%s: Alarm State: %s", self.account, self.state)
    self.async_schedule_update_ha_state()


# 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_update(self):
    """Update Guard state."""
    self.check_login_changes()
    try:
        if not self.enabled:
            return
    except AttributeError:
        pass
    import json

    if self._login.session.closed:
        return
    _LOGGER.debug("%s: Refreshing %s", self.account, self.name)
    state = None
    state_json = await self.alexa_api.get_guard_state(self._login, self._appliance_id)
    # _LOGGER.debug("%s: state_json %s", self.account, state_json)
    if state_json and "deviceStates" in state_json and state_json["deviceStates"]:
        cap = state_json["deviceStates"][0]["capabilityStates"]
        # _LOGGER.debug("%s: cap %s", self.account, cap)
        for item_json in cap:
            item = json.loads(item_json)
            # _LOGGER.debug("%s: item %s", self.account, item)
            if item["name"] == "armState":
                state = item["value"]
                # _LOGGER.debug("%s: state %s", self.account, state)
    elif state_json["errors"]:
        _LOGGER.debug(
            "%s: Error refreshing alarm_control_panel %s: %s",
            self.account,
            self.name,
            json.dumps(state_json["errors"]) if state_json else None,
        )
    if state is None:
        return
    if state == "ARMED_AWAY":
        self._state = STATE_ALARM_ARMED_AWAY
    elif state == "ARMED_STAY":
        self._state = STATE_ALARM_DISARMED
    else:
        self._state = STATE_ALARM_DISARMED
    _LOGGER.debug("%s: Alarm State: %s", self.account, self.state)
    self.async_schedule_update_ha_state()