Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Support for Spa Client selects."""
2 
3 from pybalboa import SpaControl
4 from pybalboa.enums import LowHighRange
5 
6 from homeassistant.components.select import SelectEntity
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from . import BalboaConfigEntry
11 from .entity import BalboaEntity
12 
13 
15  hass: HomeAssistant,
16  entry: BalboaConfigEntry,
17  async_add_entities: AddEntitiesCallback,
18 ) -> None:
19  """Set up the spa select entity."""
20  spa = entry.runtime_data
21  async_add_entities([BalboaTempRangeSelectEntity(spa.temperature_range)])
22 
23 
25  """Representation of a Temperature Range select."""
26 
27  _attr_translation_key = "temperature_range"
28  _attr_options = [
29  LowHighRange.LOW.name.lower(),
30  LowHighRange.HIGH.name.lower(),
31  ]
32 
33  def __init__(self, control: SpaControl) -> None:
34  """Initialise the select."""
35  super().__init__(control.client, "TempHiLow")
36  self._control_control = control
37 
38  @property
39  def current_option(self) -> str | None:
40  """Return current select option."""
41  if self._control_control.state == LowHighRange.HIGH:
42  return LowHighRange.HIGH.name.lower()
43  return LowHighRange.LOW.name.lower()
44 
45  async def async_select_option(self, option: str) -> None:
46  """Select temperature range high/low mode."""
47  if option == LowHighRange.HIGH.name.lower():
48  await self._client_client.set_temperature_range(LowHighRange.HIGH)
49  else:
50  await self._client_client.set_temperature_range(LowHighRange.LOW)
None async_setup_entry(HomeAssistant hass, BalboaConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: select.py:18