Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Support for Velbus select."""
2 
3 from velbusaio.channels import SelectedProgram
4 
5 from homeassistant.components.select import SelectEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.const import EntityCategory
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 
11 from .const import DOMAIN
12 from .entity import VelbusEntity, api_call
13 
14 
16  hass: HomeAssistant,
17  entry: ConfigEntry,
18  async_add_entities: AddEntitiesCallback,
19 ) -> None:
20  """Set up Velbus select based on config_entry."""
21  await hass.data[DOMAIN][entry.entry_id]["tsk"]
22  cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
23  async_add_entities(VelbusSelect(channel) for channel in cntrl.get_all("select"))
24 
25 
27  """Representation of a select option for velbus."""
28 
29  _channel: SelectedProgram
30  _attr_entity_category = EntityCategory.CONFIG
31 
32  def __init__(
33  self,
34  channel: SelectedProgram,
35  ) -> None:
36  """Initialize a select Velbus entity."""
37  super().__init__(channel)
38  self._attr_options_attr_options = self._channel_channel.get_options()
39  self._attr_unique_id_attr_unique_id_attr_unique_id = f"{self._attr_unique_id}-program_select"
40 
41  @api_call
42  async def async_select_option(self, option: str) -> None:
43  """Update the program on the module."""
44  await self._channel_channel.set_selected_program(option)
45 
46  @property
47  def current_option(self) -> str:
48  """Return the selected option."""
49  return self._channel_channel.get_selected_program()
None __init__(self, SelectedProgram channel)
Definition: select.py:35
list[dict[str, Any]] get_options(list[dict[str, Any]] feeds)
Definition: config_flow.py:34
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: select.py:19