Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Select platform for Advantage Air integration."""
2 
3 from homeassistant.components.select import SelectEntity
4 from homeassistant.core import HomeAssistant
5 from homeassistant.helpers.entity_platform import AddEntitiesCallback
6 
7 from . import AdvantageAirDataConfigEntry
8 from .entity import AdvantageAirAcEntity
9 from .models import AdvantageAirData
10 
11 ADVANTAGE_AIR_INACTIVE = "Inactive"
12 
13 
15  hass: HomeAssistant,
16  config_entry: AdvantageAirDataConfigEntry,
17  async_add_entities: AddEntitiesCallback,
18 ) -> None:
19  """Set up AdvantageAir select platform."""
20 
21  instance = config_entry.runtime_data
22 
23  if aircons := instance.coordinator.data.get("aircons"):
24  async_add_entities(AdvantageAirMyZone(instance, ac_key) for ac_key in aircons)
25 
26 
28  """Representation of Advantage Air MyZone control."""
29 
30  _attr_icon = "mdi:home-thermometer"
31  _attr_name = "MyZone"
32 
33  def __init__(self, instance: AdvantageAirData, ac_key: str) -> None:
34  """Initialize an Advantage Air MyZone control."""
35  super().__init__(instance, ac_key)
36  self._attr_unique_id += "-myzone"
37  self._attr_options_attr_options = [ADVANTAGE_AIR_INACTIVE]
38  self._number_to_name_number_to_name = {0: ADVANTAGE_AIR_INACTIVE}
39  self._name_to_number_name_to_number = {ADVANTAGE_AIR_INACTIVE: 0}
40 
41  if "aircons" in instance.coordinator.data:
42  for zone in instance.coordinator.data["aircons"][ac_key]["zones"].values():
43  if zone["type"] > 0:
44  self._name_to_number_name_to_number[zone["name"]] = zone["number"]
45  self._number_to_name_number_to_name[zone["number"]] = zone["name"]
46  self._attr_options_attr_options.append(zone["name"])
47 
48  @property
49  def current_option(self) -> str:
50  """Return the current MyZone."""
51  return self._number_to_name_number_to_name[self._ac_ac["myZone"]]
52 
53  async def async_select_option(self, option: str) -> None:
54  """Set the MyZone."""
55  await self.async_update_acasync_update_ac({"myZone": self._name_to_number_name_to_number[option]})
None __init__(self, AdvantageAirData instance, str ac_key)
Definition: select.py:33
None async_setup_entry(HomeAssistant hass, AdvantageAirDataConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: select.py:18