# Buggy code
def __init__(self, login, hass):
    # pylint: disable=unexpected-keyword-arg
    """Initialize the Alexa device."""
    from alexapy import AlexaAPI

    # Class info
    self._login = login
    self.alexa_api = AlexaAPI(self, login)
    self.alexa_api_session = login.session
    self.account = hide_email(login.email)
    self.hass = hass

    # Guard info
    self._appliance_id = None
    self._guard_entity_id = None
    self._friendly_name = "Alexa Guard"
    self._state = None
    self._should_poll = False
    self._attrs = {}

    data = self.alexa_api.get_guard_details(self._login)
    guard_dict = data["locationDetails"]["locationDetails"]["Default_Location"][
        "amazonBridgeDetails"
    ]["amazonBridgeDetails"]["LambdaBridge_AAA/OnGuardSmartHomeBridgeService"][
        "applianceDetails"
    ]["applianceDetails"]
    for key, value in guard_dict.items():
        if value["modelName"] == "REDROCK_GUARD_PANEL":
            self._appliance_id = value["applianceId"]
            self._guard_entity_id = value["entityId"]
            self._friendly_name += " " + self._appliance_id[-5:]
            _LOGGER.debug(
                "Discovered Alexa Guard %s: %s %s",
                self._friendly_name,
                self._appliance_id,
                self._guard_entity_id,
            )
    # Register event handler on bus
    hass.bus.listen(
        ("{}_{}".format(ALEXA_DOMAIN, hide_email(login.email)))[0:32],
        self._handle_event,
    )
    self.refresh(no_throttle=True)


# 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 __init__(self, login, hass):
    # pylint: disable=unexpected-keyword-arg
    """Initialize the Alexa device."""
    from alexapy import AlexaAPI

    # Class info
    self._login = login
    self.alexa_api = AlexaAPI(self, login)
    self.alexa_api_session = login.session
    self.account = hide_email(login.email)
    self.hass = hass

    # Guard info
    self._appliance_id = None
    self._guard_entity_id = None
    self._friendly_name = "Alexa Guard"
    self._state = None
    self._should_poll = False
    self._attrs = {}

    data = self.alexa_api.get_guard_details(self._login)
    try:
        guard_dict = data["locationDetails"]["locationDetails"]["Default_Location"][
            "amazonBridgeDetails"
        ]["amazonBridgeDetails"]["LambdaBridge_AAA/OnGuardSmartHomeBridgeService"][
            "applianceDetails"
        ]["applianceDetails"]
    except KeyError:
        guard_dict = {}
    for key, value in guard_dict.items():
        if value["modelName"] == "REDROCK_GUARD_PANEL":
            self._appliance_id = value["applianceId"]
            self._guard_entity_id = value["entityId"]
            self._friendly_name += " " + self._appliance_id[-5:]
            _LOGGER.debug(
                "%s: Discovered %s: %s %s",
                self.account,
                self._friendly_name,
                self._appliance_id,
                self._guard_entity_id,
            )
    if not self._appliance_id:
        _LOGGER.debug("%s: No Alexa Guard entity found", self.account)
        return None
    # Register event handler on bus
    hass.bus.listen(
        ("{}_{}".format(ALEXA_DOMAIN, hide_email(login.email)))[0:32],
        self._handle_event,
    )
    self.refresh(no_throttle=True)