mirror of
https://github.com/home-assistant/core.git
synced 2026-05-26 18:26:25 +01:00
ecee23fc7a
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""The pi_hole component."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from hole import Hole
|
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import PiHoleUpdateCoordinator
|
|
|
|
|
|
class PiHoleEntity(CoordinatorEntity[PiHoleUpdateCoordinator]):
|
|
"""Representation of a Pi-hole entity."""
|
|
|
|
def __init__(
|
|
self,
|
|
api: Hole,
|
|
coordinator: PiHoleUpdateCoordinator,
|
|
name: str,
|
|
server_unique_id: str,
|
|
) -> None:
|
|
"""Initialize a Pi-hole entity."""
|
|
super().__init__(coordinator)
|
|
self.api = api
|
|
self._name = name
|
|
self._server_unique_id = server_unique_id
|
|
|
|
@property
|
|
def device_info(self) -> DeviceInfo:
|
|
"""Return the device information of the entity."""
|
|
if (
|
|
getattr(self.api, "tls", None) # API version 5
|
|
or getattr(self.api, "protocol", None) == "https" # API version 6
|
|
):
|
|
config_url = f"https://{self.api.host}/{self.api.location}"
|
|
else:
|
|
config_url = f"http://{self.api.host}/{self.api.location}"
|
|
|
|
return DeviceInfo(
|
|
identifiers={(DOMAIN, self._server_unique_id)},
|
|
name=self._name,
|
|
manufacturer="Pi-hole",
|
|
configuration_url=config_url,
|
|
)
|