Add support for background tasks in HA (#88265)
* Add support for background tasks * make name mandatory for background tasks * Update docstring * async_create_background_task * Grammar
This commit is contained in:
@@ -1933,3 +1933,21 @@ async def test_state_changed_events_to_not_leak_contexts(hass: HomeAssistant) ->
|
||||
gc.collect()
|
||||
|
||||
assert len(_get_by_type("homeassistant.core.Context")) == init_count
|
||||
|
||||
|
||||
async def test_background_task(hass):
|
||||
"""Test background tasks being quit."""
|
||||
result = asyncio.Future()
|
||||
|
||||
async def test_task():
|
||||
try:
|
||||
await asyncio.sleep(1)
|
||||
except asyncio.CancelledError:
|
||||
result.set_result(hass.state)
|
||||
raise
|
||||
|
||||
task = hass.async_create_background_task(test_task(), "happy task")
|
||||
assert "happy task" in str(task)
|
||||
await asyncio.sleep(0)
|
||||
await hass.async_stop()
|
||||
assert result.result() == ha.CoreState.stopping
|
||||
|
||||
Reference in New Issue
Block a user