"""Base entity for Ninlight devices.""" from __future__ import annotations from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DEFAULT_PORT, DOMAIN from .coordinator import NinlightCoordinator, NinlightConfigEntry class NinlightEntity(CoordinatorEntity[NinlightCoordinator]): """Common device info for every entity of one bulb.""" _attr_has_entity_name = True def __init__(self, coordinator: NinlightCoordinator, entry: NinlightConfigEntry) -> None: super().__init__(coordinator, context=entry.entry_id) mac = (entry.unique_id or "unknown").lower() info = coordinator.info or {} # Deliberately no `connections={("mac", mac)}`: HA treats a MAC in `connections` # as a network-topology link, so a bulb the FRITZ!Box tracker already knows merged # into that router-adjacent device and its entity id fell back to the IP. The MAC # still identifies the device via unique_id; identifiers are the sole identity here. self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, mac)}, # The bulb itself has no user-visible name field that survives rediscovery # cleanly, so the entry title (set from mDNS or by the user) names the device. name=entry.title, manufacturer="Klyqa", model=info.get("product_name") or info.get("product"), model_id=info.get("device_type"), sw_version=info.get("fw_version"), configuration_url=f"http://{entry.data['host']}:{entry.data.get('port', DEFAULT_PORT)}/", ) def _entry_mac(entry: NinlightConfigEntry) -> str: mac: str = entry.unique_id or "unknown" return mac.lower()