1 """Support for DROP selects."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
15 from .const
import CONF_DEVICE_TYPE, DEV_HUB, DOMAIN
16 from .coordinator
import DROPDeviceDataUpdateCoordinator
17 from .entity
import DROPEntity
19 _LOGGER = logging.getLogger(__name__)
22 PROTECT_MODE =
"protect_mode"
24 PROTECT_MODE_OPTIONS = [
"away",
"home",
"schedule"]
27 @dataclass(kw_only=True, frozen=True)
29 """Describes DROP select entity."""
31 value_fn: Callable[[DROPDeviceDataUpdateCoordinator], int |
None]
32 set_fn: Callable[[DROPDeviceDataUpdateCoordinator, str], Awaitable[Any]]
35 SELECTS: list[DROPSelectEntityDescription] = [
38 translation_key=PROTECT_MODE,
39 options=PROTECT_MODE_OPTIONS,
40 value_fn=
lambda device: device.drop_api.protect_mode(),
41 set_fn=
lambda device, value: device.set_protect_mode(value),
46 DEVICE_SELECTS: dict[str, list[str]] = {
47 DEV_HUB: [PROTECT_MODE],
53 config_entry: ConfigEntry,
54 async_add_entities: AddEntitiesCallback,
56 """Set up the DROP selects from config entry."""
58 "Set up select for device type %s with entry_id is %s",
59 config_entry.data[CONF_DEVICE_TYPE],
60 config_entry.entry_id,
63 if config_entry.data[CONF_DEVICE_TYPE]
in DEVICE_SELECTS:
65 DROPSelect(hass.data[DOMAIN][config_entry.entry_id], select)
67 if select.key
in DEVICE_SELECTS[config_entry.data[CONF_DEVICE_TYPE]]
72 """Representation of a DROP select."""
74 entity_description: DROPSelectEntityDescription
78 coordinator: DROPDeviceDataUpdateCoordinator,
79 entity_description: DROPSelectEntityDescription,
81 """Initialize the select."""
82 super().
__init__(entity_description.key, coordinator)
87 """Return the current selected option."""
89 return str(val)
if val
else None
92 """Update the current selected option."""
None async_select_option(self, str option)
None __init__(self, DROPDeviceDataUpdateCoordinator coordinator, DROPSelectEntityDescription entity_description)
str|None current_option(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)