hass-core/homeassistant/components/justnimbus/coordinator.py
Koen van Zuijlen acd07b4826
Fix for justnimbus integration (#99212)
* Fix for justnimbus integration

* Fixed tests and moved const

* fix: added reauth flow

* fix: fixed reauth config flow

* chore: added config_flow reauth test

* chore: Processed PR feedback

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2024-01-23 08:56:11 +01:00

36 lines
1.1 KiB
Python

"""JustNimbus coordinator."""
from __future__ import annotations
from datetime import timedelta
import logging
import justnimbus
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import CONF_ZIP_CODE, DOMAIN
_LOGGER = logging.getLogger(__name__)
class JustNimbusCoordinator(DataUpdateCoordinator[justnimbus.JustNimbusModel]):
"""Data update coordinator."""
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Initialize the coordinator."""
super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(minutes=1),
)
self._client = justnimbus.JustNimbusClient(
client_id=entry.data[CONF_CLIENT_ID], zip_code=entry.data[CONF_ZIP_CODE]
)
async def _async_update_data(self) -> justnimbus.JustNimbusModel:
"""Fetch the latest data from the source."""
return await self.hass.async_add_executor_job(self._client.get_data)