Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Provides the Fully Kiosk Browser DataUpdateCoordinator."""
2 
3 import asyncio
4 from typing import Any, cast
5 
6 from fullykiosk import FullyKiosk
7 from fullykiosk.exceptions import FullyKioskError
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SSL, CONF_VERIFY_SSL
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.aiohttp_client import async_get_clientsession
13 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
14 
15 from .const import DEFAULT_PORT, LOGGER, UPDATE_INTERVAL
16 
17 
19  """Define an object to hold Fully Kiosk Browser data."""
20 
21  def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
22  """Initialize."""
23  self.use_ssluse_ssl = entry.data.get(CONF_SSL, False)
24  self.fullyfully = FullyKiosk(
26  entry.data[CONF_HOST],
27  DEFAULT_PORT,
28  entry.data[CONF_PASSWORD],
29  use_ssl=self.use_ssluse_ssl,
30  verify_ssl=entry.data.get(CONF_VERIFY_SSL, False),
31  )
32  super().__init__(
33  hass,
34  LOGGER,
35  name=entry.data[CONF_HOST],
36  update_interval=UPDATE_INTERVAL,
37  )
38 
39  async def _async_update_data(self) -> dict[str, Any]:
40  """Update data via library."""
41  try:
42  async with asyncio.timeout(15):
43  # Get device info and settings in parallel
44  result = await asyncio.gather(
45  self.fullyfully.getDeviceInfo(), self.fullyfully.getSettings()
46  )
47  # Store settings under settings key in data
48  result[0]["settings"] = result[1]
49  return cast(dict[str, Any], result[0])
50  except FullyKioskError as error:
51  raise UpdateFailed(error) from error
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)