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