* 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>
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""Coordinator for the Arve integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
|
|
from asyncarve import (
|
|
Arve,
|
|
ArveConnectionError,
|
|
ArveDeviceInfo,
|
|
ArveDevices,
|
|
ArveError,
|
|
ArveSensProData,
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_SECRET
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
from .const import DOMAIN, LOGGER
|
|
|
|
|
|
class ArveCoordinator(DataUpdateCoordinator[ArveSensProData]):
|
|
"""Arve coordinator."""
|
|
|
|
config_entry: ConfigEntry
|
|
devices: ArveDevices
|
|
|
|
def __init__(self, hass: HomeAssistant) -> None:
|
|
"""Initialize Arve coordinator."""
|
|
super().__init__(
|
|
hass,
|
|
LOGGER,
|
|
name=DOMAIN,
|
|
update_interval=timedelta(seconds=60),
|
|
)
|
|
|
|
self.arve = Arve(
|
|
self.config_entry.data[CONF_ACCESS_TOKEN],
|
|
self.config_entry.data[CONF_CLIENT_SECRET],
|
|
session=async_get_clientsession(hass),
|
|
)
|
|
|
|
async def _async_update_data(self) -> dict[str, ArveDeviceInfo]:
|
|
"""Fetch data from API endpoint."""
|
|
try:
|
|
self.devices = await self.arve.get_devices()
|
|
|
|
response_data = {
|
|
sn: ArveDeviceInfo(
|
|
await self.arve.device_sensor_data(sn),
|
|
await self.arve.get_sensor_info(sn),
|
|
)
|
|
for sn in self.devices.sn
|
|
}
|
|
except ArveConnectionError as err:
|
|
raise UpdateFailed("Unable to connect to the Arve device") from err
|
|
except ArveError as err:
|
|
raise UpdateFailed("Unknown error occurred") from err
|
|
|
|
return response_data
|