# Buggy code
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Set up the Alexa alarm control panel platform."""
    devices = []  # type: List[AlexaAlarmControlPanel]
    for account, account_dict in hass.data[DATA_ALEXAMEDIA]["accounts"].items():
        alexa_client = AlexaAlarmControlPanel(account_dict["login_obj"], hass)
        # type: AlexaAlarmControlPanel
        if not alexa_client:
            continue
        devices.append(alexa_client)
        (
            hass.data[DATA_ALEXAMEDIA]["accounts"][account]["entities"][
                "alarm_control_panel"
            ]
        ) = alexa_client
    if devices:
        _LOGGER.debug("Adding %s", devices)
        try:
            add_devices_callback(devices, True)
        except HomeAssistantError as exception_:
            message = exception_.message  # type: str
            if message.startswith("Entity id already exists"):
                _LOGGER.debug("Device already added: %s", message)
            else:
                _LOGGER.debug("Unable to add devices: %s : %s", devices, message)
    return True


# Traceback (KeyError)
2019-06-23 09:59:32 ERROR (MainThread) [homeassistant.components.alarm_control_panel] Error while setting up platform alexa_media
Traceback (most recent call last):
File "/usr/src/app/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 "/config/custom_components/alexa_media/alarm_control_panel.py", line 34, in setup_platform
hass)  \
File "/config/custom_components/alexa_media/alarm_control_panel.py", line 73, in __init__
['LambdaBridge_AAA/OnGuardSmartHomeBridgeService']
KeyError: 'LambdaBridge_AAA/OnGuardSmartHomeBridgeService'

# Fixed code
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Set up the Alexa alarm control panel platform."""
    devices = []  # type: List[AlexaAlarmControlPanel]
    for account, account_dict in hass.data[DATA_ALEXAMEDIA]["accounts"].items():
        alexa_client = AlexaAlarmControlPanel(account_dict["login_obj"], hass)
        # type: AlexaAlarmControlPanel
        if not (alexa_client and alexa_client.unique_id):
            _LOGGER.debug(
                "%s: Skipping creation of uninitialized device: %s",
                account,
                alexa_client,
            )
            continue
        devices.append(alexa_client)
        (
            hass.data[DATA_ALEXAMEDIA]["accounts"][account]["entities"][
                "alarm_control_panel"
            ]
        ) = alexa_client
    if devices:
        _LOGGER.debug("Adding %s", devices)
        try:
            add_devices_callback(devices, True)
        except HomeAssistantError as exception_:
            message = exception_.message  # type: str
            if message.startswith("Entity id already exists"):
                _LOGGER.debug("Device already added: %s", message)
            else:
                _LOGGER.debug("Unable to add devices: %s : %s", devices, message)
    return True