Migrate input_select entity attributes to StrEnum (#175757)

Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
epenet
2026-07-08 22:40:27 +02:00
committed by GitHub
co-authored by Franck Nijhof Copilot Autofix powered by AI
parent 972058311c
commit db484a0571
3 changed files with 22 additions and 6 deletions
@@ -15,8 +15,9 @@ from homeassistant.components.select import (
SERVICE_SELECT_OPTION,
SERVICE_SELECT_PREVIOUS,
SelectEntity,
SelectEntityCapabilityAttribute,
)
from homeassistant.const import (
from homeassistant.const import ( # noqa: F401
ATTR_EDITABLE,
CONF_ICON,
CONF_ID,
@@ -33,6 +34,8 @@ import homeassistant.helpers.service
from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType, VolDictType
from .const import InputSelectEntityStateAttribute
_LOGGER = logging.getLogger(__name__)
DOMAIN = "input_select"
@@ -250,9 +253,10 @@ class InputSelect(collection.CollectionEntity, SelectEntity, RestoreEntity):
"""Representation of a select input."""
_entity_component_unrecorded_attributes = (
SelectEntity._entity_component_unrecorded_attributes - {ATTR_OPTIONS} # noqa: SLF001
SelectEntity._entity_component_unrecorded_attributes # noqa: SLF001
- {SelectEntityCapabilityAttribute.OPTIONS}
)
_unrecorded_attributes = frozenset({ATTR_EDITABLE})
_unrecorded_attributes = frozenset({InputSelectEntityStateAttribute.EDITABLE})
_attr_should_poll = False
editable: bool
@@ -299,7 +303,7 @@ class InputSelect(collection.CollectionEntity, SelectEntity, RestoreEntity):
@override
def extra_state_attributes(self) -> dict[str, bool]:
"""Return the state attributes."""
return {ATTR_EDITABLE: self.editable}
return {InputSelectEntityStateAttribute.EDITABLE: self.editable}
@override
async def async_select_option(self, option: str) -> None:
@@ -0,0 +1,9 @@
"""Constants for the input_select integration."""
from enum import StrEnum
class InputSelectEntityStateAttribute(StrEnum):
"""State attributes for input select entities."""
EDITABLE = "editable"
@@ -5,6 +5,7 @@ from collections.abc import Iterable, Mapping
import logging
from typing import Any
from homeassistant.components.select import SelectEntityCapabilityAttribute
from homeassistant.const import ATTR_ENTITY_ID, ATTR_OPTION
from homeassistant.core import Context, HomeAssistant, State
@@ -39,9 +40,11 @@ async def _async_reproduce_state(
service_data = {ATTR_ENTITY_ID: state.entity_id}
# If options are specified, call SERVICE_SET_OPTIONS
if ATTR_OPTIONS in state.attributes:
if SelectEntityCapabilityAttribute.OPTIONS in state.attributes:
service = SERVICE_SET_OPTIONS
service_data[ATTR_OPTIONS] = state.attributes[ATTR_OPTIONS]
service_data[ATTR_OPTIONS] = state.attributes[
SelectEntityCapabilityAttribute.OPTIONS
]
await hass.services.async_call(
DOMAIN, service, service_data, context=context, blocking=True