Illia cbaef096fa
Add Arve integration (#113156)
* add Arve integration

* Update homeassistant/components/arve/config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Various fixes, changed scan interval to one minute

* coordinator implementation

* Code cleanup

* Moved device info to the entity.py, ArveDeviceEntityDescription to sensor.py

* delete refresh before adding entities

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/test_config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/conftest.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Changed value_fn in sensors.py, added typing to description

* Code cleanups, platfrom test implementation

* New code cleanups, first two working tests

* Created platform test, generated snapshots

* Reworked integration to get all of the customer devices

* new fixes

* Added customer id, small cleanups

* Logic of setting unique_id to the config flow

* Added test of abortion on duplicate config_flow id

* Added "available" and "device" properties fro ArveDeviceEntity

* small _attr_unique_id fix

* Added new test, improved mocking, various fixes

* Various cleanups and fixes

* microfix

* Update homeassistant/components/arve/strings.json

* ruff fix

---------

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-04-08 17:24:32 +02:00

54 lines
1.6 KiB
Python

"""Config flow for Arve integration."""
from __future__ import annotations
import logging
from typing import Any
from asyncarve import Arve, ArveConnectionError, ArveCustomer
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_SECRET
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class ArveConfigFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Arve."""
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:
arve = Arve(
user_input[CONF_ACCESS_TOKEN],
user_input[CONF_CLIENT_SECRET],
)
try:
customer: ArveCustomer = await arve.get_customer_id()
except ArveConnectionError:
errors["base"] = "cannot_connect"
else:
await self.async_set_unique_id(customer.customerId)
self._abort_if_unique_id_configured()
return self.async_create_entry(
title="Arve",
data=user_input,
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_ACCESS_TOKEN): str,
vol.Required(CONF_CLIENT_SECRET): str,
}
),
errors=errors,
)