33 lines
942 B
Python
33 lines
942 B
Python
"""Data Update Coordinator"""
|
|
import logging
|
|
from datetime import timedelta
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
from .fplapi import FplApi
|
|
from .const import DOMAIN
|
|
|
|
SCAN_INTERVAL = timedelta(seconds=1200)
|
|
|
|
_LOGGER: logging.Logger = logging.getLogger(__package__)
|
|
|
|
|
|
class FplDataUpdateCoordinator(DataUpdateCoordinator):
|
|
"""Class to manage fetching data from the API."""
|
|
|
|
def __init__(self, hass: HomeAssistant, client: FplApi) -> None:
|
|
"""Initialize."""
|
|
self.api = client
|
|
self.platforms = []
|
|
|
|
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
|
|
|
|
async def _async_update_data(self):
|
|
"""Update data via library."""
|
|
try:
|
|
return await self.api.async_get_data()
|
|
except Exception as exception:
|
|
raise UpdateFailed() from exception
|