Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Select for Yale Alarm."""
2 
3 from __future__ import annotations
4 
5 from yalesmartalarmclient import YaleLock, YaleLockVolume
6 
7 from homeassistant.components.select import SelectEntity
8 from homeassistant.core import HomeAssistant, callback
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 
11 from . import YaleConfigEntry
12 from .coordinator import YaleDataUpdateCoordinator
13 from .entity import YaleLockEntity
14 
15 VOLUME_OPTIONS = {value.name.lower(): str(value.value) for value in YaleLockVolume}
16 
17 
19  hass: HomeAssistant, entry: YaleConfigEntry, async_add_entities: AddEntitiesCallback
20 ) -> None:
21  """Set up the Yale select entry."""
22 
23  coordinator = entry.runtime_data
24 
26  YaleLockVolumeSelect(coordinator, lock)
27  for lock in coordinator.locks
28  if lock.supports_lock_config()
29  )
30 
31 
33  """Representation of a Yale lock volume select."""
34 
35  _attr_translation_key = "volume"
36 
37  def __init__(self, coordinator: YaleDataUpdateCoordinator, lock: YaleLock) -> None:
38  """Initialize the Yale volume select."""
39  super().__init__(coordinator, lock)
40  self._attr_unique_id_attr_unique_id = f"{lock.sid()}-volume"
41  self._attr_current_option_attr_current_option = self.lock_datalock_data.volume().name.lower()
42  self._attr_options_attr_options = [volume.name.lower() for volume in YaleLockVolume]
43 
44  async def async_select_option(self, option: str) -> None:
45  """Change the selected option."""
46  convert_to_value = VOLUME_OPTIONS[option]
47  option_enum = YaleLockVolume(convert_to_value)
48  if await self.hasshasshass.async_add_executor_job(
49  self.lock_datalock_data.set_volume, option_enum
50  ):
51  self._attr_current_option_attr_current_option = self.lock_datalock_data.volume().name.lower()
52  self.async_write_ha_stateasync_write_ha_state()
53 
54  @callback
55  def _handle_coordinator_update(self) -> None:
56  """Handle updated data from the coordinator."""
57  self._attr_current_option_attr_current_option = self.lock_datalock_data.volume().name.lower()
None __init__(self, YaleDataUpdateCoordinator coordinator, YaleLock lock)
Definition: select.py:37
None async_setup_entry(HomeAssistant hass, YaleConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: select.py:20