mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Use the preferred assist pipeline if none was specified (#91611)
* Use the preferred assist pipeline if none was specified * Add test
This commit is contained in:
parent
016e051db6
commit
10606c4d1e
@ -58,10 +58,13 @@ async def async_get_pipeline(
|
|||||||
"""Get a pipeline by id or create one for a language."""
|
"""Get a pipeline by id or create one for a language."""
|
||||||
pipeline_data: PipelineData = hass.data[DOMAIN]
|
pipeline_data: PipelineData = hass.data[DOMAIN]
|
||||||
|
|
||||||
if pipeline_id is not None:
|
if pipeline_id is None:
|
||||||
return pipeline_data.pipeline_store.data.get(pipeline_id)
|
# A pipeline was not specified, use the preferred one
|
||||||
|
pipeline_id = pipeline_data.pipeline_store.async_get_preferred_item()
|
||||||
|
|
||||||
# Construct a pipeline for the required/configured language
|
if pipeline_id is None:
|
||||||
|
# There's no preferred pipeline, construct a pipeline for the
|
||||||
|
# required/configured language
|
||||||
language = language or hass.config.language
|
language = language or hass.config.language
|
||||||
return await pipeline_data.pipeline_store.async_create_item(
|
return await pipeline_data.pipeline_store.async_create_item(
|
||||||
{
|
{
|
||||||
@ -73,6 +76,8 @@ async def async_get_pipeline(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return pipeline_data.pipeline_store.data.get(pipeline_id)
|
||||||
|
|
||||||
|
|
||||||
class PipelineEventType(StrEnum):
|
class PipelineEventType(StrEnum):
|
||||||
"""Event types emitted during a pipeline run."""
|
"""Event types emitted during a pipeline run."""
|
||||||
|
@ -7,6 +7,7 @@ from homeassistant.components.assist_pipeline.pipeline import (
|
|||||||
STORAGE_VERSION,
|
STORAGE_VERSION,
|
||||||
PipelineData,
|
PipelineData,
|
||||||
PipelineStorageCollection,
|
PipelineStorageCollection,
|
||||||
|
async_get_pipeline,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.storage import Store
|
from homeassistant.helpers.storage import Store
|
||||||
@ -109,3 +110,24 @@ async def test_loading_datasets_from_storage(
|
|||||||
store = pipeline_data.pipeline_store
|
store = pipeline_data.pipeline_store
|
||||||
assert len(store.data) == 3
|
assert len(store.data) == 3
|
||||||
assert store.async_get_preferred_item() == "01GX8ZWBAQYWNB1XV3EXEZ75DY"
|
assert store.async_get_preferred_item() == "01GX8ZWBAQYWNB1XV3EXEZ75DY"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_pipeline(hass: HomeAssistant) -> None:
|
||||||
|
"""Test async_get_pipeline."""
|
||||||
|
assert await async_setup_component(hass, "assist_pipeline", {})
|
||||||
|
|
||||||
|
pipeline_data: PipelineData = hass.data[DOMAIN]
|
||||||
|
store = pipeline_data.pipeline_store
|
||||||
|
assert len(store.data) == 0
|
||||||
|
|
||||||
|
# Test a pipeline is created
|
||||||
|
pipeline = await async_get_pipeline(hass, None)
|
||||||
|
assert len(store.data) == 1
|
||||||
|
|
||||||
|
# Test we get the same pipeline again
|
||||||
|
assert pipeline is await async_get_pipeline(hass, None)
|
||||||
|
assert len(store.data) == 1
|
||||||
|
|
||||||
|
# Test getting a specific pipeline
|
||||||
|
assert pipeline is await async_get_pipeline(hass, pipeline.id)
|
||||||
|
assert len(store.data) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user