Skip to content

Commit 7ff586d

Browse files
committed
fix: unload switch platform on reload
async_unload_entry was reading entry_data["loaded_platforms"], a key that is never written, so it always passed an empty set to async_unload_platforms. The switch platform was never torn down, and the next async_setup_entry (options save, reload) raised "Config entry ... for unifi_network_rules.switch has already been setup!" Use PLATFORMS directly to mirror async_forward_entry_setups in setup. Bumps version to 4.4.2.
1 parent 3fdfdff commit 7ff586d

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

custom_components/unifi_network_rules/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,21 @@ def _handle_entity_registry_updated(event):
229229

230230
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
231231
"""Unload a config entry."""
232-
# Only unload platforms that were successfully loaded
233232
if entry.entry_id in hass.data.get(DOMAIN, {}):
234233
entry_data = hass.data[DOMAIN][entry.entry_id]
235-
loaded_platforms = entry_data.get("loaded_platforms", set())
236234

237-
LOGGER.debug("Unloading entry: %s with loaded platforms: %s", entry.entry_id, loaded_platforms)
235+
LOGGER.debug("Unloading entry: %s with platforms: %s", entry.entry_id, PLATFORMS)
238236

239237
# Unregister coordinator from services
240238
if "services" in hass.data[DOMAIN] and "unregister_coordinator" in hass.data[DOMAIN]["services"]:
241239
LOGGER.debug("Unregistering coordinator for entry: %s", entry.entry_id)
242240
unregister_coordinator = hass.data[DOMAIN]["services"]["unregister_coordinator"]
243241
unregister_coordinator(entry.entry_id)
244242

245-
# Attempt to unload all platforms at once
246243
try:
247-
unload_ok = await hass.config_entries.async_unload_platforms(entry, loaded_platforms)
244+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
248245
if not unload_ok:
249-
LOGGER.warning("Failed to unload one or more platforms: %s", loaded_platforms)
246+
LOGGER.warning("Failed to unload one or more platforms: %s", PLATFORMS)
250247
except Exception as unload_error:
251248
LOGGER.exception("Error unloading platforms: %s", unload_error)
252249
unload_ok = False

custom_components/unifi_network_rules/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"aiounifi>=87.0.0",
1616
"orjson>=3.8.0"
1717
],
18-
"version": "4.4.1"
18+
"version": "4.4.2"
1919
}

0 commit comments

Comments
 (0)