# Buggy code
async def ws_error_handler(message):
    """Handle websocket error.

    This currently logs the error.  In the future, this should invalidate
    the websocket and determine if a reconnect should be done. By
    specification, websockets will issue a close after every error.
    """
    email = login_obj.email
    errors = hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"]
    _LOGGER.debug(
        "%s: Received websocket error #%i %s: type %s",
        hide_email(email),
        errors,
        message,
        type(message),
    )
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"] = None
    if message == "<class 'aiohttp.streams.EofStream'>":
        hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = 5
        _LOGGER.debug("%s: Immediate abort on EoFstream", hide_email(email))
        return
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = errors + 1


# Traceback (ValueError)
2019-10-26 14:43:05 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ***REDACTED*** - amazon.com for media_player
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 340, in async_setup_entry
return await hass.data[DOMAIN].async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 151, in async_setup_entry
raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2019-10-26 14:43:05 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ***REDACTED*** - amazon.com for alarm_control_panel
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/usr/src/homeassistant/homeassistant/components/alarm_control_panel/__init__.py", line 74, in async_setup_entry
return await hass.data[DOMAIN].async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 151, in async_setup_entry
raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2019-10-26 14:43:05 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ***REDACTED*** - amazon.com for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/usr/src/homeassistant/homeassistant/components/switch/__init__.py", line 79, in async_setup_entry
return await hass.data[DOMAIN].async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 151, in async_setup_entry
raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2019-10-26 14:43:05 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ***REDACTED*** - amazon.com for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 60, in async_setup_entry
return await hass.data[DOMAIN].async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 151, in async_setup_entry
raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!**System details**```

# Fixed code
async def ws_error_handler(message):
    """Handle websocket error.

    This currently logs the error.  In the future, this should invalidate
    the websocket and determine if a reconnect should be done. By
    specification, websockets will issue a close after every error.
    """
    email: Text = login_obj.email
    errors = hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"]
    _LOGGER.debug(
        "%s: Received websocket error #%i %s: type %s",
        hide_email(email),
        errors,
        message,
        type(message),
    )
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"] = None
    if message == "<class 'aiohttp.streams.EofStream'>":
        hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = 5
        _LOGGER.debug("%s: Immediate abort on EoFstream", hide_email(email))
        return
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = errors + 1