From 8b738c919c7c43322b68477fcd5fd2cbfc4b6979 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:51:07 +0100 Subject: [PATCH] Correct labels in EnOcean config flow (#136338) --- homeassistant/components/enocean/__init__.py | 2 +- .../components/enocean/config_flow.py | 27 ++++++++++++++----- homeassistant/components/enocean/const.py | 2 +- homeassistant/components/enocean/dongle.py | 6 ++--- homeassistant/components/enocean/strings.json | 22 ++++++++++++--- tests/components/enocean/test_config_flow.py | 6 ++--- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/enocean/__init__.py b/homeassistant/components/enocean/__init__.py index 6dcec5ec218..9f53c79cc5b 100644 --- a/homeassistant/components/enocean/__init__.py +++ b/homeassistant/components/enocean/__init__.py @@ -47,7 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: - """Unload ENOcean config entry.""" + """Unload EnOcean config entry.""" enocean_dongle = hass.data[DATA_ENOCEAN][ENOCEAN_DONGLE] enocean_dongle.unload() diff --git a/homeassistant/components/enocean/config_flow.py b/homeassistant/components/enocean/config_flow.py index 2452d27b168..fd25b0c6ce1 100644 --- a/homeassistant/components/enocean/config_flow.py +++ b/homeassistant/components/enocean/config_flow.py @@ -1,4 +1,4 @@ -"""Config flows for the ENOcean integration.""" +"""Config flows for the EnOcean integration.""" from typing import Any @@ -6,6 +6,11 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_DEVICE +from homeassistant.helpers.selector import ( + SelectSelector, + SelectSelectorConfig, + SelectSelectorMode, +) from . import dongle from .const import DOMAIN, ERROR_INVALID_DONGLE_PATH, LOGGER @@ -15,7 +20,7 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN): """Handle the enOcean config flows.""" VERSION = 1 - MANUAL_PATH_VALUE = "Custom path" + MANUAL_PATH_VALUE = "manual" def __init__(self) -> None: """Initialize the EnOcean config flow.""" @@ -52,14 +57,24 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN): return self.create_enocean_entry(user_input) errors = {CONF_DEVICE: ERROR_INVALID_DONGLE_PATH} - bridges = await self.hass.async_add_executor_job(dongle.detect) - if len(bridges) == 0: + devices = await self.hass.async_add_executor_job(dongle.detect) + if len(devices) == 0: return await self.async_step_manual(user_input) + devices.append(self.MANUAL_PATH_VALUE) - bridges.append(self.MANUAL_PATH_VALUE) return self.async_show_form( step_id="detect", - data_schema=vol.Schema({vol.Required(CONF_DEVICE): vol.In(bridges)}), + data_schema=vol.Schema( + { + vol.Required(CONF_DEVICE): SelectSelector( + SelectSelectorConfig( + options=devices, + translation_key="devices", + mode=SelectSelectorMode.LIST, + ) + ) + } + ), errors=errors, ) diff --git a/homeassistant/components/enocean/const.py b/homeassistant/components/enocean/const.py index 3624493b42e..0f3271655d8 100644 --- a/homeassistant/components/enocean/const.py +++ b/homeassistant/components/enocean/const.py @@ -1,4 +1,4 @@ -"""Constants for the ENOcean integration.""" +"""Constants for the EnOcean integration.""" import logging diff --git a/homeassistant/components/enocean/dongle.py b/homeassistant/components/enocean/dongle.py index 2d9a3f8787e..43214b12064 100644 --- a/homeassistant/components/enocean/dongle.py +++ b/homeassistant/components/enocean/dongle.py @@ -18,7 +18,7 @@ _LOGGER = logging.getLogger(__name__) class EnOceanDongle: """Representation of an EnOcean dongle. - The dongle is responsible for receiving the ENOcean frames, + The dongle is responsible for receiving the EnOcean frames, creating devices if needed, and dispatching messages to platforms. """ @@ -53,7 +53,7 @@ class EnOceanDongle: def callback(self, packet): """Handle EnOcean device's callback. - This is the callback function called by python-enocan whenever there + This is the callback function called by python-enocean whenever there is an incoming packet. """ @@ -63,7 +63,7 @@ class EnOceanDongle: def detect(): - """Return a list of candidate paths for USB ENOcean dongles. + """Return a list of candidate paths for USB EnOcean dongles. This method is currently a bit simplistic, it may need to be improved to support more configurations and OS. diff --git a/homeassistant/components/enocean/strings.json b/homeassistant/components/enocean/strings.json index 1a6f08cbf37..9baf4386eda 100644 --- a/homeassistant/components/enocean/strings.json +++ b/homeassistant/components/enocean/strings.json @@ -1,16 +1,23 @@ { "config": { + "flow_title": "{name}", "step": { "detect": { - "title": "Select the path to your EnOcean dongle", + "description": "Select your EnOcean USB dongle.", "data": { - "path": "USB dongle path" + "device": "USB dongle" + }, + "data_description": { + "device": "Path to your EnOcean USB dongle." } }, "manual": { - "title": "Enter the path to your EnOcean dongle", + "description": "Enter the path to your EnOcean USB dongle.", "data": { - "path": "[%key:component::enocean::config::step::detect::data::path%]" + "device": "[%key:component::enocean::config::step::detect::data::device%]" + }, + "data_description": { + "device": "[%key:component::enocean::config::step::detect::data_description::device%]" } } }, @@ -20,5 +27,12 @@ "abort": { "invalid_dongle_path": "Invalid dongle path" } + }, + "selector": { + "devices": { + "options": { + "manual": "Custom path" + } + } } } diff --git a/tests/components/enocean/test_config_flow.py b/tests/components/enocean/test_config_flow.py index 96c0843906f..fb5b1de19d8 100644 --- a/tests/components/enocean/test_config_flow.py +++ b/tests/components/enocean/test_config_flow.py @@ -32,7 +32,7 @@ async def test_user_flow_cannot_create_multiple_instances(hass: HomeAssistant) - async def test_user_flow_with_detected_dongle(hass: HomeAssistant) -> None: - """Test the user flow with a detected ENOcean dongle.""" + """Test the user flow with a detected EnOcean dongle.""" FAKE_DONGLE_PATH = "/fake/dongle" with patch(DONGLE_DETECT_METHOD, Mock(return_value=[FAKE_DONGLE_PATH])): @@ -42,13 +42,13 @@ async def test_user_flow_with_detected_dongle(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.FORM assert result["step_id"] == "detect" - devices = result["data_schema"].schema.get("device").container + devices = result["data_schema"].schema.get(CONF_DEVICE).config.get("options") assert FAKE_DONGLE_PATH in devices assert EnOceanFlowHandler.MANUAL_PATH_VALUE in devices async def test_user_flow_with_no_detected_dongle(hass: HomeAssistant) -> None: - """Test the user flow with a detected ENOcean dongle.""" + """Test the user flow with a detected EnOcean dongle.""" with patch(DONGLE_DETECT_METHOD, Mock(return_value=[])): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}