Add a DataUpdateCoordinator to Hydrawise (#93223)

* Add a DataUpdateCoordinator to Hydrawise

* Replace DATA_HYDRAWISE with DOMAIN

* Replace persistent notification with a ConfigEntryNotReady exception

* Changes requested during PR review

* Add a type annotation to the `monitored_conditions` field.

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
David Knowles 2023-05-24 08:07:37 -04:00 committed by GitHub
parent f355f0cc6d
commit ace45f31ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 136 additions and 91 deletions

View file

@ -0,0 +1,29 @@
"""DataUpdateCoordinator for the Hydrawise integration."""
from __future__ import annotations
from datetime import timedelta
from hydrawiser.core import Hydrawiser
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DOMAIN, LOGGER
class HydrawiseDataUpdateCoordinator(DataUpdateCoordinator[None]):
"""The Hydrawise Data Update Coordinator."""
def __init__(
self, hass: HomeAssistant, api: Hydrawiser, scan_interval: timedelta
) -> None:
"""Initialize HydrawiseDataUpdateCoordinator."""
super().__init__(hass, LOGGER, name=DOMAIN, update_interval=scan_interval)
self.api = api
async def _async_update_data(self) -> None:
"""Fetch the latest data from Hydrawise."""
result = await self.hass.async_add_executor_job(self.api.update_controller_info)
if not result:
raise UpdateFailed("Failed to refresh Hydrawise data")