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

@ -1,36 +1,32 @@
"""Base classes for Hydrawise entities."""
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity, EntityDescription
from typing import Any
from .const import SIGNAL_UPDATE_HYDRAWISE
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
class HydrawiseEntity(Entity):
class HydrawiseEntity(CoordinatorEntity):
"""Entity class for Hydrawise devices."""
_attr_attribution = "Data provided by hydrawise.com"
def __init__(self, data, description: EntityDescription) -> None:
def __init__(
self,
*,
data: dict[str, Any],
coordinator: DataUpdateCoordinator,
description: EntityDescription,
) -> None:
"""Initialize the Hydrawise entity."""
self.entity_description = description
super().__init__(coordinator=coordinator)
self.data = data
self.entity_description = description
self._attr_name = f"{self.data['name']} {description.name}"
async def async_added_to_hass(self):
"""Register callbacks."""
self.async_on_remove(
async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_HYDRAWISE, self._update_callback
)
)
@callback
def _update_callback(self):
"""Call update method."""
self.async_schedule_update_ha_state(True)
@property
def extra_state_attributes(self):
"""Return the state attributes."""