mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Correct labels in EnOcean config flow (#136338)
This commit is contained in:
parent
7fc5a2294d
commit
8b738c919c
@ -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:
|
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 = hass.data[DATA_ENOCEAN][ENOCEAN_DONGLE]
|
||||||
enocean_dongle.unload()
|
enocean_dongle.unload()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""Config flows for the ENOcean integration."""
|
"""Config flows for the EnOcean integration."""
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -6,6 +6,11 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_DEVICE
|
from homeassistant.const import CONF_DEVICE
|
||||||
|
from homeassistant.helpers.selector import (
|
||||||
|
SelectSelector,
|
||||||
|
SelectSelectorConfig,
|
||||||
|
SelectSelectorMode,
|
||||||
|
)
|
||||||
|
|
||||||
from . import dongle
|
from . import dongle
|
||||||
from .const import DOMAIN, ERROR_INVALID_DONGLE_PATH, LOGGER
|
from .const import DOMAIN, ERROR_INVALID_DONGLE_PATH, LOGGER
|
||||||
@ -15,7 +20,7 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle the enOcean config flows."""
|
"""Handle the enOcean config flows."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
MANUAL_PATH_VALUE = "Custom path"
|
MANUAL_PATH_VALUE = "manual"
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the EnOcean config flow."""
|
"""Initialize the EnOcean config flow."""
|
||||||
@ -52,14 +57,24 @@ class EnOceanFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
return self.create_enocean_entry(user_input)
|
return self.create_enocean_entry(user_input)
|
||||||
errors = {CONF_DEVICE: ERROR_INVALID_DONGLE_PATH}
|
errors = {CONF_DEVICE: ERROR_INVALID_DONGLE_PATH}
|
||||||
|
|
||||||
bridges = await self.hass.async_add_executor_job(dongle.detect)
|
devices = await self.hass.async_add_executor_job(dongle.detect)
|
||||||
if len(bridges) == 0:
|
if len(devices) == 0:
|
||||||
return await self.async_step_manual(user_input)
|
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(
|
return self.async_show_form(
|
||||||
step_id="detect",
|
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,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""Constants for the ENOcean integration."""
|
"""Constants for the EnOcean integration."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class EnOceanDongle:
|
class EnOceanDongle:
|
||||||
"""Representation of an EnOcean dongle.
|
"""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.
|
creating devices if needed, and dispatching messages to platforms.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class EnOceanDongle:
|
|||||||
def callback(self, packet):
|
def callback(self, packet):
|
||||||
"""Handle EnOcean device's callback.
|
"""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.
|
is an incoming packet.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class EnOceanDongle:
|
|||||||
|
|
||||||
|
|
||||||
def detect():
|
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
|
This method is currently a bit simplistic, it may need to be
|
||||||
improved to support more configurations and OS.
|
improved to support more configurations and OS.
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
|
"flow_title": "{name}",
|
||||||
"step": {
|
"step": {
|
||||||
"detect": {
|
"detect": {
|
||||||
"title": "Select the path to your EnOcean dongle",
|
"description": "Select your EnOcean USB dongle.",
|
||||||
"data": {
|
"data": {
|
||||||
"path": "USB dongle path"
|
"device": "USB dongle"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"device": "Path to your EnOcean USB dongle."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"manual": {
|
"manual": {
|
||||||
"title": "Enter the path to your EnOcean dongle",
|
"description": "Enter the path to your EnOcean USB dongle.",
|
||||||
"data": {
|
"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": {
|
"abort": {
|
||||||
"invalid_dongle_path": "Invalid dongle path"
|
"invalid_dongle_path": "Invalid dongle path"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"selector": {
|
||||||
|
"devices": {
|
||||||
|
"options": {
|
||||||
|
"manual": "Custom path"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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:
|
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"
|
FAKE_DONGLE_PATH = "/fake/dongle"
|
||||||
|
|
||||||
with patch(DONGLE_DETECT_METHOD, Mock(return_value=[FAKE_DONGLE_PATH])):
|
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["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "detect"
|
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 FAKE_DONGLE_PATH in devices
|
||||||
assert EnOceanFlowHandler.MANUAL_PATH_VALUE in devices
|
assert EnOceanFlowHandler.MANUAL_PATH_VALUE in devices
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_with_no_detected_dongle(hass: HomeAssistant) -> None:
|
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=[])):
|
with patch(DONGLE_DETECT_METHOD, Mock(return_value=[])):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user