Make Debouncer shutdown async (#91542)

* Make shutdown async in Debouncer

* Adjust test
pull/91575/head
epenet 2023-04-17 23:31:30 +02:00 committed by GitHub
parent e32dacc62d
commit 81f018b7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 6 deletions

View File

@ -165,10 +165,9 @@ class DebouncedEntryReloader:
LOGGER.debug("Calling debouncer to get a reload after cooldown") LOGGER.debug("Calling debouncer to get a reload after cooldown")
await self._debounced_reload.async_call() await self._debounced_reload.async_call()
@callback async def async_shutdown(self) -> None:
def async_shutdown(self) -> None:
"""Cancel any pending reload.""" """Cancel any pending reload."""
self._debounced_reload.async_shutdown() await self._debounced_reload.async_shutdown()
async def _async_reload_entry(self) -> None: async def _async_reload_entry(self) -> None:
"""Reload entry.""" """Reload entry."""

View File

@ -118,8 +118,7 @@ class Debouncer(Generic[_R_co]):
# Schedule a new timer to prevent new runs during cooldown # Schedule a new timer to prevent new runs during cooldown
self._schedule_timer() self._schedule_timer()
@callback async def async_shutdown(self) -> None:
def async_shutdown(self) -> None:
"""Cancel any scheduled call, and prevent new runs.""" """Cancel any scheduled call, and prevent new runs."""
self._shutdown_requested = True self._shutdown_requested = True
self.async_cancel() self.async_cancel()

View File

@ -202,7 +202,7 @@ async def test_shutdown(hass: HomeAssistant) -> None:
# Ensure shutdown during a run doesn't create a cooldown timer # Ensure shutdown during a run doesn't create a cooldown timer
hass.async_create_task(debouncer.async_call()) hass.async_create_task(debouncer.async_call())
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
debouncer.async_shutdown() await debouncer.async_shutdown()
future.set_result(True) future.set_result(True)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 1 assert len(calls) == 1