From 9f1b4c9035da4bcb4dc2bef2a60858fd7c661a29 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:14:45 +0100 Subject: [PATCH] Improve EnOcean config flow (#162751) --- .../components/enocean/config_flow.py | 21 +++++++++---------- tests/components/enocean/test_config_flow.py | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/enocean/config_flow.py b/homeassistant/components/enocean/config_flow.py index fd25b0c6ce1..0f7b1126425 100644 --- a/homeassistant/components/enocean/config_flow.py +++ b/homeassistant/components/enocean/config_flow.py @@ -6,6 +6,7 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_DEVICE +from homeassistant.helpers import config_validation as cv from homeassistant.helpers.selector import ( SelectSelector, SelectSelectorConfig, @@ -15,6 +16,12 @@ from homeassistant.helpers.selector import ( from . import dongle from .const import DOMAIN, ERROR_INVALID_DONGLE_PATH, LOGGER +MANUAL_SCHEMA = vol.Schema( + { + vol.Required(CONF_DEVICE): cv.string, + } +) + class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN): """Handle the enOcean config flows.""" @@ -49,17 +56,14 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Propose a list of detected dongles.""" - errors = {} if user_input is not None: if user_input[CONF_DEVICE] == self.MANUAL_PATH_VALUE: return await self.async_step_manual() - if await self.validate_enocean_conf(user_input): - return self.create_enocean_entry(user_input) - errors = {CONF_DEVICE: ERROR_INVALID_DONGLE_PATH} + return await self.async_step_manual(user_input) devices = await self.hass.async_add_executor_job(dongle.detect) if len(devices) == 0: - return await self.async_step_manual(user_input) + return await self.async_step_manual() devices.append(self.MANUAL_PATH_VALUE) return self.async_show_form( @@ -75,26 +79,21 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN): ) } ), - errors=errors, ) async def async_step_manual( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Request manual USB dongle path.""" - default_value = None errors = {} if user_input is not None: if await self.validate_enocean_conf(user_input): return self.create_enocean_entry(user_input) - default_value = user_input[CONF_DEVICE] errors = {CONF_DEVICE: ERROR_INVALID_DONGLE_PATH} return self.async_show_form( step_id="manual", - data_schema=vol.Schema( - {vol.Required(CONF_DEVICE, default=default_value): str} - ), + data_schema=self.add_suggested_values_to_schema(MANUAL_SCHEMA, user_input), errors=errors, ) diff --git a/tests/components/enocean/test_config_flow.py b/tests/components/enocean/test_config_flow.py index fb5b1de19d8..3e9f81661ff 100644 --- a/tests/components/enocean/test_config_flow.py +++ b/tests/components/enocean/test_config_flow.py @@ -106,7 +106,7 @@ async def test_detection_flow_with_invalid_path(hass: HomeAssistant) -> None: ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "detect" + assert result["step_id"] == "manual" assert CONF_DEVICE in result["errors"]