Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Demo platform that offers a fake select entity."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.select import SelectEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.device_registry import DeviceInfo
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 
11 from . import DOMAIN
12 
13 
15  hass: HomeAssistant,
16  config_entry: ConfigEntry,
17  async_add_entities: AddEntitiesCallback,
18 ) -> None:
19  """Set up the demo select platform."""
21  [
22  DemoSelect(
23  unique_id="speed",
24  device_name="Speed",
25  current_option="ridiculous_speed",
26  options=[
27  "light_speed",
28  "ridiculous_speed",
29  "ludicrous_speed",
30  ],
31  translation_key="speed",
32  ),
33  ]
34  )
35 
36 
38  """Representation of a demo select entity."""
39 
40  _attr_has_entity_name = True
41  _attr_name = None
42  _attr_should_poll = False
43 
44  def __init__(
45  self,
46  unique_id: str,
47  device_name: str,
48  current_option: str | None,
49  options: list[str],
50  translation_key: str,
51  ) -> None:
52  """Initialize the Demo select entity."""
53  self._attr_unique_id_attr_unique_id = unique_id
54  self._attr_current_option_attr_current_option = current_option
55  self._attr_options_attr_options = options
56  self._attr_translation_key_attr_translation_key = translation_key
57  self._attr_device_info_attr_device_info = DeviceInfo(
58  identifiers={(DOMAIN, unique_id)},
59  name=device_name,
60  )
61 
62  async def async_select_option(self, option: str) -> None:
63  """Update the current selected option."""
64  self._attr_current_option_attr_current_option = option
65  self.async_write_ha_stateasync_write_ha_state()
None __init__(self, str unique_id, str device_name, str|None current_option, list[str] options, str translation_key)
Definition: select.py:51
None async_select_option(self, str option)
Definition: select.py:62
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: select.py:18