* reset to latest dev branch * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * formatting tweak * Removed info errors * fix bad billing error message * addressing PR * addressing PR * reauth abort and already_confiugred added to strings.json * adding the reauth message * ruff * update reqs * reset to latest dev branch * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * formatting tweak * Removed info errors * fix bad billing error message * addressing PR * addressing PR * reauth abort and already_confiugred added to strings.json * adding the reauth message * ruff * update reqs * Update homeassistant/components/simplefin/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Addressing a few PR comments - removing nix - and adding runtime data * updated comments * rename config flow * pulling reauth :( - inline stuff * inline more * fixed a tab issue * reverting changes * various PR updates and code removal * generator async add * Update homeassistant/components/simplefin/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * always callable * Update homeassistant/components/simplefin/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * no-verify * type * fixing missing domain * it looks like this file is gone now * typing * sorta pass * fix license * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * addressing PR * Update homeassistant/components/simplefin/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * move property to entity.py * moved stuff out to else block * Initial Snappshot Testing ... still have unadressed changes to make * Addressing PR Comments * pushing back to joost * removing non-needed file * added more asserts * reducing mocks - need to fix patch paths still * Changed patch to be more localized to config_flow * Removed unneeded fixture * Moved coordinator around * Cleaning up the code * Removed a NOQA" * Upping the number of asserts * cleanup * fixed abort call * incremental update - for Josot... changed a function signature and removed an annotatoin * no-verify * Added an abort test * ruff * increased coverage but it might not pass muster for JOOST * increased coverage but it might not pass muster for JOOST * Much nicer test now * tried to simplify * Fix nits --------- Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Data update coordinator for the SimpleFIN integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
from typing import Any
|
|
|
|
from simplefin4py import FinancialData, SimpleFin
|
|
from simplefin4py.exceptions import SimpleFinAuthError, SimpleFinPaymentRequiredError
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryError
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
from .const import LOGGER
|
|
|
|
|
|
class SimpleFinDataUpdateCoordinator(DataUpdateCoordinator[FinancialData]):
|
|
"""Data update coordinator for the SimpleFIN integration."""
|
|
|
|
config_entry: ConfigEntry
|
|
|
|
def __init__(self, hass: HomeAssistant, client: SimpleFin) -> None:
|
|
"""Initialize the coordinator."""
|
|
super().__init__(
|
|
hass=hass,
|
|
logger=LOGGER,
|
|
name="simplefin",
|
|
update_interval=timedelta(hours=4),
|
|
)
|
|
self.client = client
|
|
|
|
async def _async_update_data(self) -> Any:
|
|
"""Fetch data for all accounts."""
|
|
try:
|
|
return await self.client.fetch_data()
|
|
except SimpleFinAuthError as err:
|
|
raise ConfigEntryError("Authentication failed") from err
|
|
|
|
except SimpleFinPaymentRequiredError as err:
|
|
LOGGER.warning(
|
|
"There is a billing issue with your SimpleFin account, contact Simplefin to address this issue"
|
|
)
|
|
raise UpdateFailed from err
|