Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """DataUpdateCoordinator for the SABnzbd integration."""
2 
3 from datetime import timedelta
4 import logging
5 from typing import Any
6 
7 from pysabnzbd import SabnzbdApi, SabnzbdApiException
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  """The SABnzbd update coordinator."""
18 
19  config_entry: ConfigEntry
20 
21  def __init__(
22  self,
23  hass: HomeAssistant,
24  config_entry: ConfigEntry,
25  sab_api: SabnzbdApi,
26  ) -> None:
27  """Initialize the SABnzbd update coordinator."""
28  self.sab_apisab_api = sab_api
29 
30  super().__init__(
31  hass,
32  _LOGGER,
33  config_entry=config_entry,
34  name="SABnzbd",
35  update_interval=timedelta(seconds=30),
36  )
37 
38  async def _async_update_data(self) -> dict[str, Any]:
39  """Get the latest data from the SABnzbd API."""
40  try:
41  await self.sab_apisab_api.refresh_data()
42  except SabnzbdApiException as err:
43  raise UpdateFailed("Error while fetching data") from err
44 
45  return self.sab_apisab_api.queue
None __init__(self, HomeAssistant hass, ConfigEntry config_entry, SabnzbdApi sab_api)
Definition: coordinator.py:26