mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00

* Support for firmware 2.1.7 * add device ID as unique_id * add device ID as unique_id * add test device id as unique_id * backward compatibility * move outside try * Sensor return type Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * not needed * make slave error enum state * fix enum * Update homeassistant/components/v2c/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/v2c/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/v2c/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * simplify tests * fix misspellings from upstream library * add sensor tests * just enough coverage for enum sensor * Refactor V2C tests (#117264) * Refactor V2C tests * fix rebase issues * ruff * review * fix https://github.com/home-assistant/core/issues/117296 --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""Config flow for V2C integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from pytrydan import Trydan
|
|
from pytrydan.exceptions import TrydanError
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
|
from homeassistant.const import CONF_HOST
|
|
from homeassistant.helpers.httpx_client import get_async_client
|
|
|
|
from .const import DOMAIN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
STEP_USER_DATA_SCHEMA = vol.Schema(
|
|
{
|
|
vol.Required(CONF_HOST): str,
|
|
}
|
|
)
|
|
|
|
|
|
class V2CConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for V2C."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_user(
|
|
self, user_input: dict[str, Any] | None = None
|
|
) -> ConfigFlowResult:
|
|
"""Handle the initial step."""
|
|
errors: dict[str, str] = {}
|
|
if user_input is not None:
|
|
evse = Trydan(
|
|
user_input[CONF_HOST],
|
|
client=get_async_client(self.hass, verify_ssl=False),
|
|
)
|
|
|
|
try:
|
|
data = await evse.get_data()
|
|
|
|
except TrydanError:
|
|
errors["base"] = "cannot_connect"
|
|
except Exception:
|
|
_LOGGER.exception("Unexpected exception")
|
|
errors["base"] = "unknown"
|
|
else:
|
|
if data.ID:
|
|
await self.async_set_unique_id(data.ID)
|
|
self._abort_if_unique_id_configured()
|
|
|
|
return self.async_create_entry(
|
|
title=f"EVSE {user_input[CONF_HOST]}", data=user_input
|
|
)
|
|
|
|
return self.async_show_form(
|
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
|
)
|