1 """Support for esphome selects."""
3 from __future__
import annotations
5 from aioesphomeapi
import EntityInfo, SelectInfo, SelectState
18 from .const
import DOMAIN
22 convert_api_error_ha_error,
23 esphome_state_property,
24 platform_async_setup_entry,
26 from .entry_data
import ESPHomeConfigEntry, RuntimeEntryData
31 entry: ESPHomeConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Set up esphome selects based on a config entry."""
40 entity_type=EsphomeSelect,
41 state_type=SelectState,
44 entry_data = entry.runtime_data
45 assert entry_data.device_info
is not None
46 if entry_data.device_info.voice_assistant_feature_flags_compat(
47 entry_data.api_version
59 """A select implementation for esphome."""
63 """Set attrs from static info."""
68 @esphome_state_property
70 """Return the state of the entity."""
72 return None if state.missing_state
else state.state
74 @convert_api_error_ha_error
76 """Change the selected option."""
77 self.
_client_client.select_command(self.
_key_key, option)
81 """Pipeline selector for esphome devices."""
83 def __init__(self, hass: HomeAssistant, entry_data: RuntimeEntryData) ->
None:
84 """Initialize a pipeline selector."""
85 EsphomeAssistEntity.__init__(self, entry_data)
86 AssistPipelineSelect.__init__(self, hass, DOMAIN, self.
_device_info_device_info.mac_address)
90 """VAD sensitivity selector for ESPHome devices."""
92 def __init__(self, hass: HomeAssistant, entry_data: RuntimeEntryData) ->
None:
93 """Initialize a VAD sensitivity selector."""
94 EsphomeAssistEntity.__init__(self, entry_data)
95 VadSensitivitySelect.__init__(self, hass, self.
_device_info_device_info.mac_address)
99 EsphomeAssistEntity, SelectEntity, restore_state.RestoreEntity
101 """Wake word selector for esphome devices."""
105 translation_key=
"wake_word",
106 entity_category=EntityCategory.CONFIG,
108 _attr_should_poll =
False
109 _attr_current_option: str |
None =
None
110 _attr_options: list[str] = []
112 def __init__(self, hass: HomeAssistant, entry_data: RuntimeEntryData) ->
None:
113 """Initialize a wake word selector."""
114 EsphomeAssistEntity.__init__(self, entry_data)
116 unique_id_prefix = self.
_device_info_device_info.mac_address
124 """Return if entity is available."""
128 """Run when entity about to be added to hass."""
133 self._entry_data.async_register_assist_satellite_config_updated_callback(
139 """Select an option."""
144 self._entry_data.async_assist_satellite_set_wake_word(wake_word_id)
147 self, config: AssistSatelliteConfiguration
149 """Update options with available wake words."""
150 if (
not config.available_wake_words)
or (config.max_active_wake_words < 1):
156 self.
_wake_words_wake_words = {w.wake_word: w.id
for w
in config.available_wake_words}
159 if config.active_wake_words:
161 wake_word_id = config.active_wake_words[0]
162 for wake_word
in config.available_wake_words:
163 if wake_word.id == wake_word_id:
None __init__(self, HomeAssistant hass, RuntimeEntryData entry_data)
None async_added_to_hass(self)
None __init__(self, HomeAssistant hass, RuntimeEntryData entry_data)
None async_satellite_config_updated(self, AssistSatelliteConfiguration config)
None async_select_option(self, str option)
None async_select_option(self, str option)
None _on_static_info_update(self, EntityInfo static_info)
str|None current_option(self)
None __init__(self, HomeAssistant hass, RuntimeEntryData entry_data)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
web.Response get(self, web.Request request, str config_key)
None platform_async_setup_entry(HomeAssistant hass, ESPHomeConfigEntry entry, AddEntitiesCallback async_add_entities, *type[_InfoT] info_type, type[_EntityT] entity_type, type[_StateT] state_type)
None async_setup_entry(HomeAssistant hass, ESPHomeConfigEntry entry, AddEntitiesCallback async_add_entities)