mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
Fix config entry _async_process_on_unload being called for forwarded platforms (#117084)
This commit is contained in:
parent
ac9b8cce37
commit
89049bc022
@ -144,6 +144,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
dispatcher = wemo_data.config_entry_data.dispatcher
|
dispatcher = wemo_data.config_entry_data.dispatcher
|
||||||
if unload_ok := await dispatcher.async_unload_platforms(hass):
|
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
|
assert not wemo_data.config_entry_data.device_coordinators
|
||||||
wemo_data.config_entry_data = None # type: ignore[assignment]
|
wemo_data.config_entry_data = None # type: ignore[assignment]
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -142,6 +142,8 @@ class DeviceCoordinator(DataUpdateCoordinator[None]): # pylint: disable=hass-en
|
|||||||
|
|
||||||
async def async_shutdown(self) -> None:
|
async def async_shutdown(self) -> None:
|
||||||
"""Unregister push subscriptions and remove from coordinators dict."""
|
"""Unregister push subscriptions and remove from coordinators dict."""
|
||||||
|
if self._shutdown_requested:
|
||||||
|
return
|
||||||
await super().async_shutdown()
|
await super().async_shutdown()
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# mypy doesn't known that the device_id is set in async_setup.
|
# 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()
|
component = await integration.async_get_component()
|
||||||
|
|
||||||
if integration.domain == self.domain:
|
if domain_is_integration := self.domain == integration.domain:
|
||||||
if not self.state.recoverable:
|
if not self.state.recoverable:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -765,7 +765,7 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
supports_unload = hasattr(component, "async_unload_entry")
|
supports_unload = hasattr(component, "async_unload_entry")
|
||||||
|
|
||||||
if not supports_unload:
|
if not supports_unload:
|
||||||
if integration.domain == self.domain:
|
if domain_is_integration:
|
||||||
self._async_set_state(
|
self._async_set_state(
|
||||||
hass, ConfigEntryState.FAILED_UNLOAD, "Unload not supported"
|
hass, ConfigEntryState.FAILED_UNLOAD, "Unload not supported"
|
||||||
)
|
)
|
||||||
@ -777,15 +777,16 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
|
|
||||||
# Only adjust state if we unloaded the component
|
# Only adjust state if we unloaded the component
|
||||||
if result and integration.domain == self.domain:
|
if domain_is_integration:
|
||||||
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
|
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:
|
except Exception as exc:
|
||||||
_LOGGER.exception(
|
_LOGGER.exception(
|
||||||
"Error unloading entry %s for %s", self.title, integration.domain
|
"Error unloading entry %s for %s", self.title, integration.domain
|
||||||
)
|
)
|
||||||
if integration.domain == self.domain:
|
if domain_is_integration:
|
||||||
self._async_set_state(
|
self._async_set_state(
|
||||||
hass, ConfigEntryState.FAILED_UNLOAD, str(exc) or "Unknown error"
|
hass, ConfigEntryState.FAILED_UNLOAD, str(exc) or "Unknown error"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user