36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN, MANUFACTURER, MODEL
|
|
from .coordinator import DualPidDataUpdateCoordinator
|
|
|
|
|
|
class DualPidEntity(CoordinatorEntity[DualPidDataUpdateCoordinator]):
|
|
"""Base entity for Dual PID entities."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: DualPidDataUpdateCoordinator,
|
|
entry: ConfigEntry,
|
|
key: str,
|
|
) -> None:
|
|
super().__init__(coordinator)
|
|
self._entry = entry
|
|
self._key = key
|
|
self._attr_unique_id = f"{entry.entry_id}_{key}"
|
|
|
|
@property
|
|
def device_info(self) -> DeviceInfo:
|
|
return DeviceInfo(
|
|
identifiers={(DOMAIN, self._entry.entry_id)},
|
|
name=self._entry.title,
|
|
manufacturer=MANUFACTURER,
|
|
model=MODEL,
|
|
configuration_url=f"http://{self._entry.data['host']}:{self._entry.data['port']}",
|
|
)
|