Move legacy tts setup to use tracked tasks (#113717)

* Move legacy tts setup to a tracked task

* comment

* fix test

* fix test

* fix more tests

* tweak
This commit is contained in:
J. Nick Koston 2024-03-18 02:11:22 -10:00 committed by GitHub
parent 719d373bd7
commit 8f33bad4ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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)

View file

@ -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,