From 0180fa4a937cede4c86eef344358ede83f81f337 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 9 Dec 2025 23:51:17 -0800 Subject: [PATCH] feat: use EntitySelector for light entity selection with search support (#1335) Replace cv.multi_select with HA's EntitySelector for the lights field in the options flow. This provides: - Built-in search/typing to find entities faster - Better UX with HA's native entity picker - Improved handling of renamed entities Closes #1208 --- .../adaptive_lighting/config_flow.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 12f1f65e..5e21e67b 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -3,11 +3,11 @@ import logging from typing import Any -import homeassistant.helpers.config_validation as cv import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_NAME, MAJOR_VERSION, MINOR_VERSION from homeassistant.core import callback +from homeassistant.helpers.selector import EntitySelector, EntitySelectorConfig from .const import ( # pylint: disable=unused-import CONF_LIGHTS, @@ -16,8 +16,7 @@ from .const import ( # pylint: disable=unused-import NONE_STR, VALIDATION_TUPLES, ) -from .helpers import get_friendly_name -from .switch import _supported_features, validate +from .switch import validate _LOGGER = logging.getLogger(__name__) @@ -146,12 +145,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow): if not errors: return self.async_create_entry(title="", data=user_input) - all_lights_with_names = { - light: get_friendly_name(self.hass, light) - for light in self.hass.states.async_entity_ids("light") - if _supported_features(self.hass, light) - } - all_lights = list(all_lights_with_names.keys()) + # Validate that all configured lights still exist + all_lights = set(self.hass.states.async_entity_ids("light")) for configured_light in data[CONF_LIGHTS]: if configured_light not in all_lights: errors = {CONF_LIGHTS: "entity_missing"} @@ -160,14 +155,15 @@ class OptionsFlowHandler(config_entries.OptionsFlow): data[CONF_NAME], configured_light, ) - all_lights.append(configured_light) - all_lights_with_names[configured_light] = configured_light - light_options = { - entity_id: f"{name} ({entity_id})" - for entity_id, name in all_lights_with_names.items() + to_replace = { + CONF_LIGHTS: EntitySelector( + EntitySelectorConfig( + domain="light", + multiple=True, + ), + ), } - to_replace = {CONF_LIGHTS: cv.multi_select(light_options)} options_schema = {} for name, default, validation in VALIDATION_TUPLES: