Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Select platform for the Flipr's Hub."""
2 
3 import logging
4 
5 from homeassistant.components.select import SelectEntity, SelectEntityDescription
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 
9 from . import FliprConfigEntry
10 from .entity import FliprEntity
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 SELECT_TYPES: tuple[SelectEntityDescription, ...] = (
16  key="hubMode",
17  translation_key="hub_mode",
18  options=["auto", "manual", "planning"],
19  ),
20 )
21 
22 
24  hass: HomeAssistant,
25  config_entry: FliprConfigEntry,
26  async_add_entities: AddEntitiesCallback,
27 ) -> None:
28  """Set up select for Flipr hub mode."""
29  coordinators = config_entry.runtime_data.hub_coordinators
30 
32  FliprHubSelect(coordinator, description, True)
33  for description in SELECT_TYPES
34  for coordinator in coordinators
35  )
36 
37 
39  """Select representing Hub mode."""
40 
41  @property
42  def current_option(self) -> str | None:
43  """Return current select option."""
44  _LOGGER.debug("coordinator data = %s", self.coordinator.data)
45  return self.coordinator.data["mode"]
46 
47  async def async_select_option(self, option: str) -> None:
48  """Select new mode for Hub."""
49  _LOGGER.debug("Changing mode of %s to %s", self.device_iddevice_iddevice_id, option)
50  data = await self.hasshasshass.async_add_executor_job(
51  self.coordinator.client.set_hub_mode,
52  self.device_iddevice_iddevice_id,
53  option,
54  )
55  _LOGGER.debug("New hub infos are %s", data)
56  self.coordinator.async_set_updated_data(data)
None async_setup_entry(HomeAssistant hass, FliprConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: select.py:27