Correct labels in EnOcean config flow (#136338)

This commit is contained in:
Christopher Fenner 2025-01-28 11:51:07 +01:00 committed by GitHub
parent 7fc5a2294d
commit 8b738c919c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 18 deletions

View File

@ -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()

View File

@ -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,
)

View File

@ -1,4 +1,4 @@
"""Constants for the ENOcean integration."""
"""Constants for the EnOcean integration."""
import logging

View File

@ -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.

View File

@ -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"
}
}
}
}

View File

@ -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}