Make eager_start default to True for async_create_task (#114995)

This commit is contained in:
J. Nick Koston 2024-04-06 09:15:40 -10:00 committed by GitHub
parent fa47e79292
commit c33a234048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -719,7 +719,7 @@ class HomeAssistant:
self,
target: Coroutine[Any, Any, _R],
name: str | None = None,
eager_start: bool = False,
eager_start: bool = True,
) -> asyncio.Task[_R]:
"""Create a task from within the event loop.

View File

@ -327,7 +327,7 @@ async def test_async_create_task_schedule_coroutine() -> None:
async def job():
pass
ha.HomeAssistant.async_create_task(hass, job())
ha.HomeAssistant.async_create_task(hass, job(), eager_start=False)
assert len(hass.loop.call_soon.mock_calls) == 0
assert len(hass.loop.create_task.mock_calls) == 1
assert len(hass.add_job.mock_calls) == 0
@ -353,7 +353,9 @@ async def test_async_create_task_schedule_coroutine_with_name() -> None:
async def job():
pass
task = ha.HomeAssistant.async_create_task(hass, job(), "named task")
task = ha.HomeAssistant.async_create_task(
hass, job(), "named task", eager_start=False
)
assert len(hass.loop.call_soon.mock_calls) == 0
assert len(hass.loop.create_task.mock_calls) == 1
assert len(hass.add_job.mock_calls) == 0