Migrate esphome select platform to use _on_static_info_update (#95022)

This commit is contained in:
J. Nick Koston 2023-06-22 09:05:57 +02:00 committed by GitHub
parent e204e80528
commit b700400183
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,12 @@
"""Support for esphome selects."""
from __future__ import annotations
from aioesphomeapi import SelectInfo, SelectState
from aioesphomeapi import EntityInfo, SelectInfo, SelectState
from homeassistant.components.assist_pipeline.select import AssistPipelineSelect
from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import (
@ -44,10 +44,11 @@ async def async_setup_entry(
class EsphomeSelect(EsphomeEntity[SelectInfo, SelectState], SelectEntity):
"""A select implementation for esphome."""
@property
def options(self) -> list[str]:
"""Return a set of selectable options."""
return self._static_info.options
@callback
def _on_static_info_update(self, static_info: EntityInfo) -> None:
"""Set attrs from static info."""
super()._on_static_info_update(static_info)
self._attr_options = self._static_info.options
@property
@esphome_state_property
@ -58,7 +59,7 @@ class EsphomeSelect(EsphomeEntity[SelectInfo, SelectState], SelectEntity):
async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
await self._client.select_command(self._static_info.key, option)
await self._client.select_command(self._key, option)
class EsphomeAssistPipelineSelect(EsphomeAssistEntity, AssistPipelineSelect):