Fix config entry _async_process_on_unload being called for forwarded platforms (#117084)
This commit is contained in:
parent
ac9b8cce37
commit
89049bc022
3 changed files with 13 additions and 6 deletions
|
@ -144,6 +144,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
dispatcher = wemo_data.config_entry_data.dispatcher
|
||||
if unload_ok := await dispatcher.async_unload_platforms(hass):
|
||||
for coordinator in list(
|
||||
wemo_data.config_entry_data.device_coordinators.values()
|
||||
):
|
||||
await coordinator.async_shutdown()
|
||||
assert not wemo_data.config_entry_data.device_coordinators
|
||||
wemo_data.config_entry_data = None # type: ignore[assignment]
|
||||
return unload_ok
|
||||
|
|
|
@ -142,6 +142,8 @@ class DeviceCoordinator(DataUpdateCoordinator[None]): # pylint: disable=hass-en
|
|||
|
||||
async def async_shutdown(self) -> None:
|
||||
"""Unregister push subscriptions and remove from coordinators dict."""
|
||||
if self._shutdown_requested:
|
||||
return
|
||||
await super().async_shutdown()
|
||||
if TYPE_CHECKING:
|
||||
# mypy doesn't known that the device_id is set in async_setup.
|
||||
|
|
|
@ -753,7 +753,7 @@ class ConfigEntry(Generic[_DataT]):
|
|||
|
||||
component = await integration.async_get_component()
|
||||
|
||||
if integration.domain == self.domain:
|
||||
if domain_is_integration := self.domain == integration.domain:
|
||||
if not self.state.recoverable:
|
||||
return False
|
||||
|
||||
|
@ -765,7 +765,7 @@ class ConfigEntry(Generic[_DataT]):
|
|||
supports_unload = hasattr(component, "async_unload_entry")
|
||||
|
||||
if not supports_unload:
|
||||
if integration.domain == self.domain:
|
||||
if domain_is_integration:
|
||||
self._async_set_state(
|
||||
hass, ConfigEntryState.FAILED_UNLOAD, "Unload not supported"
|
||||
)
|
||||
|
@ -777,15 +777,16 @@ class ConfigEntry(Generic[_DataT]):
|
|||
assert isinstance(result, bool)
|
||||
|
||||
# Only adjust state if we unloaded the component
|
||||
if result and integration.domain == self.domain:
|
||||
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
|
||||
if domain_is_integration:
|
||||
if result:
|
||||
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
|
||||
|
||||
await self._async_process_on_unload(hass)
|
||||
await self._async_process_on_unload(hass)
|
||||
except Exception as exc:
|
||||
_LOGGER.exception(
|
||||
"Error unloading entry %s for %s", self.title, integration.domain
|
||||
)
|
||||
if integration.domain == self.domain:
|
||||
if domain_is_integration:
|
||||
self._async_set_state(
|
||||
hass, ConfigEntryState.FAILED_UNLOAD, str(exc) or "Unknown error"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue