2023-02-19 02:58:21 +01:00
|
|
|
import logging
|
2023-07-23 21:52:42 +02:00
|
|
|
from typing import Any
|
2023-02-19 02:58:21 +01:00
|
|
|
|
2023-11-20 15:56:24 +01:00
|
|
|
import voluptuous as vol # type: ignore[import-untyped]
|
2023-02-19 02:58:21 +01:00
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
2023-07-23 21:52:42 +02:00
|
|
|
from homeassistant.data_entry_flow import FlowResult
|
2023-05-25 00:52:54 +02:00
|
|
|
|
2023-02-19 02:58:21 +01:00
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class HonFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|
|
|
VERSION = 1
|
|
|
|
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
|
|
|
|
2023-07-23 21:52:42 +02:00
|
|
|
def __init__(self) -> None:
|
|
|
|
self._email: str | None = None
|
|
|
|
self._password: str | None = None
|
2023-02-19 02:58:21 +01:00
|
|
|
|
2023-07-23 21:52:42 +02:00
|
|
|
async def async_step_user(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
) -> FlowResult:
|
2023-02-19 02:58:21 +01:00
|
|
|
if user_input is None:
|
2023-04-10 19:51:16 +02:00
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str}
|
|
|
|
),
|
|
|
|
)
|
2023-02-19 02:58:21 +01:00
|
|
|
|
|
|
|
self._email = user_input[CONF_EMAIL]
|
|
|
|
self._password = user_input[CONF_PASSWORD]
|
|
|
|
|
2023-07-23 21:52:42 +02:00
|
|
|
if self._email is None or self._password is None:
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2023-02-19 02:58:21 +01:00
|
|
|
# Check if already configured
|
|
|
|
await self.async_set_unique_id(self._email)
|
|
|
|
self._abort_if_unique_id_configured()
|
|
|
|
|
|
|
|
return self.async_create_entry(
|
|
|
|
title=self._email,
|
|
|
|
data={
|
|
|
|
CONF_EMAIL: self._email,
|
|
|
|
CONF_PASSWORD: self._password,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-07-23 21:52:42 +02:00
|
|
|
async def async_step_import(self, user_input: dict[str, str]) -> FlowResult:
|
2023-02-19 02:58:21 +01:00
|
|
|
return await self.async_step_user(user_input)
|