hass-core/homeassistant/components/flipr/coordinator.py
cnico ee7bee2766
Refactoring flipr integration to prepare Hub device addition (#125262)
* Addition of hub device

* coordinator udata updated after a hub action

* Unit tests update

* Unit tests improvements

* addition of tests on select and switch platforms

* wording

* Removal of select platform for PR containing only one platform

* Remove hub to maintain only the refactoring that prepare the hub device addition

* Review corrections

* wording

* Review corrections

* Review corrections

* Review corrections
2024-09-11 23:34:29 +02:00

44 lines
1.3 KiB
Python

"""DataUpdateCoordinator for flipr integration."""
from datetime import timedelta
import logging
from flipr_api import FliprAPIRestClient
from flipr_api.exceptions import FliprError
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
_LOGGER = logging.getLogger(__name__)
class FliprDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to hold Flipr data retrieval."""
config_entry: ConfigEntry
def __init__(
self, hass: HomeAssistant, client: FliprAPIRestClient, flipr_or_hub_id: str
) -> None:
"""Initialize."""
self.device_id = flipr_or_hub_id
self.client = client
super().__init__(
hass,
_LOGGER,
name=f"Flipr or Hub data measure for {self.device_id}",
update_interval=timedelta(minutes=15),
)
async def _async_update_data(self):
"""Fetch data from API endpoint."""
try:
data = await self.hass.async_add_executor_job(
self.client.get_pool_measure_latest, self.device_id
)
except FliprError as error:
raise UpdateFailed(error) from error
return data