Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """DataUpdateCoordinator for the PVOutput integration."""
2 
3 from __future__ import annotations
4 
5 from pvo import PVOutput, PVOutputAuthenticationError, PVOutputNoDataError, Status
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_API_KEY
9 from homeassistant.core import HomeAssistant
10 from homeassistant.exceptions import ConfigEntryAuthFailed
11 from homeassistant.helpers.aiohttp_client import async_get_clientsession
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 from .const import CONF_SYSTEM_ID, DOMAIN, LOGGER, SCAN_INTERVAL
15 
16 
18  """The PVOutput Data Update Coordinator."""
19 
20  config_entry: ConfigEntry
21 
22  def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
23  """Initialize the PVOutput coordinator."""
24  self.config_entryconfig_entryconfig_entry = entry
25  self.pvoutputpvoutput = PVOutput(
26  api_key=entry.data[CONF_API_KEY],
27  system_id=entry.data[CONF_SYSTEM_ID],
28  session=async_get_clientsession(hass),
29  )
30 
31  super().__init__(hass, LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
32 
33  async def _async_update_data(self) -> Status:
34  """Fetch system status from PVOutput."""
35  try:
36  return await self.pvoutputpvoutput.status()
37  except PVOutputNoDataError as err:
38  raise UpdateFailed("PVOutput has no data available") from err
39  except PVOutputAuthenticationError as err:
40  raise ConfigEntryAuthFailed from err
None __init__(self, HomeAssistant hass, ConfigEntry entry)
Definition: coordinator.py:22
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)