Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Define an object to manage fetching Mastodon data."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from typing import Any
7 
8 from mastodon import Mastodon
9 from mastodon.Mastodon import MastodonError
10 
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 from .const import LOGGER
15 
16 
18  """Class to manage fetching Mastodon data."""
19 
20  def __init__(self, hass: HomeAssistant, client: Mastodon) -> None:
21  """Initialize coordinator."""
22  super().__init__(
23  hass, logger=LOGGER, name="Mastodon", update_interval=timedelta(hours=1)
24  )
25  self.clientclient = client
26 
27  async def _async_update_data(self) -> dict[str, Any]:
28  try:
29  account: dict = await self.hasshass.async_add_executor_job(
30  self.clientclient.account_verify_credentials
31  )
32  except MastodonError as ex:
33  raise UpdateFailed(ex) from ex
34 
35  return account
None __init__(self, HomeAssistant hass, Mastodon client)
Definition: coordinator.py:20