Migrate async_run_job to use eager_start for tasks (#113011)

pull/113102/head
J. Nick Koston 2024-03-11 11:30:46 -10:00 committed by GitHub
parent 52b69bcfde
commit 77cdecf0f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -855,7 +855,7 @@ class HomeAssistant:
# https://github.com/home-assistant/core/pull/71960
if TYPE_CHECKING:
target = cast(Callable[..., Coroutine[Any, Any, _R] | _R], target)
return self.async_run_hass_job(HassJob(target), *args)
return self.async_run_hass_job(HassJob(target), *args, eager_start=True)
def block_till_done(self) -> None:
"""Block until all pending work is done."""

View File

@ -2116,6 +2116,20 @@ async def test_async_functions_with_callback(hass: HomeAssistant) -> None:
assert len(runs) == 3
async def test_async_run_job_starts_tasks_eagerly(hass: HomeAssistant) -> None:
"""Test async_run_job starts tasks eagerly."""
runs = []
async def _test():
runs.append(True)
task = hass.async_run_job(_test)
# No call to hass.async_block_till_done to ensure the task is run eagerly
assert len(runs) == 1
assert task.done()
await task
def test_valid_entity_id() -> None:
"""Test valid entity ID."""
for invalid in [