Hi, I’m searching for the same reload option in custom developed component. Indeed, as soon as I implemented the async_unload_entry
, the Reload option became available in ‘Integrations’.
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
await hass.config_entries.async_unload_platforms(config_entry, "sensor")
return True
I’ve also implemented async_remove_entry
in __init__.py
async def async_remove_entry(hass, config_entry):
try:
await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
_LOGGER.info("Successfully removed sensor from the integration")
except ValueError:
pass
And in my sensor.py
I’ve added async_remove_entry
:
async def async_remove_entry(hass, config_entry):
_LOGGER.info("async_remove_entry " + NAME)
try:
await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
_LOGGER.info("Successfully removed sensor from the integration")
except ValueError:
pass
and in my sensor component itself I defined: async_will_remove_from_hass
which would clear my session so next time it’s used, it would re-initiate the session.
async def async_will_remove_from_hass(self):
"""Clean up after entity before removal."""
_LOGGER.info("async_will_remove_from_hass " + NAME)
self._data.clear_session()
But when I try the reload I get an error indicating the entry can’t be setup since it already exists. While the remove entry is never called.
2023-01-08 13:12:45.268 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Telenet Telemeter for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 372, in async_setup
result = await component.async_setup_entry(hass, self)
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 431, in async_setup_entry
return await component.async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 166, in async_setup_entry
raise ValueError("Config entry has already been setup!")
Could someone explain me the flow to be used? or point to the correct docs? I was checking this info: Config Entries | Home Assistant Developer Docs