diff --git a/tests/components/knx/test_init.py b/tests/components/knx/test_init.py index a26bdc34a367bb..0f998303084681 100644 --- a/tests/components/knx/test_init.py +++ b/tests/components/knx/test_init.py @@ -290,14 +290,12 @@ async def _init_switch_and_wait_for_first_state_updater_run( freezer.tick(timedelta(minutes=59)) async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) await knx.assert_no_telegram() freezer.tick(timedelta(minutes=1)) # 60 minutes passed async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) async def test_default_state_updater_enabled( diff --git a/tests/components/nest/test_media_source.py b/tests/components/nest/test_media_source.py index 0b0654fc69c2dc..efdd25d1ab6fbb 100644 --- a/tests/components/nest/test_media_source.py +++ b/tests/components/nest/test_media_source.py @@ -1644,8 +1644,7 @@ async def test_remove_stale_media( point_in_time = datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=1) with freeze_time(point_in_time): async_fire_time_changed(hass, point_in_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) # Verify that the event media is still present and that the extra files # are removed. Newer media is not removed. diff --git a/tests/components/openrgb/test_init.py b/tests/components/openrgb/test_init.py index 9d1637da811d81..d73dd502e392ea 100644 --- a/tests/components/openrgb/test_init.py +++ b/tests/components/openrgb/test_init.py @@ -246,8 +246,7 @@ async def test_reconnection_on_update_failure( freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) # Verify that disconnect and connect were called (reconnection happened) mock_openrgb_client.disconnect.assert_called_once() @@ -295,9 +294,7 @@ async def test_reconnection_fails_second_attempt( freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) # Verify that the light became unavailable after failed reconnection state = hass.states.get("light.ene_dram") @@ -340,8 +337,7 @@ async def test_normal_update_without_errors( freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) # Verify that disconnect and connect were NOT called (no reconnection needed) mock_openrgb_client.disconnect.assert_not_called() diff --git a/tests/components/playstation_network/test_image.py b/tests/components/playstation_network/test_image.py index 0dc52646d9e6cf..b0d4d1ac79a29c 100644 --- a/tests/components/playstation_network/test_image.py +++ b/tests/components/playstation_network/test_image.py @@ -75,8 +75,7 @@ async def test_image_platform( freezer.tick(timedelta(seconds=30)) async_fire_time_changed(hass) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert (state := hass.states.get("image.testuser_avatar")) assert state.state == "2025-06-16T00:00:30+00:00" diff --git a/tests/components/rflink/test_binary_sensor.py b/tests/components/rflink/test_binary_sensor.py index fd113bceaa0f43..303b39ef8c1d5d 100644 --- a/tests/components/rflink/test_binary_sensor.py +++ b/tests/components/rflink/test_binary_sensor.py @@ -176,8 +176,7 @@ def listener(event): future = now + timedelta(seconds=35) with freeze_time(future): async_fire_time_changed(hass, future) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) state = hass.states.get("binary_sensor.test2") assert state.state == STATE_ON assert len(events) == 2 @@ -186,8 +185,7 @@ def listener(event): future = now + timedelta(seconds=45) with freeze_time(future): async_fire_time_changed(hass, future) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) state = hass.states.get("binary_sensor.test2") assert state.state == STATE_OFF assert len(events) == 3 diff --git a/tests/components/sun/test_init.py b/tests/components/sun/test_init.py index 3896498bbb00df..203207d616e60e 100644 --- a/tests/components/sun/test_init.py +++ b/tests/components/sun/test_init.py @@ -148,8 +148,7 @@ async def test_state_change( caplog.clear() with freeze_time(patched_time): async_fire_time_changed(hass, patched_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert caplog.text.count("sun phase_update") == 1 # Called once by time listener, once from Sun.update_events diff --git a/tests/components/template/test_sensor.py b/tests/components/template/test_sensor.py index 0a940d111c5ece..d0e9f565d63ec9 100644 --- a/tests/components/template/test_sensor.py +++ b/tests/components/template/test_sensor.py @@ -1005,8 +1005,7 @@ async def test_self_referencing_entity_picture_loop( "homeassistant.helpers.ratelimit.time.time", return_value=next_time.timestamp() ): async_fire_time_changed(hass, next_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert "Template loop detected" in caplog_setup_text diff --git a/tests/components/template/test_trigger.py b/tests/components/template/test_trigger.py index 6de07612c36952..9caa252eff6345 100644 --- a/tests/components/template/test_trigger.py +++ b/tests/components/template/test_trigger.py @@ -882,22 +882,19 @@ async def test_if_fires_on_time_change( second_time = start_time.replace(minute=4, second=0) freezer.move_to(second_time) async_fire_time_changed(hass, second_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(calls) == 1 # Trigger again (do not match template) third_time = start_time.replace(minute=5, second=0) freezer.move_to(third_time) async_fire_time_changed(hass, third_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(calls) == 1 # Trigger again (match template) forth_time = start_time.replace(minute=8, second=0) freezer.move_to(forth_time) async_fire_time_changed(hass, forth_time) - await hass.async_block_till_done() - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(calls) == 2