1 """Support for RainMachine selects."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from regenmaschine.errors
import RainMachineError
17 from .
import RainMachineConfigEntry, RainMachineData
18 from .const
import DATA_RESTRICTIONS_UNIVERSAL
19 from .entity
import RainMachineEntity, RainMachineEntityDescription
20 from .util
import key_exists
23 @dataclass(frozen=True, kw_only=True)
25 SelectEntityDescription, RainMachineEntityDescription
27 """Describe a generic RainMachine select."""
34 """Define an option for a freeze selection select."""
41 @dataclass(frozen=True, kw_only=True)
43 """Describe a freeze protection temperature select."""
45 extended_options: list[FreezeProtectionSelectOption]
48 TYPE_FREEZE_PROTECTION_TEMPERATURE =
"freeze_protection_temperature"
50 SELECT_DESCRIPTIONS = (
52 key=TYPE_FREEZE_PROTECTION_TEMPERATURE,
53 translation_key=TYPE_FREEZE_PROTECTION_TEMPERATURE,
54 entity_category=EntityCategory.CONFIG,
55 api_category=DATA_RESTRICTIONS_UNIVERSAL,
56 data_key=
"freezeProtectTemp",
60 imperial_label=
"32°F",
65 imperial_label=
"35.6°F",
70 imperial_label=
"41°F",
75 imperial_label=
"50°F",
85 entry: RainMachineConfigEntry,
86 async_add_entities: AddEntitiesCallback,
88 """Set up RainMachine selects based on a config entry."""
89 data = entry.runtime_data
92 TYPE_FREEZE_PROTECTION_TEMPERATURE: FreezeProtectionTemperatureSelect,
96 entity_map[description.key](entry, data, description, hass.config.units)
97 for description
in SELECT_DESCRIPTIONS
99 (coordinator := data.coordinators[description.api_category])
is not None
101 and key_exists(coordinator.data, description.data_key)
107 """Define a RainMachine select."""
109 entity_description: FreezeProtectionSelectDescription
114 data: RainMachineData,
115 description: FreezeProtectionSelectDescription,
116 unit_system: UnitSystem,
119 super().
__init__(entry, data, description)
124 for option
in description.extended_options:
125 if unit_system
is US_CUSTOMARY_SYSTEM:
126 label = option.imperial_label
128 label = option.metric_label
135 """Change the selected option."""
137 await self.
_data_data.controller.restrictions.set_universal(
140 except RainMachineError
as err:
145 """Update the entity when new data is received."""
None update_from_latest_data(self)
None __init__(self, ConfigEntry entry, RainMachineData data, FreezeProtectionSelectDescription description, UnitSystem unit_system)
None async_select_option(self, str option)
None async_setup_entry(HomeAssistant hass, RainMachineConfigEntry entry, AddEntitiesCallback async_add_entities)
bool key_exists(dict[str, Any] data, str search_key)