mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Use selectors in Open-Meteo configuration flow (#67004)
This commit is contained in:
parent
102ae9f0e3
commit
23fdf9eef8
@ -5,10 +5,11 @@ from typing import Any
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN, ENTITY_ID_HOME
|
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_ZONE
|
from homeassistant.const import CONF_ZONE
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers.selector import selector
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
@ -22,31 +23,22 @@ class OpenMeteoFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
zones: dict[str, str] = {
|
|
||||||
entity_id: state.name
|
|
||||||
for entity_id in self.hass.states.async_entity_ids(ZONE_DOMAIN)
|
|
||||||
if (state := self.hass.states.get(entity_id)) is not None
|
|
||||||
}
|
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
await self.async_set_unique_id(user_input[CONF_ZONE])
|
await self.async_set_unique_id(user_input[CONF_ZONE])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
state = self.hass.states.get(user_input[CONF_ZONE])
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=zones[user_input[CONF_ZONE]],
|
title=state.name if state else "Open-Meteo",
|
||||||
data={CONF_ZONE: user_input[CONF_ZONE]},
|
data={CONF_ZONE: user_input[CONF_ZONE]},
|
||||||
)
|
)
|
||||||
|
|
||||||
zones = dict(sorted(zones.items(), key=lambda x: x[1], reverse=True))
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_ZONE): vol.In(
|
vol.Required(CONF_ZONE): selector(
|
||||||
{
|
{"entity": {"domain": ZONE_DOMAIN}}
|
||||||
ENTITY_ID_HOME: zones.pop(ENTITY_ID_HOME),
|
|
||||||
**zones,
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user