Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Data update coordinator for the SimpleFIN integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from typing import Any
7 
8 from simplefin4py import FinancialData, SimpleFin
9 from simplefin4py.exceptions import SimpleFinAuthError, SimpleFinPaymentRequiredError
10 
11 from homeassistant.config_entries import ConfigEntry
12 from homeassistant.core import HomeAssistant
13 from homeassistant.exceptions import ConfigEntryError
14 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
15 
16 from .const import LOGGER
17 
18 
20  """Data update coordinator for the SimpleFIN integration."""
21 
22  config_entry: ConfigEntry
23 
24  def __init__(self, hass: HomeAssistant, client: SimpleFin) -> None:
25  """Initialize the coordinator."""
26  super().__init__(
27  hass=hass,
28  logger=LOGGER,
29  name="simplefin",
30  update_interval=timedelta(hours=4),
31  )
32  self.clientclient = client
33 
34  async def _async_update_data(self) -> Any:
35  """Fetch data for all accounts."""
36  try:
37  return await self.clientclient.fetch_data()
38  except SimpleFinAuthError as err:
39  raise ConfigEntryError("Authentication failed") from err
40 
41  except SimpleFinPaymentRequiredError as err:
42  LOGGER.warning(
43  "There is a billing issue with your SimpleFin account, contact Simplefin to address this issue"
44  )
45  raise UpdateFailed from err
None __init__(self, HomeAssistant hass, SimpleFin client)
Definition: coordinator.py:24
MetOfficeData fetch_data(datapoint.Manager connection, Site site, str mode)
Definition: helpers.py:32