Adjust config entry state checks in qbus (#138911)

pull/138916/head
Erik Montnemery 2025-02-20 08:57:55 +01:00 committed by GitHub
parent a2ceeb19dc
commit 0949f7d0ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 8 deletions

View File

@ -71,17 +71,14 @@ async def async_unload_entry(hass: HomeAssistant, entry: QbusConfigEntry) -> boo
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
entry.runtime_data.shutdown()
cleanup(hass, entry)
_cleanup(hass, entry)
return unload_ok
def cleanup(hass: HomeAssistant, entry: QbusConfigEntry) -> None:
def _cleanup(hass: HomeAssistant, entry: QbusConfigEntry) -> None:
"""Shutdown if no more entries are loaded."""
entries = hass.config_entries.async_loaded_entries(DOMAIN)
count = len(entries)
# During unloading of the entry, it is not marked as unloaded yet. So
# count can be 1 if it is the last one.
if count <= 1 and (config_coordinator := hass.data.get(QBUS_KEY)):
if not hass.config_entries.async_loaded_entries(DOMAIN) and (
config_coordinator := hass.data.get(QBUS_KEY)
):
config_coordinator.shutdown()