* Adding initial Epion Air integration logic * Skipping sensors with missing data * Patching Epion integration * Adding additional Epion measurement types * Cleaning up logging * Cleaning up code * Fixing error handling for invalid Epion keys * Adding tests and improving error handling * Patching Epion tests * Cleaning up Epion integration code * Bumping Epion package and including missing files * Moving data updates to coordinator and addressing feedback * Improve exception handling * Exposing model name and firmware version * Cleaning up code according to review * Cleaning up code according to review * Adding check to prevent duplicate account setup * Refactoring tests and checking for duplicates * Cleaning up test code according to review * Cleaning up test code * Removing entity name overrides * Fix code format for tests * Adding missing newlines in JSON files * Fixing formatting * Updating device method to always return a device * Updating coordinator
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Config flow for Epion."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from epion import Epion, EpionAuthenticationError, EpionConnectionError
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.config_entries import ConfigFlow
|
|
from homeassistant.const import CONF_API_KEY
|
|
from homeassistant.data_entry_flow import FlowResult
|
|
|
|
from .const import DOMAIN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class EpionConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for Epion."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_user(
|
|
self, user_input: dict[str, Any] | None = None
|
|
) -> FlowResult:
|
|
"""Handle a flow initiated by the user."""
|
|
errors = {}
|
|
if user_input:
|
|
api = Epion(user_input[CONF_API_KEY])
|
|
try:
|
|
api_data = await self.hass.async_add_executor_job(api.get_current)
|
|
except EpionAuthenticationError:
|
|
errors["base"] = "invalid_auth"
|
|
except EpionConnectionError:
|
|
_LOGGER.error("Unexpected problem when configuring Epion API")
|
|
errors["base"] = "cannot_connect"
|
|
else:
|
|
await self.async_set_unique_id(api_data["accountId"])
|
|
self._abort_if_unique_id_configured()
|
|
return self.async_create_entry(
|
|
title="Epion integration",
|
|
data=user_input,
|
|
)
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema(
|
|
{
|
|
vol.Required(CONF_API_KEY): str,
|
|
}
|
|
),
|
|
errors=errors,
|
|
)
|