fix shutdown
This commit is contained in:
parent
136c7561a6
commit
a8969d7db9
1 changed files with 7 additions and 3 deletions
|
@ -184,6 +184,7 @@ def get_test_home_assistant() -> Generator[HomeAssistant, None, None]:
|
|||
def stop_hass() -> None:
|
||||
"""Stop hass."""
|
||||
orig_stop()
|
||||
asyncio.run_coroutine_threadsafe(asyncio.sleep(0), loop).result()
|
||||
loop_stop_event.wait()
|
||||
|
||||
hass.start = start_hass
|
||||
|
@ -346,13 +347,16 @@ async def async_test_home_assistant(
|
|||
|
||||
hass.set_state(CoreState.running)
|
||||
|
||||
@callback
|
||||
def clear_instance(event):
|
||||
async def clear_instance(event):
|
||||
"""Clear global instance."""
|
||||
# Give time for the aiohttp, and anything else that is
|
||||
# not scheduling tasks eagerly to run one iteration
|
||||
# to shutdown.
|
||||
await asyncio.sleep(0)
|
||||
INSTANCES.remove(hass)
|
||||
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_CLOSE, clear_instance, run_immediately=False
|
||||
EVENT_HOMEASSISTANT_CLOSE, clear_instance, run_immediately=True
|
||||
)
|
||||
|
||||
yield hass
|
||||
|
|
Loading…
Add table
Reference in a new issue