Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for The Internet Printing Protocol (IPP) integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 import logging
7 
8 from pyipp import IPP, IPPError, Printer as IPPPrinter
9 
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.aiohttp_client import async_get_clientsession
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 from .const import DOMAIN
15 
16 SCAN_INTERVAL = timedelta(seconds=60)
17 
18 _LOGGER = logging.getLogger(__name__)
19 
20 
22  """Class to manage fetching IPP data from single endpoint."""
23 
24  def __init__(
25  self,
26  hass: HomeAssistant,
27  *,
28  host: str,
29  port: int,
30  base_path: str,
31  tls: bool,
32  verify_ssl: bool,
33  device_id: str,
34  ) -> None:
35  """Initialize global IPP data updater."""
36  self.device_iddevice_id = device_id
37  self.ippipp = IPP(
38  host=host,
39  port=port,
40  base_path=base_path,
41  tls=tls,
42  verify_ssl=verify_ssl,
43  session=async_get_clientsession(hass, verify_ssl),
44  )
45 
46  super().__init__(
47  hass,
48  _LOGGER,
49  name=DOMAIN,
50  update_interval=SCAN_INTERVAL,
51  )
52 
53  async def _async_update_data(self) -> IPPPrinter:
54  """Fetch data from IPP."""
55  try:
56  return await self.ippipp.printer()
57  except IPPError as error:
58  raise UpdateFailed(f"Invalid response from API: {error}") from error
None __init__(self, HomeAssistant hass, *str host, int port, str base_path, bool tls, bool verify_ssl, str device_id)
Definition: coordinator.py:34
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)