Files
ha-freshharvest/custom_components/freshharvest/config_flow.py
T
flan eb50a9ecc1 Add Fresh Harvest integration scaffold
Implements the freshharvest.com two-step login handshake, config flow,
6-hour polling coordinator, and four delivery sensors. Portal page parsing
is not implemented; async_get_next_delivery raises until the account HTML
is mapped against a signed-in session.
2026-08-03 17:05:17 +00:00

51 lines
1.6 KiB
Python

"""Config flow for Fresh Harvest."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from .api import FreshHarvestAuthError, FreshHarvestClient, FreshHarvestError
from .const import DOMAIN
STEP_USER_SCHEMA = vol.Schema(
{vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str}
)
class FreshHarvestConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle the portal-credentials flow."""
VERSION = 1
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
errors: dict[str, str] = {}
if user_input is not None:
email = user_input[CONF_EMAIL]
await self.async_set_unique_id(email.lower())
self._abort_if_unique_id_configured()
# cookie_jar must persist across requests for the token handshake.
session = async_create_clientsession(self.hass)
client = FreshHarvestClient(session, email, user_input[CONF_PASSWORD])
try:
await client.async_login()
except FreshHarvestAuthError:
errors["base"] = "invalid_auth"
except FreshHarvestError:
errors["base"] = "cannot_connect"
else:
return self.async_create_entry(title=email, data=user_input)
return self.async_show_form(
step_id="user", data_schema=STEP_USER_SCHEMA, errors=errors
)