1 """Support for LaMetric selects."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from demetriek
import BrightnessMode, Device, LaMetricDevice
17 from .const
import DOMAIN
18 from .coordinator
import LaMetricDataUpdateCoordinator
19 from .entity
import LaMetricEntity
20 from .helpers
import lametric_exception_handler
23 @dataclass(frozen=True, kw_only=True)
25 """Class describing LaMetric select entities."""
27 current_fn: Callable[[Device], str]
28 select_fn: Callable[[LaMetricDevice, str], Awaitable[Any]]
33 key=
"brightness_mode",
34 translation_key=
"brightness_mode",
35 entity_category=EntityCategory.CONFIG,
36 options=[
"auto",
"manual"],
37 current_fn=
lambda device: device.display.brightness_mode.value,
38 select_fn=
lambda api, opt: api.display(brightness_mode=BrightnessMode(opt)),
46 async_add_entities: AddEntitiesCallback,
48 """Set up LaMetric select based on a config entry."""
49 coordinator: LaMetricDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
52 coordinator=coordinator,
53 description=description,
55 for description
in SELECTS
60 """Representation of a LaMetric select."""
62 entity_description: LaMetricSelectEntityDescription
66 coordinator: LaMetricDataUpdateCoordinator,
67 description: LaMetricSelectEntityDescription,
69 """Initiate LaMetric Select."""
72 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.data.serial_number}-{description.key}"
76 """Return the selected entity option to represent the entity state."""
79 @lametric_exception_handler
81 """Change the selected option."""
82 await self.
entity_descriptionentity_description.select_fn(self.coordinator.lametric, option)
None async_select_option(self, str option)
None __init__(self, LaMetricDataUpdateCoordinator coordinator, LaMetricSelectEntityDescription description)
str|None current_option(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)