mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add select entities to ESPHome (#53526)
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
a6b34924be
commit
18bf0762b5
@ -279,6 +279,7 @@ omit =
|
|||||||
homeassistant/components/esphome/fan.py
|
homeassistant/components/esphome/fan.py
|
||||||
homeassistant/components/esphome/light.py
|
homeassistant/components/esphome/light.py
|
||||||
homeassistant/components/esphome/number.py
|
homeassistant/components/esphome/number.py
|
||||||
|
homeassistant/components/esphome/select.py
|
||||||
homeassistant/components/esphome/sensor.py
|
homeassistant/components/esphome/sensor.py
|
||||||
homeassistant/components/esphome/switch.py
|
homeassistant/components/esphome/switch.py
|
||||||
homeassistant/components/essent/sensor.py
|
homeassistant/components/essent/sensor.py
|
||||||
|
@ -19,6 +19,7 @@ from aioesphomeapi import (
|
|||||||
FanInfo,
|
FanInfo,
|
||||||
LightInfo,
|
LightInfo,
|
||||||
NumberInfo,
|
NumberInfo,
|
||||||
|
SelectInfo,
|
||||||
SensorInfo,
|
SensorInfo,
|
||||||
SwitchInfo,
|
SwitchInfo,
|
||||||
TextSensorInfo,
|
TextSensorInfo,
|
||||||
@ -41,6 +42,7 @@ INFO_TYPE_TO_PLATFORM: dict[type[EntityInfo], str] = {
|
|||||||
FanInfo: "fan",
|
FanInfo: "fan",
|
||||||
LightInfo: "light",
|
LightInfo: "light",
|
||||||
NumberInfo: "number",
|
NumberInfo: "number",
|
||||||
|
SelectInfo: "select",
|
||||||
SensorInfo: "sensor",
|
SensorInfo: "sensor",
|
||||||
SwitchInfo: "switch",
|
SwitchInfo: "switch",
|
||||||
TextSensorInfo: "sensor",
|
TextSensorInfo: "sensor",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "ESPHome",
|
"name": "ESPHome",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/esphome",
|
"documentation": "https://www.home-assistant.io/integrations/esphome",
|
||||||
"requirements": ["aioesphomeapi==5.0.1"],
|
"requirements": ["aioesphomeapi==5.1.1"],
|
||||||
"zeroconf": ["_esphomelib._tcp.local."],
|
"zeroconf": ["_esphomelib._tcp.local."],
|
||||||
"codeowners": ["@OttoWinter", "@jesserockz"],
|
"codeowners": ["@OttoWinter", "@jesserockz"],
|
||||||
"after_dependencies": ["zeroconf", "tag"],
|
"after_dependencies": ["zeroconf", "tag"],
|
||||||
|
65
homeassistant/components/esphome/select.py
Normal file
65
homeassistant/components/esphome/select.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
"""Support for esphome selects."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
from aioesphomeapi import SelectInfo, SelectState
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.select import SelectEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
|
||||||
|
|
||||||
|
ICON_SCHEMA = vol.Schema(cv.icon)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up esphome selects based on a config entry."""
|
||||||
|
await platform_async_setup_entry(
|
||||||
|
hass,
|
||||||
|
entry,
|
||||||
|
async_add_entities,
|
||||||
|
component_key="select",
|
||||||
|
info_type=SelectInfo,
|
||||||
|
entity_type=EsphomeSelect,
|
||||||
|
state_type=SelectState,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
|
||||||
|
# pylint: disable=invalid-overridden-method
|
||||||
|
|
||||||
|
|
||||||
|
class EsphomeSelect(EsphomeEntity[SelectInfo, SelectState], SelectEntity):
|
||||||
|
"""A select implementation for esphome."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self) -> str | None:
|
||||||
|
"""Return the icon."""
|
||||||
|
if not self._static_info.icon:
|
||||||
|
return None
|
||||||
|
return cast(str, ICON_SCHEMA(self._static_info.icon))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def options(self) -> list[str]:
|
||||||
|
"""Return a set of selectable options."""
|
||||||
|
return self._static_info.options
|
||||||
|
|
||||||
|
@esphome_state_property
|
||||||
|
def current_option(self) -> str | None:
|
||||||
|
"""Return the state of the entity."""
|
||||||
|
if self._state.missing_state:
|
||||||
|
return None
|
||||||
|
return self._state.state
|
||||||
|
|
||||||
|
async def async_select_option(self, option: str) -> None:
|
||||||
|
"""Change the selected option."""
|
||||||
|
await self._client.select_command(self._static_info.key, option)
|
@ -163,7 +163,7 @@ aioeafm==0.1.2
|
|||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==5.0.1
|
aioesphomeapi==5.1.1
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==0.4.1
|
aioflo==0.4.1
|
||||||
|
@ -103,7 +103,7 @@ aioeafm==0.1.2
|
|||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==5.0.1
|
aioesphomeapi==5.1.1
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==0.4.1
|
aioflo==0.4.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user