2021-12-16 20:12:33 +00:00
|
|
|
"""Config flow to configure the Open-Meteo integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-02-22 00:29:58 +00:00
|
|
|
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN
|
2021-12-16 20:12:33 +00:00
|
|
|
from homeassistant.config_entries import ConfigFlow
|
|
|
|
from homeassistant.const import CONF_ZONE
|
|
|
|
from homeassistant.data_entry_flow import FlowResult
|
2022-04-11 07:20:56 +00:00
|
|
|
from homeassistant.helpers.selector import EntitySelector, EntitySelectorConfig
|
2021-12-16 20:12:33 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
|
|
|
class OpenMeteoFlowHandler(ConfigFlow, domain=DOMAIN):
|
|
|
|
"""Config flow for OpenMeteo."""
|
|
|
|
|
|
|
|
VERSION = 1
|
|
|
|
|
|
|
|
async def async_step_user(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
) -> FlowResult:
|
|
|
|
"""Handle a flow initialized by the user."""
|
|
|
|
if user_input is not None:
|
|
|
|
await self.async_set_unique_id(user_input[CONF_ZONE])
|
|
|
|
self._abort_if_unique_id_configured()
|
2022-02-22 00:29:58 +00:00
|
|
|
|
|
|
|
state = self.hass.states.get(user_input[CONF_ZONE])
|
2021-12-16 20:12:33 +00:00
|
|
|
return self.async_create_entry(
|
2022-02-22 00:29:58 +00:00
|
|
|
title=state.name if state else "Open-Meteo",
|
2021-12-16 20:12:33 +00:00
|
|
|
data={CONF_ZONE: user_input[CONF_ZONE]},
|
|
|
|
)
|
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{
|
2022-04-11 07:20:56 +00:00
|
|
|
vol.Required(CONF_ZONE): EntitySelector(
|
|
|
|
EntitySelectorConfig(domain=ZONE_DOMAIN),
|
2021-12-16 20:12:33 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|