1 """Select entities for a pipeline."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
12 from .const
import DOMAIN, OPTION_PREFERRED
13 from .pipeline
import AssistDevice, PipelineData, PipelineStorageCollection
14 from .vad
import VadSensitivity
19 hass: HomeAssistant, domain: str, unique_id_prefix: str
21 """Get the chosen pipeline for a domain."""
22 ent_reg = er.async_get(hass)
23 pipeline_entity_id = ent_reg.async_get_entity_id(
24 Platform.SELECT, domain, f
"{unique_id_prefix}-pipeline"
26 if pipeline_entity_id
is None:
29 state = hass.states.get(pipeline_entity_id)
30 if state
is None or state.state == OPTION_PREFERRED:
33 pipeline_store: PipelineStorageCollection = hass.data[DOMAIN].pipeline_store
35 (item.id
for item
in pipeline_store.async_items()
if item.name == state.state),
42 hass: HomeAssistant, domain: str, unique_id_prefix: str
44 """Get the chosen vad sensitivity for a domain."""
45 ent_reg = er.async_get(hass)
46 sensitivity_entity_id = ent_reg.async_get_entity_id(
47 Platform.SELECT, domain, f
"{unique_id_prefix}-vad_sensitivity"
49 if sensitivity_entity_id
is None:
50 return VadSensitivity.DEFAULT
52 state = hass.states.get(sensitivity_entity_id)
54 return VadSensitivity.DEFAULT
60 """Entity to represent a pipeline selector."""
64 translation_key=
"pipeline",
65 entity_category=EntityCategory.CONFIG,
67 _attr_should_poll =
False
68 _attr_current_option = OPTION_PREFERRED
69 _attr_options = [OPTION_PREFERRED]
71 def __init__(self, hass: HomeAssistant, domain: str, unique_id_prefix: str) ->
None:
72 """Initialize a pipeline selector."""
80 """When entity is added to Home Assistant."""
83 pipeline_data: PipelineData = self.
hasshasshass.data[DOMAIN]
84 pipeline_store = pipeline_data.pipeline_store
86 pipeline_store.async_add_change_set_listener(self.
_pipelines_updated_pipelines_updated)
89 state = await self.async_get_last_state()
90 if state
is not None and state.state
in self.
optionsoptions:
94 pipeline_data.pipeline_devices[device_id] =
AssistDevice(
98 def cleanup() -> None:
99 """Clean up registered device."""
100 pipeline_data.pipeline_devices.pop(device_id)
105 """Select an option."""
110 self, change_set: Iterable[collection.CollectionChange]
112 """Handle pipeline update."""
118 """Handle pipeline update."""
119 pipeline_store: PipelineStorageCollection = self.
hasshasshass.data[
122 options = [OPTION_PREFERRED]
123 options.extend(sorted(item.name
for item
in pipeline_store.async_items()))
131 """Entity to represent VAD sensitivity."""
134 key=
"vad_sensitivity",
135 translation_key=
"vad_sensitivity",
136 entity_category=EntityCategory.CONFIG,
138 _attr_should_poll =
False
139 _attr_current_option = VadSensitivity.DEFAULT.value
140 _attr_options = [vs.value
for vs
in VadSensitivity]
142 def __init__(self, hass: HomeAssistant, unique_id_prefix: str) ->
None:
143 """Initialize a pipeline selector."""
148 """When entity is added to Home Assistant."""
151 state = await self.async_get_last_state()
152 if state
is not None and state.state
in self.
optionsoptions:
156 """Select an option."""
None _pipelines_updated(self, Iterable[collection.CollectionChange] change_set)
None async_added_to_hass(self)
None __init__(self, HomeAssistant hass, str domain, str unique_id_prefix)
None async_select_option(self, str option)
None _update_options(self)
None async_select_option(self, str option)
None async_added_to_hass(self)
None __init__(self, HomeAssistant hass, str unique_id_prefix)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
VadSensitivity get_vad_sensitivity(HomeAssistant hass, str domain, str unique_id_prefix)
str|None get_chosen_pipeline(HomeAssistant hass, str domain, str unique_id_prefix)