Add support for select entities in velbus (#87568)

* Add support for select entities in velbus

* Implement comments

* EntityCategory is now in homeassistant.const

* more comments
This commit is contained in:
Maikel Punie 2023-03-28 14:01:31 +02:00 committed by GitHub
parent 7b18df321b
commit 0eb409cff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 0 deletions

View file

@ -1368,6 +1368,7 @@ omit =
homeassistant/components/velbus/entity.py
homeassistant/components/velbus/light.py
homeassistant/components/velbus/sensor.py
homeassistant/components/velbus/select.py
homeassistant/components/velbus/switch.py
homeassistant/components/velux/__init__.py
homeassistant/components/velux/cover.py

View file

@ -34,6 +34,7 @@ PLATFORMS = [
Platform.CLIMATE,
Platform.COVER,
Platform.LIGHT,
Platform.SELECT,
Platform.SENSOR,
Platform.SWITCH,
]

View file

@ -0,0 +1,47 @@
"""Support for Velbus select."""
from velbusaio.channels import SelectedProgram
from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Velbus select based on config_entry."""
await hass.data[DOMAIN][entry.entry_id]["tsk"]
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
async_add_entities(VelbusSelect(channel) for channel in cntrl.get_all("select"))
class VelbusSelect(VelbusEntity, SelectEntity):
"""Representation of a select option for velbus."""
_channel: SelectedProgram
_attr_entity_category = EntityCategory.CONFIG
def __init__(
self,
channel: SelectedProgram,
) -> None:
"""Initialize a select Velbus entity."""
super().__init__(channel)
self._attr_options = self._channel.get_options()
self._attr_unique_id = f"{self._attr_unique_id}-program_select"
async def async_select_option(self, option: str) -> None:
"""Update the program on the module."""
await self._channel.set_selected_program(option)
@property
def current_option(self) -> str:
"""Return the selected option."""
return self._channel.get_selected_program()