# Buggy code
def _update_recurring_alarm(self, value):
    _LOGGER.debug("value %s", value)
    alarm = value[1][self._sensor_property]
    reminder = None
    if isinstance(value[1][self._sensor_property], int):
        reminder = True
        alarm = dt.as_local(
            self._round_time(
                datetime.datetime.fromtimestamp(alarm / 1000, tz=LOCAL_TIMEZONE)
            )
        )
    alarm_on = value[1]["status"] == "ON"
    recurring_pattern = value[1].get("recurringPattern")
    while (
        alarm_on
        and recurring_pattern
        and RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm.isoweekday not in RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm < dt.now()
    ):
        alarm += datetime.timedelta(days=1)
    if reminder:
        alarm = dt.as_timestamp(alarm) * 1000
    if alarm != value[1][self._sensor_property]:
        _LOGGER.debug(
            "%s with recurrence %s set to %s",
            value[1]["type"],
            RECURRING_PATTERN[recurring_pattern],
            alarm,
        )
        value[1][self._sensor_property] = alarm
    return value


# 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
def _update_recurring_alarm(self, value):
    _LOGGER.debug("Sensor value %s", value)
    alarm = value[1][self._sensor_property]
    reminder = None
    if isinstance(value[1][self._sensor_property], int):
        reminder = True
        alarm = dt.as_local(
            self._round_time(
                datetime.datetime.fromtimestamp(alarm / 1000, tz=LOCAL_TIMEZONE)
            )
        )
    alarm_on = value[1]["status"] == "ON"
    recurring_pattern = value[1].get("recurringPattern")
    while (
        alarm_on
        and recurring_pattern
        and RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm.isoweekday not in RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm < dt.now()
    ):
        alarm += datetime.timedelta(days=1)
    if reminder:
        alarm = dt.as_timestamp(alarm) * 1000
    if alarm != value[1][self._sensor_property]:
        _LOGGER.debug(
            "%s with recurrence %s set to %s",
            value[1]["type"],
            RECURRING_PATTERN[recurring_pattern],
            alarm,
        )
        value[1][self._sensor_property] = alarm
    return value