diff --git a/homeassistant/core.py b/homeassistant/core.py index 47c05442eed..6aaab452e39 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -2293,6 +2293,7 @@ class ServiceRegistry: self._hass.async_create_task( self._run_service_call_catch_exceptions(coro, service_call), f"service call background {service_call.domain}.{service_call.service}", + eager_start=True, ) return None diff --git a/tests/components/androidtv_remote/test_media_player.py b/tests/components/androidtv_remote/test_media_player.py index efb3fa97a22..0e9013550c2 100644 --- a/tests/components/androidtv_remote/test_media_player.py +++ b/tests/components/androidtv_remote/test_media_player.py @@ -1,5 +1,4 @@ """Tests for the Android TV Remote remote platform.""" -import asyncio from unittest.mock import MagicMock, call from androidtvremote2 import ConnectionClosed @@ -237,7 +236,7 @@ async def test_media_player_play_media( ) # Give background task time to run - await asyncio.sleep(0) + await hass.async_block_till_done() await hass.services.async_call( "media_player", @@ -249,7 +248,11 @@ async def test_media_player_play_media( }, blocking=True, ) - assert mock_api.send_key_command.call_count == 2 + await hass.async_block_till_done() + + # 4 7s should be sent + # 2 1s should be sent + assert mock_api.send_key_command.call_count == 6 await hass.services.async_call( "media_player", diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 1c1197131c0..7d0943b3677 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -615,6 +615,7 @@ async def test_service_calls( # check backup with different timezone await hass.config.async_update(time_zone="Europe/London") + await hass.async_block_till_done() await hass.services.async_call( "hassio", diff --git a/tests/components/rflink/test_light.py b/tests/components/rflink/test_light.py index 75d2566f336..5ee2375bc36 100644 --- a/tests/components/rflink/test_light.py +++ b/tests/components/rflink/test_light.py @@ -4,7 +4,6 @@ Test setup of RFLink lights component/platform. State tracking and control of RFLink switch devices. """ -import asyncio from homeassistant.components.light import ATTR_BRIGHTNESS from homeassistant.components.rflink import EVENT_BUTTON_PRESSED @@ -281,19 +280,21 @@ async def test_signal_repetitions_cancelling(hass: HomeAssistant, monkeypatch) - # setup mocking rflink module _, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) + await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"} ) + await hass.async_block_till_done() - # Get background service time to start running - await asyncio.sleep(0) await hass.services.async_call( DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}, blocking=True ) await hass.async_block_till_done() assert [call[0][1] for call in protocol.send_command_ack.call_args_list] == [ + "off", + "off", "off", "on", "on",