alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.51k stars 289 forks source link

ValueError: Config entry has already been setup! #451

Closed denverpilot closed 4 years ago

denverpilot commented 5 years ago

I am seeing errors saying certain items are "already setup" at startup on a system with both Nabu Casa and this community integration combined.

I assume that's the cause anyway... having a hard time determining which one is running first and which is throwing the error.

I also assume I could probably disable the items that this integration tries to do and only leave the ones the Nebu Casa one doesn't do, activated, but not sure if that'll break things. Not sure if it would break nice things like the add-on being able to do TTS while the paid integration doesn't.

I suppose it might be nice if the add on detected an existing integration and skipped those items automatically?

Overall the bug seems harmless. Just reporting for folks who might see similar at startup.


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**```
alandtse commented 5 years ago

There's already logic to try to determine if a component has been loaded. However, it does run into issues sometime. As you noted, this looks like a cosmetic error since HA won't try to load it again.

denverpilot commented 5 years ago

Roger! As an old sysadmin with white hair, error messages give me PTSD (ha, joking!) but agreed that it looked cosmetic overall -- I just wanted to let devs know in case the code following it wasn't running after the error. This is totally a "back burner it" sort of bug for when someone is bored... LOL! Thanks for checking! Can leave open or close as you all wish...

genem2 commented 4 years ago

I landed here with 107.x; haven't seen it earlier. HA: 107.4, unRAID docker Plug-in: v2.5.7

I'm only seeing these log entries during the initial HA startup after an update.

However, with v2.5.7, I'm now getting this on each subsequent HA restart: (I can log this separately if desired.)

 2020-03-21 06:08:22 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up alexa_media platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/alexa_media/sensor.py", line 151, in async_setup_entry
    hass, config_entry.data, async_add_devices, discovery_info=None
  File "/config/custom_components/alexa_media/helpers.py", line 111, in wrapper
    result = await func(*args, **kwargs)
  File "/config/custom_components/alexa_media/sensor.py", line 112, in async_setup_platform
    account,
  File "/config/custom_components/alexa_media/sensor.py", line 414, in __init__
    client, n_json, "date_time", account, f"next {self._type}", "mdi:alarm"
  File "/config/custom_components/alexa_media/sensor.py", line 192, in __init__
    self._process_raw_notifications()
  File "/config/custom_components/alexa_media/sensor.py", line 200, in _process_raw_notifications
    self._all = list(map(self._update_recurring_alarm, self._all))
  File "/config/custom_components/alexa_media/sensor.py", line 252, in _update_recurring_alarm
    and alarm.isoweekday not in RECURRING_PATTERN_ISO_SET[recurring_pattern]
TypeError: argument of type 'int' is not iterable
alandtse commented 4 years ago

Please open a new issue for the TypeError.

genem2 commented 4 years ago

Just FYI: I'm now seeing this, suspecting it started recently with one of the newer releases. Home Assistant 0.107.7, alexa_media: Installed: v2.5.11 alexapy==1.5.2

Advise if I can posting anything more...

2020-04-05 08:10:51 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry <MY_EMAIL> - amazon.com for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 216, in async_setup
    hass, self
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 59, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 156, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
alandtse commented 4 years ago

It's entirely based on timing in HA. If the component has to load dependent devices later, it will end up triggering that error. It appears entirely cosmetic at this point.

genem2 commented 4 years ago

Ok, thank you. Ignoring. But curious: 'dependent devices'? Is this initiated by something I'd doing, perhaps disabling in the Entity mgr? Tnx.

alandtse commented 4 years ago

The switches (repeat, do not disturb) Guard mode, and timer notifications are all dependent on the media player loading. So if a media player hasn't been fully loaded, all those dependent devices need to wait to load.