mirror of
https://github.com/home-assistant/core.git
synced 2026-09-08 06:31:35 +01:00
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
"""Base entity for the WattWächter Plus integration."""
|
|
|
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN, MANUFACTURER
|
|
from .coordinator import WattwaechterCoordinator
|
|
|
|
|
|
class WattwaechterEntity(CoordinatorEntity[WattwaechterCoordinator]):
|
|
"""Base entity for WattWächter Plus devices."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(self, coordinator: WattwaechterCoordinator) -> None:
|
|
"""Initialize the entity."""
|
|
super().__init__(coordinator)
|
|
# Prefer the device's mDNS hostname for the visit link (stable across
|
|
# DHCP changes); fall back to the host/IP when system info is missing.
|
|
system = coordinator.data.system
|
|
mdns_name = system.get_value("wifi", "mdns_name") if system else None
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, coordinator.device_id)},
|
|
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)},
|
|
manufacturer=MANUFACTURER,
|
|
model=coordinator.model,
|
|
sw_version=coordinator.fw_version,
|
|
configuration_url=f"http://{mdns_name or coordinator.host}",
|
|
)
|