Convert async_get_conversation_languages from async to callback (#121162)

* Convert get_languages to callback

* One more callback
This commit is contained in:
Paulus Schoutsen 2024-07-04 10:41:31 +02:00 committed by GitHub
parent cf96084ea3
commit 869f24df49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View file

@ -115,7 +115,8 @@ AUDIO_PROCESSOR_SAMPLES: Final = 160 # 10 ms @ 16 Khz
AUDIO_PROCESSOR_BYTES: Final = AUDIO_PROCESSOR_SAMPLES * 2 # 16-bit samples AUDIO_PROCESSOR_BYTES: Final = AUDIO_PROCESSOR_SAMPLES * 2 # 16-bit samples
async def _async_resolve_default_pipeline_settings( @callback
def _async_resolve_default_pipeline_settings(
hass: HomeAssistant, hass: HomeAssistant,
stt_engine_id: str | None, stt_engine_id: str | None,
tts_engine_id: str | None, tts_engine_id: str | None,
@ -139,7 +140,7 @@ async def _async_resolve_default_pipeline_settings(
# Find a matching language supported by the Home Assistant conversation agent # Find a matching language supported by the Home Assistant conversation agent
conversation_languages = language_util.matches( conversation_languages = language_util.matches(
hass.config.language, hass.config.language,
await conversation.async_get_conversation_languages( conversation.async_get_conversation_languages(
hass, conversation.HOME_ASSISTANT_AGENT hass, conversation.HOME_ASSISTANT_AGENT
), ),
country=hass.config.country, country=hass.config.country,
@ -222,7 +223,7 @@ async def _async_create_default_pipeline(
The default pipeline will use the homeassistant conversation agent and the The default pipeline will use the homeassistant conversation agent and the
default stt / tts engines. default stt / tts engines.
""" """
pipeline_settings = await _async_resolve_default_pipeline_settings( pipeline_settings = _async_resolve_default_pipeline_settings(
hass, stt_engine_id=None, tts_engine_id=None, pipeline_name="Home Assistant" hass, stt_engine_id=None, tts_engine_id=None, pipeline_name="Home Assistant"
) )
return await pipeline_store.async_create_item(pipeline_settings) return await pipeline_store.async_create_item(pipeline_settings)
@ -241,7 +242,7 @@ async def async_create_default_pipeline(
""" """
pipeline_data: PipelineData = hass.data[DOMAIN] pipeline_data: PipelineData = hass.data[DOMAIN]
pipeline_store = pipeline_data.pipeline_store pipeline_store = pipeline_data.pipeline_store
pipeline_settings = await _async_resolve_default_pipeline_settings( pipeline_settings = _async_resolve_default_pipeline_settings(
hass, stt_engine_id, tts_engine_id, pipeline_name=pipeline_name hass, stt_engine_id, tts_engine_id, pipeline_name=pipeline_name
) )
if ( if (

View file

@ -378,8 +378,8 @@ def websocket_get_run(
vol.Required("type"): "assist_pipeline/language/list", vol.Required("type"): "assist_pipeline/language/list",
} }
) )
@websocket_api.async_response @callback
async def websocket_list_languages( def websocket_list_languages(
hass: HomeAssistant, hass: HomeAssistant,
connection: websocket_api.connection.ActiveConnection, connection: websocket_api.connection.ActiveConnection,
msg: dict[str, Any], msg: dict[str, Any],
@ -389,7 +389,7 @@ async def websocket_list_languages(
This will return a list of languages which are supported by at least one stt, tts This will return a list of languages which are supported by at least one stt, tts
and conversation engine respectively. and conversation engine respectively.
""" """
conv_language_tags = await conversation.async_get_conversation_languages(hass) conv_language_tags = conversation.async_get_conversation_languages(hass)
stt_language_tags = stt.async_get_speech_to_text_languages(hass) stt_language_tags = stt.async_get_speech_to_text_languages(hass)
tts_language_tags = tts.async_get_text_to_speech_languages(hass) tts_language_tags = tts.async_get_text_to_speech_languages(hass)
pipeline_languages: set[str] | None = None pipeline_languages: set[str] | None = None

View file

@ -118,7 +118,8 @@ def async_unset_agent(
get_agent_manager(hass).async_unset_agent(config_entry.entry_id) get_agent_manager(hass).async_unset_agent(config_entry.entry_id)
async def async_get_conversation_languages( @callback
def async_get_conversation_languages(
hass: HomeAssistant, agent_id: str | None = None hass: HomeAssistant, agent_id: str | None = None
) -> set[str] | Literal["*"]: ) -> set[str] | Literal["*"]:
"""Return languages supported by conversation agents. """Return languages supported by conversation agents.