Add device info to Hydrawise (#100828)

* Add device info to Hydrawise

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Remove _attr_has_entity_name

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
David Knowles 2023-09-26 03:15:20 -04:00 committed by GitHub
parent 7b1b189f3e
commit 8ba6fd7935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 9 deletions

View file

@ -3,9 +3,11 @@ from __future__ import annotations
from typing import Any
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, MANUFACTURER
from .coordinator import HydrawiseDataUpdateCoordinator
@ -20,14 +22,16 @@ class HydrawiseEntity(CoordinatorEntity[HydrawiseDataUpdateCoordinator]):
data: dict[str, Any],
coordinator: HydrawiseDataUpdateCoordinator,
description: EntityDescription,
device_id_key: str = "relay_id",
) -> None:
"""Initialize the Hydrawise entity."""
super().__init__(coordinator=coordinator)
self.data = data
self.entity_description = description
self._attr_name = f"{self.data['name']} {description.name}"
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {"identifier": self.data.get("relay")}
self._device_id = str(data.get(device_id_key))
self._attr_unique_id = f"{self._device_id}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
name=data["name"],
manufacturer=MANUFACTURER,
)