Cancel config entry retry, platform retry, and polling at the stop event (#49138)
This commit is contained in:
parent
0b4b071c02
commit
44beff31c2
6 changed files with 143 additions and 13 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue