Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """The OpenGarage integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 import logging
7 from typing import Any
8 
9 import opengarage
10 
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers import update_coordinator
13 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
14 
15 from .const import DOMAIN
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 
21  """Class to manage fetching Opengarage data."""
22 
23  def __init__(
24  self,
25  hass: HomeAssistant,
26  *,
27  open_garage_connection: opengarage.OpenGarage,
28  ) -> None:
29  """Initialize global Opengarage data updater."""
30  self.open_garage_connectionopen_garage_connection = open_garage_connection
31 
32  super().__init__(
33  hass,
34  _LOGGER,
35  name=DOMAIN,
36  update_interval=timedelta(seconds=5),
37  )
38 
39  async def _async_update_data(self) -> dict[str, Any]:
40  """Fetch data."""
41  data = await self.open_garage_connectionopen_garage_connection.update_state()
42  if data is None:
43  raise update_coordinator.UpdateFailed(
44  "Unable to connect to OpenGarage device"
45  )
46  return data
None __init__(self, HomeAssistant hass, *opengarage.OpenGarage open_garage_connection)
Definition: coordinator.py:28