mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Cancel config entry retry, platform retry, and polling at the stop event (#49138)
This commit is contained in:
@@ -174,6 +174,18 @@ class EntityPlatform:
|
||||
|
||||
await self._async_setup_platform(async_create_setup_task)
|
||||
|
||||
async def async_shutdown(self) -> None:
|
||||
"""Call when Home Assistant is stopping."""
|
||||
self.async_cancel_retry_setup()
|
||||
self.async_unsub_polling()
|
||||
|
||||
@callback
|
||||
def async_cancel_retry_setup(self) -> None:
|
||||
"""Cancel retry setup."""
|
||||
if self._async_cancel_retry_setup is not None:
|
||||
self._async_cancel_retry_setup()
|
||||
self._async_cancel_retry_setup = None
|
||||
|
||||
async def async_setup_entry(self, config_entry: config_entries.ConfigEntry) -> bool:
|
||||
"""Set up the platform from a config entry."""
|
||||
# Store it so that we can save config entry ID in entity registry
|
||||
@@ -549,9 +561,7 @@ class EntityPlatform:
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
if self._async_cancel_retry_setup is not None:
|
||||
self._async_cancel_retry_setup()
|
||||
self._async_cancel_retry_setup = None
|
||||
self.async_cancel_retry_setup()
|
||||
|
||||
if not self.entities:
|
||||
return
|
||||
@@ -560,10 +570,15 @@ class EntityPlatform:
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
self.async_unsub_polling()
|
||||
self._setup_complete = False
|
||||
|
||||
@callback
|
||||
def async_unsub_polling(self) -> None:
|
||||
"""Stop polling."""
|
||||
if self._async_unsub_polling is not None:
|
||||
self._async_unsub_polling()
|
||||
self._async_unsub_polling = None
|
||||
self._setup_complete = False
|
||||
|
||||
async def async_destroy(self) -> None:
|
||||
"""Destroy an entity platform.
|
||||
|
||||
Reference in New Issue
Block a user