1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-01 03:36:05 +01:00
Files
core/homeassistant/components/pi_hole/entity.py
T
2026-04-30 21:14:48 +02:00

45 lines
1.3 KiB
Python

"""The pi_hole component."""
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,
)