From db484a0571a5a459bcbf2552b3ad2fa25d5e6c70 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Jul 2026 22:40:27 +0200 Subject: [PATCH] Migrate input_select entity attributes to StrEnum (#175757) Co-authored-by: Franck Nijhof Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/input_select/__init__.py | 12 ++++++++---- homeassistant/components/input_select/const.py | 9 +++++++++ .../components/input_select/reproduce_state.py | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 homeassistant/components/input_select/const.py diff --git a/homeassistant/components/input_select/__init__.py b/homeassistant/components/input_select/__init__.py index 7d7c809c68e5..ac220c1a24b6 100644 --- a/homeassistant/components/input_select/__init__.py +++ b/homeassistant/components/input_select/__init__.py @@ -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: diff --git a/homeassistant/components/input_select/const.py b/homeassistant/components/input_select/const.py new file mode 100644 index 000000000000..46e2e69d3371 --- /dev/null +++ b/homeassistant/components/input_select/const.py @@ -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" diff --git a/homeassistant/components/input_select/reproduce_state.py b/homeassistant/components/input_select/reproduce_state.py index f3781d70cd4f..a02dab5ea15b 100644 --- a/homeassistant/components/input_select/reproduce_state.py +++ b/homeassistant/components/input_select/reproduce_state.py @@ -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