hass-core/homeassistant/components/open_meteo/config_flow.py
Raman Gupta b325c112b4
Add SelectorType enum and TypedDicts for each selector's data (#68399)
* rebase off current

* rearrange

* Overload selector function

* Update/fix all selector references

* better typing?

* remove extra option

* move things around

* Switch to Sequence type to avoid ignoring mypy error

* Get rid of ...'s

* Improve typing to reduce number of ignores

* Remove all typing ignores

* Make config optional for selectors that don't need a config

* add missing unit prefixes

* Rename TypedDicts

* Update homeassistant/helpers/selector.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* review feedback

* remove peta from integration integration

* Fix min_max

* Revert change to selector function

* Fix logic

* Add typing for selector classes

* Update selector.py

* Fix indent

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-04-11 09:20:56 +02:00

45 lines
1.4 KiB
Python

"""Config flow to configure the Open-Meteo integration."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_ZONE
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.selector import EntitySelector, EntitySelectorConfig
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()
state = self.hass.states.get(user_input[CONF_ZONE])
return self.async_create_entry(
title=state.name if state else "Open-Meteo",
data={CONF_ZONE: user_input[CONF_ZONE]},
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_ZONE): EntitySelector(
EntitySelectorConfig(domain=ZONE_DOMAIN),
),
}
),
)