Files
core/homeassistant/components/homee/select.py
Markus Adrario eaad8ec49d Add Homee select platform (#139534)
* homee select initial

* Finish select tests

* Add motor rotation

* fix snapshot after translation compilation

* string improvement

* last fixes

* fix review comments

* remove restore last known state

* readd wind monitoring state

* fix strings

* remove problematic selects

* remove motor rotation from strings

* fix review comments

* Update tests/components/homee/test_select.py

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>

* add PARALLEL_UPDATES

* parallel updates for select, not light.

---------

Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
2025-03-06 18:56:17 +00:00

64 lines
2.0 KiB
Python

"""The Homee select platform."""
from pyHomee.const import AttributeType
from pyHomee.model import HomeeAttribute
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import HomeeConfigEntry
from .entity import HomeeEntity
PARALLEL_UPDATES = 0
SELECT_DESCRIPTIONS: dict[AttributeType, SelectEntityDescription] = {
AttributeType.REPEATER_MODE: SelectEntityDescription(
key="repeater_mode",
options=["off", "level1", "level2"],
entity_category=EntityCategory.CONFIG,
),
}
async def async_setup_entry(
hass: HomeAssistant,
config_entry: HomeeConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Add the Homee platform for the select component."""
async_add_entities(
HomeeSelect(attribute, config_entry, SELECT_DESCRIPTIONS[attribute.type])
for node in config_entry.runtime_data.nodes
for attribute in node.attributes
if attribute.type in SELECT_DESCRIPTIONS and attribute.editable
)
class HomeeSelect(HomeeEntity, SelectEntity):
"""Representation of a Homee select entity."""
def __init__(
self,
attribute: HomeeAttribute,
entry: HomeeConfigEntry,
description: SelectEntityDescription,
) -> None:
"""Initialize a Homee select entity."""
super().__init__(attribute, entry)
self.entity_description = description
assert description.options is not None
self._attr_options = description.options
self._attr_translation_key = description.key
@property
def current_option(self) -> str:
"""Return the current selected option."""
return self.options[int(self._attribute.current_value)]
async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
await self.async_set_homee_value(self.options.index(option))