Add API to fetch Assist devices (#107333)
* Add API to fetch Assist devices * Revert some changes to fixture, make a single fixture for an Assist device
This commit is contained in:
parent
6201e81eca
commit
f1d2868fd0
9 changed files with 166 additions and 23 deletions
|
@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers import collection, entity_registry as er, restore_state
|
||||
|
||||
from .const import DOMAIN
|
||||
from .pipeline import PipelineData, PipelineStorageCollection
|
||||
from .pipeline import AssistDevice, PipelineData, PipelineStorageCollection
|
||||
from .vad import VadSensitivity
|
||||
|
||||
OPTION_PREFERRED = "preferred"
|
||||
|
@ -70,8 +70,10 @@ class AssistPipelineSelect(SelectEntity, restore_state.RestoreEntity):
|
|||
_attr_current_option = OPTION_PREFERRED
|
||||
_attr_options = [OPTION_PREFERRED]
|
||||
|
||||
def __init__(self, hass: HomeAssistant, unique_id_prefix: str) -> None:
|
||||
def __init__(self, hass: HomeAssistant, domain: str, unique_id_prefix: str) -> None:
|
||||
"""Initialize a pipeline selector."""
|
||||
self._domain = domain
|
||||
self._unique_id_prefix = unique_id_prefix
|
||||
self._attr_unique_id = f"{unique_id_prefix}-pipeline"
|
||||
self.hass = hass
|
||||
self._update_options()
|
||||
|
@ -91,11 +93,16 @@ class AssistPipelineSelect(SelectEntity, restore_state.RestoreEntity):
|
|||
self._attr_current_option = state.state
|
||||
|
||||
if self.registry_entry and (device_id := self.registry_entry.device_id):
|
||||
pipeline_data.pipeline_devices.add(device_id)
|
||||
self.async_on_remove(
|
||||
lambda: pipeline_data.pipeline_devices.discard(device_id)
|
||||
pipeline_data.pipeline_devices[device_id] = AssistDevice(
|
||||
self._domain, self._unique_id_prefix
|
||||
)
|
||||
|
||||
def cleanup() -> None:
|
||||
"""Clean up registered device."""
|
||||
pipeline_data.pipeline_devices.pop(device_id)
|
||||
|
||||
self.async_on_remove(cleanup)
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Select an option."""
|
||||
self._attr_current_option = option
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue