Skip to content

Commit c61a5ca

Browse files
authored
Merge pull request #18 from disforw/fix-unld
Fix unload
2 parents 9b768b9 + 0ad4781 commit c61a5ca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

custom_components/goveelife/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
105105
try:
106106
_LOGGER.debug("Unloading config entry: %s", entry.entry_id)
107107
all_ok = True
108+
109+
# Unload platforms
108110
for platform in SUPPORTED_PLATFORMS:
109111
_LOGGER.debug("%s - async_unload_entry: unload platform: %s", entry.entry_id, platform)
110112
platform_ok = await hass.config_entries.async_forward_entry_unload(entry, platform)
@@ -113,10 +115,21 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
113115
all_ok = platform_ok
114116

115117
if all_ok:
118+
# Remove entities from the entity registry
119+
entity_registry = hass.helpers.entity_registry.async_get(hass)
120+
entities = async_entries_for_config_entry(entity_registry, entry.entry_id)
121+
for entity in entities:
122+
_LOGGER.debug("%s - async_unload_entry: removing entity: %s", entry.entry_id, entity.entity_id)
123+
entity_registry.async_remove(entity.entity_id)
124+
125+
# Unload option updates listener
116126
_LOGGER.debug("%s - async_unload_entry: Unload option updates listener: %s.%s ", entry.entry_id, FUNC_OPTION_UPDATES)
117127
hass.data[DOMAIN][entry.entry_id][FUNC_OPTION_UPDATES]()
128+
129+
# Remove data store
118130
_LOGGER.debug("%s - async_unload_entry: Remove data store: %s.%s ", entry.entry_id, DOMAIN, entry.entry_id)
119131
hass.data[DOMAIN].pop(entry.entry_id)
132+
120133
return all_ok
121134
except Exception as e:
122135
_LOGGER.error("%s - async_unload_entry: Unload device failed: %s (%s.%s)", entry.entry_id, str(e), e.__class__.__module__, type(e).__name__)

0 commit comments

Comments
 (0)