1 """The Aprilaire select component."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
7 from typing
import cast
9 from pyaprilaire.const
import Attribute
15 from .coordinator
import AprilaireConfigEntry, AprilaireCoordinator
16 from .entity
import BaseAprilaireEntity
18 AIR_CLEANING_EVENT_MAP = {0:
"off", 3:
"event_clean", 4:
"allergies"}
19 AIR_CLEANING_MODE_MAP = {0:
"off", 1:
"constant_clean", 2:
"automatic"}
20 FRESH_AIR_EVENT_MAP = {0:
"off", 2:
"3hour", 3:
"24hour"}
21 FRESH_AIR_MODE_MAP = {0:
"off", 1:
"automatic"}
26 config_entry: AprilaireConfigEntry,
27 async_add_entities: AddEntitiesCallback,
29 """Set up Aprilaire select devices."""
31 coordinator = config_entry.runtime_data
33 assert config_entry.unique_id
is not None
35 descriptions: list[AprilaireSelectDescription] = []
37 if coordinator.data.get(Attribute.AIR_CLEANING_AVAILABLE) == 1:
41 key=
"air_cleaning_event",
42 translation_key=
"air_cleaning_event",
43 options_map=AIR_CLEANING_EVENT_MAP,
44 event_value_key=Attribute.AIR_CLEANING_EVENT,
45 mode_value_key=Attribute.AIR_CLEANING_MODE,
47 select_option_fn=coordinator.client.set_air_cleaning,
50 key=
"air_cleaning_mode",
51 translation_key=
"air_cleaning_mode",
52 options_map=AIR_CLEANING_MODE_MAP,
53 event_value_key=Attribute.AIR_CLEANING_EVENT,
54 mode_value_key=Attribute.AIR_CLEANING_MODE,
56 select_option_fn=coordinator.client.set_air_cleaning,
61 if coordinator.data.get(Attribute.VENTILATION_AVAILABLE) == 1:
65 key=
"fresh_air_event",
66 translation_key=
"fresh_air_event",
67 options_map=FRESH_AIR_EVENT_MAP,
68 event_value_key=Attribute.FRESH_AIR_EVENT,
69 mode_value_key=Attribute.FRESH_AIR_MODE,
71 select_option_fn=coordinator.client.set_fresh_air,
75 translation_key=
"fresh_air_mode",
76 options_map=FRESH_AIR_MODE_MAP,
77 event_value_key=Attribute.FRESH_AIR_EVENT,
78 mode_value_key=Attribute.FRESH_AIR_MODE,
80 select_option_fn=coordinator.client.set_fresh_air,
87 for description
in descriptions
91 @dataclass(frozen=True, kw_only=True)
93 """Class describing Aprilaire select entities."""
95 options_map: dict[int, str]
99 select_option_fn: Callable[[int, int], Awaitable]
103 """Base select entity for Aprilaire."""
105 entity_description: AprilaireSelectDescription
109 coordinator: AprilaireCoordinator,
110 description: AprilaireSelectDescription,
113 """Initialize a select for an Aprilaire device."""
116 self.
values_mapvalues_map = {v: k
for k, v
in description.options_map.items()}
118 super().
__init__(coordinator, unique_id)
124 """Get the current option."""
131 current_value =
int(self.coordinator.data.get(value_key, 0))
133 return self.
entity_descriptionentity_description.options_map.get(current_value,
"off")
136 """Set the current option."""
139 event_value = self.
values_mapvalues_map[option]
142 int, self.coordinator.data.get(self.
entity_descriptionentity_description.mode_value_key)
145 mode_value = self.
values_mapvalues_map[option]
148 int, self.coordinator.data.get(self.
entity_descriptionentity_description.event_value_key)
151 await self.
entity_descriptionentity_description.select_option_fn(mode_value, event_value)
None __init__(self, AprilaireCoordinator coordinator, AprilaireSelectDescription description, str unique_id)
None async_select_option(self, str option)
None async_setup_entry(HomeAssistant hass, AprilaireConfigEntry config_entry, AddEntitiesCallback async_add_entities)