@@ -105,6 +105,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
105
105
try :
106
106
_LOGGER .debug ("Unloading config entry: %s" , entry .entry_id )
107
107
all_ok = True
108
+
109
+ # Unload platforms
108
110
for platform in SUPPORTED_PLATFORMS :
109
111
_LOGGER .debug ("%s - async_unload_entry: unload platform: %s" , entry .entry_id , platform )
110
112
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:
113
115
all_ok = platform_ok
114
116
115
117
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
116
126
_LOGGER .debug ("%s - async_unload_entry: Unload option updates listener: %s.%s " , entry .entry_id , FUNC_OPTION_UPDATES )
117
127
hass .data [DOMAIN ][entry .entry_id ][FUNC_OPTION_UPDATES ]()
128
+
129
+ # Remove data store
118
130
_LOGGER .debug ("%s - async_unload_entry: Remove data store: %s.%s " , entry .entry_id , DOMAIN , entry .entry_id )
119
131
hass .data [DOMAIN ].pop (entry .entry_id )
132
+
120
133
return all_ok
121
134
except Exception as e :
122
135
_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