Make Debouncer shutdown async (#91542)
* Make shutdown async in Debouncer * Adjust testpull/91575/head
parent
e32dacc62d
commit
81f018b7e5
|
@ -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."""
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue