diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index f445309fffe..82055d542ff 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -319,9 +319,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: platform_setups = await async_setup_legacy(hass, config) - if platform_setups: - await asyncio.wait([asyncio.create_task(setup) for setup in platform_setups]) - component.async_register_entity_service( "speak", { @@ -345,6 +342,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: schema=SCHEMA_SERVICE_CLEAR_CACHE, ) + for setup in platform_setups: + # Tasks are created as tracked tasks to ensure startup + # waits for them to finish, but we explicitly do not + # want to wait for them to finish here because we want + # any config entries that use tts as a base platform + # to be able to start with out having to wait for the + # legacy platforms to finish setting up. + hass.async_create_task(setup, eager_start=True) + return True diff --git a/tests/components/cloud/test_tts.py b/tests/components/cloud/test_tts.py index 2fd42012c77..3797a9784e1 100644 --- a/tests/components/cloud/test_tts.py +++ b/tests/components/cloud/test_tts.py @@ -101,6 +101,7 @@ async def test_prefs_default_voice( """Test cloud provider uses the preferences.""" assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, TTS_DOMAIN, {TTS_DOMAIN: platform_config}) + await hass.async_block_till_done() assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) await hass.async_block_till_done() @@ -108,6 +109,7 @@ async def test_prefs_default_voice( on_start_callback = cloud.register_on_start.call_args[0][0] await on_start_callback() + await hass.async_block_till_done() engine = get_engine_instance(hass, engine_id) diff --git a/tests/components/microsoft/test_tts.py b/tests/components/microsoft/test_tts.py index cd4ccabcf0d..c395dc82419 100644 --- a/tests/components/microsoft/test_tts.py +++ b/tests/components/microsoft/test_tts.py @@ -61,6 +61,7 @@ async def test_service_say( await async_setup_component( hass, tts.DOMAIN, {tts.DOMAIN: {"platform": "microsoft", "api_key": ""}} ) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN, @@ -110,6 +111,7 @@ async def test_service_say_en_gb_config( } }, ) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN, @@ -151,6 +153,7 @@ async def test_service_say_en_gb_service( tts.DOMAIN, {tts.DOMAIN: {"platform": "microsoft", "api_key": ""}}, ) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN, @@ -201,6 +204,7 @@ async def test_service_say_fa_ir_config( } }, ) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN, @@ -246,6 +250,7 @@ async def test_service_say_fa_ir_service( } await async_setup_component(hass, tts.DOMAIN, config) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN, @@ -303,6 +308,7 @@ async def test_invalid_language(hass: HomeAssistant, mock_tts, calls) -> None: tts.DOMAIN, {tts.DOMAIN: {"platform": "microsoft", "api_key": "", "language": "en"}}, ) + await hass.async_block_till_done() with pytest.raises(ServiceNotFound): await hass.services.async_call( @@ -327,6 +333,7 @@ async def test_service_say_error( await async_setup_component( hass, tts.DOMAIN, {tts.DOMAIN: {"platform": "microsoft", "api_key": ""}} ) + await hass.async_block_till_done() await hass.services.async_call( tts.DOMAIN,