mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
fix shutdown
This commit is contained in:
parent
136c7561a6
commit
a8969d7db9
@ -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…
Reference in New Issue
Block a user