mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add options to SelectEntityDescription (#78882)
This commit is contained in:
parent
f8f4b059a1
commit
ca9bfc8b86
@ -23,7 +23,6 @@ class PlenticoreRequiredKeysMixin:
|
|||||||
"""A class that describes required properties for plenticore select entities."""
|
"""A class that describes required properties for plenticore select entities."""
|
||||||
|
|
||||||
module_id: str
|
module_id: str
|
||||||
options: list[str]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -65,6 +64,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for description in SELECT_SETTINGS_DATA:
|
for description in SELECT_SETTINGS_DATA:
|
||||||
|
assert description.options is not None
|
||||||
if description.module_id not in available_settings_data:
|
if description.module_id not in available_settings_data:
|
||||||
continue
|
continue
|
||||||
needed_data_ids = {
|
needed_data_ids = {
|
||||||
@ -109,7 +109,6 @@ class PlenticoreDataSelect(CoordinatorEntity, SelectEntity):
|
|||||||
self.platform_name = platform_name
|
self.platform_name = platform_name
|
||||||
self.module_id = description.module_id
|
self.module_id = description.module_id
|
||||||
self.data_id = description.key
|
self.data_id = description.key
|
||||||
self._attr_options = description.options
|
|
||||||
self._device_info = device_info
|
self._device_info = device_info
|
||||||
self._attr_unique_id = f"{entry_id}_{description.module_id}"
|
self._attr_unique_id = f"{entry_id}_{description.module_id}"
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ from .entity import LaMetricEntity
|
|||||||
class LaMetricEntityDescriptionMixin:
|
class LaMetricEntityDescriptionMixin:
|
||||||
"""Mixin values for LaMetric entities."""
|
"""Mixin values for LaMetric entities."""
|
||||||
|
|
||||||
options: list[str]
|
|
||||||
current_fn: Callable[[Device], str]
|
current_fn: Callable[[Device], str]
|
||||||
select_fn: Callable[[LaMetricDevice, str], Awaitable[Any]]
|
select_fn: Callable[[LaMetricDevice, str], Awaitable[Any]]
|
||||||
|
|
||||||
@ -77,7 +76,6 @@ class LaMetricSelectEntity(LaMetricEntity, SelectEntity):
|
|||||||
"""Initiate LaMetric Select."""
|
"""Initiate LaMetric Select."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_options = description.options
|
|
||||||
self._attr_unique_id = f"{coordinator.data.serial_number}-{description.key}"
|
self._attr_unique_id = f"{coordinator.data.serial_number}-{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -21,7 +21,6 @@ from .entity import OverkizDescriptiveEntity, OverkizDeviceClass
|
|||||||
class OverkizSelectDescriptionMixin:
|
class OverkizSelectDescriptionMixin:
|
||||||
"""Define an entity description mixin for select entities."""
|
"""Define an entity description mixin for select entities."""
|
||||||
|
|
||||||
options: list[str | OverkizCommandParam]
|
|
||||||
select_option: Callable[[str, Callable[..., Awaitable[None]]], Awaitable[None]]
|
select_option: Callable[[str, Callable[..., Awaitable[None]]], Awaitable[None]]
|
||||||
|
|
||||||
|
|
||||||
@ -149,11 +148,6 @@ class OverkizSelect(OverkizDescriptiveEntity, SelectEntity):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def options(self) -> list[str]:
|
|
||||||
"""Return a set of selectable options."""
|
|
||||||
return self.entity_description.options
|
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Change the selected option."""
|
"""Change the selected option."""
|
||||||
await self.entity_description.select_option(
|
await self.entity_description.select_option(
|
||||||
|
@ -24,7 +24,6 @@ class RenaultSelectRequiredKeysMixin:
|
|||||||
|
|
||||||
data_key: str
|
data_key: str
|
||||||
icon_lambda: Callable[[RenaultSelectEntity], str]
|
icon_lambda: Callable[[RenaultSelectEntity], str]
|
||||||
options: list[str]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -74,11 +73,6 @@ class RenaultSelectEntity(
|
|||||||
"""Icon handling."""
|
"""Icon handling."""
|
||||||
return self.entity_description.icon_lambda(self)
|
return self.entity_description.icon_lambda(self)
|
||||||
|
|
||||||
@property
|
|
||||||
def options(self) -> list[str]:
|
|
||||||
"""Return a set of selectable options."""
|
|
||||||
return self.entity_description.options
|
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Change the selected option."""
|
"""Change the selected option."""
|
||||||
await self.vehicle.vehicle.set_charge_mode(option)
|
await self.vehicle.vehicle.set_charge_mode(option)
|
||||||
|
@ -72,6 +72,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
class SelectEntityDescription(EntityDescription):
|
class SelectEntityDescription(EntityDescription):
|
||||||
"""A class that describes select entities."""
|
"""A class that describes select entities."""
|
||||||
|
|
||||||
|
options: list[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
class SelectEntity(Entity):
|
class SelectEntity(Entity):
|
||||||
"""Representation of a Select entity."""
|
"""Representation of a Select entity."""
|
||||||
@ -99,7 +101,14 @@ class SelectEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def options(self) -> list[str]:
|
def options(self) -> list[str]:
|
||||||
"""Return a set of selectable options."""
|
"""Return a set of selectable options."""
|
||||||
|
if hasattr(self, "_attr_options"):
|
||||||
return self._attr_options
|
return self._attr_options
|
||||||
|
if (
|
||||||
|
hasattr(self, "entity_description")
|
||||||
|
and self.entity_description.options is not None
|
||||||
|
):
|
||||||
|
return self.entity_description.options
|
||||||
|
raise AttributeError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_option(self) -> str | None:
|
def current_option(self) -> str | None:
|
||||||
|
@ -74,7 +74,6 @@ class XiaomiMiioSelectDescription(SelectEntityDescription):
|
|||||||
options_map: dict = field(default_factory=dict)
|
options_map: dict = field(default_factory=dict)
|
||||||
set_method: str = ""
|
set_method: str = ""
|
||||||
set_method_error_message: str = ""
|
set_method_error_message: str = ""
|
||||||
options: tuple = ()
|
|
||||||
|
|
||||||
|
|
||||||
class AttributeEnumMapping(NamedTuple):
|
class AttributeEnumMapping(NamedTuple):
|
||||||
@ -150,7 +149,7 @@ SELECTOR_TYPES = (
|
|||||||
set_method_error_message="Setting the display orientation failed.",
|
set_method_error_message="Setting the display orientation failed.",
|
||||||
icon="mdi:tablet",
|
icon="mdi:tablet",
|
||||||
device_class="xiaomi_miio__display_orientation",
|
device_class="xiaomi_miio__display_orientation",
|
||||||
options=("forward", "left", "right"),
|
options=["forward", "left", "right"],
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
XiaomiMiioSelectDescription(
|
XiaomiMiioSelectDescription(
|
||||||
@ -161,7 +160,7 @@ SELECTOR_TYPES = (
|
|||||||
set_method_error_message="Setting the led brightness failed.",
|
set_method_error_message="Setting the led brightness failed.",
|
||||||
icon="mdi:brightness-6",
|
icon="mdi:brightness-6",
|
||||||
device_class="xiaomi_miio__led_brightness",
|
device_class="xiaomi_miio__led_brightness",
|
||||||
options=("bright", "dim", "off"),
|
options=["bright", "dim", "off"],
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
XiaomiMiioSelectDescription(
|
XiaomiMiioSelectDescription(
|
||||||
@ -172,7 +171,7 @@ SELECTOR_TYPES = (
|
|||||||
set_method_error_message="Setting the ptc level failed.",
|
set_method_error_message="Setting the ptc level failed.",
|
||||||
icon="mdi:fire-circle",
|
icon="mdi:fire-circle",
|
||||||
device_class="xiaomi_miio__ptc_level",
|
device_class="xiaomi_miio__ptc_level",
|
||||||
options=("low", "medium", "high"),
|
options=["low", "medium", "high"],
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -220,7 +219,6 @@ class XiaomiSelector(XiaomiCoordinatedMiioEntity, SelectEntity):
|
|||||||
def __init__(self, device, entry, unique_id, coordinator, description):
|
def __init__(self, device, entry, unique_id, coordinator, description):
|
||||||
"""Initialize the generic Xiaomi attribute selector."""
|
"""Initialize the generic Xiaomi attribute selector."""
|
||||||
super().__init__(device, entry, unique_id, coordinator)
|
super().__init__(device, entry, unique_id, coordinator)
|
||||||
self._attr_options = list(description.options)
|
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user