2023-05-22 13:47:32 +00:00
|
|
|
"""Base classes for Hydrawise entities."""
|
2023-05-25 05:58:59 +00:00
|
|
|
from __future__ import annotations
|
2023-05-22 13:47:32 +00:00
|
|
|
|
2023-05-24 12:07:37 +00:00
|
|
|
from typing import Any
|
2023-05-22 13:47:32 +00:00
|
|
|
|
2023-05-24 12:07:37 +00:00
|
|
|
from homeassistant.helpers.entity import EntityDescription
|
2023-05-25 05:58:59 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2023-05-22 13:47:32 +00:00
|
|
|
|
2023-05-25 05:58:59 +00:00
|
|
|
from .coordinator import HydrawiseDataUpdateCoordinator
|
2023-05-22 13:47:32 +00:00
|
|
|
|
2023-05-25 05:58:59 +00:00
|
|
|
|
|
|
|
class HydrawiseEntity(CoordinatorEntity[HydrawiseDataUpdateCoordinator]):
|
2023-05-22 13:47:32 +00:00
|
|
|
"""Entity class for Hydrawise devices."""
|
|
|
|
|
|
|
|
_attr_attribution = "Data provided by hydrawise.com"
|
|
|
|
|
2023-05-24 12:07:37 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
*,
|
|
|
|
data: dict[str, Any],
|
2023-05-25 05:58:59 +00:00
|
|
|
coordinator: HydrawiseDataUpdateCoordinator,
|
2023-05-24 12:07:37 +00:00
|
|
|
description: EntityDescription,
|
|
|
|
) -> None:
|
2023-05-22 13:47:32 +00:00
|
|
|
"""Initialize the Hydrawise entity."""
|
2023-05-24 12:07:37 +00:00
|
|
|
super().__init__(coordinator=coordinator)
|
2023-05-22 13:47:32 +00:00
|
|
|
self.data = data
|
2023-05-24 12:07:37 +00:00
|
|
|
self.entity_description = description
|
2023-05-22 13:47:32 +00:00
|
|
|
self._attr_name = f"{self.data['name']} {description.name}"
|
|
|
|
|
|
|
|
@property
|
2023-05-25 05:58:59 +00:00
|
|
|
def extra_state_attributes(self) -> dict[str, Any]:
|
2023-05-22 13:47:32 +00:00
|
|
|
"""Return the state attributes."""
|
|
|
|
return {"identifier": self.data.get("relay")}
|