ludeeus/integration_blueprint

Updating config options multiple times throws errors

mjmeli opened this issue · 0 comments

If you attempt to update the configuration options more than once, a bunch of errors are thrown in the logs. It also seems to run the __init__.py async_setup_entry multiple times. In the template, the integration recovers fine and keeps running despite the errors in the logs, however the fact that async_setup_entry is running multiple times has caused some issues in my integration that I have to work around. Ideally this wouldn't happen to save that effort.

Steps to Reproduce

  1. Setup the integration (I'm using the raw integration_blueprint template here as this issue exists in the template)
  2. Click "Configure" on the integrations page
  3. Change any setting and click "Submit" - all seems fine
  4. Click "Configure" again
  5. Change any setting again and click "Submit" again - errors will be thrown in the logs

Logs
Below I've annotated with asterisks where I performed the multiple options update. The first time, I disabled the binary_sensor platform. The second time, I re-enabled it.

2021-12-22 03:29:10 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.045 seconds (success: True)
***** Configured options first time *****
2021-12-22 03:29:37 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.055 seconds (success: True)
2021-12-22 03:29:37 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.integration_blueprint
2021-12-22 03:29:37 INFO (MainThread) [homeassistant.components.switch] Setting up switch.integration_blueprint
2021-12-22 03:30:07 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.048 seconds (success: True)
***** Configured options second time *****
2021-12-22 03:30:29 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry test for sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 472, in async_unload
    result = await component.async_unload_entry(hass, self)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/homeassistant/components/sensor/__init__.py", line 210, in async_unload_entry
    return await component.async_unload_entry(entry)
  File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 177, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
2021-12-22 03:30:29 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry test for switch
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 472, in async_unload
    result = await component.async_unload_entry(hass, self)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/homeassistant/components/switch/__init__.py", line 95, in async_unload_entry
    return await component.async_unload_entry(entry)
  File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 177, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
2021-12-22 03:30:29 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.047 seconds (success: True)
2021-12-22 03:30:29 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.integration_blueprint
2021-12-22 03:30:29 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.integration_blueprint
2021-12-22 03:30:29 INFO (MainThread) [homeassistant.components.switch] Setting up switch.integration_blueprint
2021-12-22 03:30:29 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.063 seconds (success: True)
2021-12-22 03:30:29 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry test for binary_sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 333, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/homeassistant/components/binary_sensor/__init__.py", line 163, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 162, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2021-12-22 03:30:29 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry test for sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 333, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/homeassistant/components/sensor/__init__.py", line 204, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 162, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2021-12-22 03:30:29 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry test for switch
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 333, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/homeassistant/components/switch/__init__.py", line 89, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 162, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2021-12-22 03:30:59 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.046 seconds (success: True)
2021-12-22 03:31:29 DEBUG (MainThread) [custom_components.integration_blueprint] Finished fetching integration_blueprint data in 0.044 seconds (success: True)