Move pi_hole base entity to separate module (#126509)
parent
78d80fefc5
commit
f7543cd0ba
|
@ -22,12 +22,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import CONF_STATISTICS_ONLY, DOMAIN, MIN_TIME_BETWEEN_UPDATES
|
||||
|
||||
|
@ -140,35 +135,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: PiHoleConfigEntry) -> bo
|
|||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload Pi-hole entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class PiHoleEntity(CoordinatorEntity[DataUpdateCoordinator[None]]):
|
||||
"""Representation of a Pi-hole entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: Hole,
|
||||
coordinator: DataUpdateCoordinator[None],
|
||||
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 self.api.tls:
|
||||
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,
|
||||
)
|
||||
|
|
|
@ -17,7 +17,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from . import PiHoleConfigEntry, PiHoleEntity
|
||||
from . import PiHoleConfigEntry
|
||||
from .entity import PiHoleEntity
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
"""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,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class PiHoleEntity(CoordinatorEntity[DataUpdateCoordinator[None]]):
|
||||
"""Representation of a Pi-hole entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: Hole,
|
||||
coordinator: DataUpdateCoordinator[None],
|
||||
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 self.api.tls:
|
||||
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,
|
||||
)
|
|
@ -11,7 +11,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from . import PiHoleConfigEntry, PiHoleEntity
|
||||
from . import PiHoleConfigEntry
|
||||
from .entity import PiHoleEntity
|
||||
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
|
|
|
@ -14,8 +14,9 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PiHoleConfigEntry, PiHoleEntity
|
||||
from . import PiHoleConfigEntry
|
||||
from .const import SERVICE_DISABLE, SERVICE_DISABLE_ATTR_DURATION
|
||||
from .entity import PiHoleEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from . import PiHoleConfigEntry, PiHoleEntity
|
||||
from . import PiHoleConfigEntry
|
||||
from .entity import PiHoleEntity
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
|
Loading…
Reference in New Issue