Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for Brother integration."""
2 
3 from asyncio import timeout
4 import logging
5 
6 from brother import Brother, BrotherSensors, SnmpError, UnsupportedModelError
7 
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
10 
11 from .const import DOMAIN, UPDATE_INTERVAL
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  """Class to manage fetching Brother data from the printer."""
18 
19  def __init__(self, hass: HomeAssistant, brother: Brother) -> None:
20  """Initialize."""
21  self.brotherbrother = brother
22 
23  super().__init__(
24  hass,
25  _LOGGER,
26  name=DOMAIN,
27  update_interval=UPDATE_INTERVAL,
28  )
29 
30  async def _async_update_data(self) -> BrotherSensors:
31  """Update data via library."""
32  try:
33  async with timeout(20):
34  data = await self.brotherbrother.async_update()
35  except (ConnectionError, SnmpError, UnsupportedModelError) as error:
36  raise UpdateFailed(error) from error
37  return data
None __init__(self, HomeAssistant hass, Brother brother)
Definition: coordinator.py:19