# Buggy code
def refresh(self):
    """Update Guard state."""
    import json

    _LOGGER.debug("%s: Refreshing %s", self.account, self.name)
    state = None
    state_json = self.alexa_api.get_guard_state(self._login, self._appliance_id)
    # _LOGGER.debug("%s: state_json %s", self.account, state_json)
    if 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 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)


# Traceback (TypeError)
Error while setting up platform alexa_media
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/alexa_media/alarm_control_panel.py", line 34, in setup_platform
hass)  \
File "/home/homeassistant/.homeassistant/custom_components/alexa_media/alarm_control_panel.py", line 70, in __init__
guard_dict = (data['locationDetails']
TypeError: 'NoneType' object is not subscriptable

# Fixed code
def refresh(self):
    """Update Guard state."""
    import json

    _LOGGER.debug("%s: Refreshing %s", self.account, self.name)
    state = None
    state_json = 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)