Fix pi_hole sensor icon (#54403)
This commit is contained in:
parent
f5901265dc
commit
c0a7fca628
3 changed files with 26 additions and 17 deletions
|
@ -161,6 +161,8 @@ def _async_platforms(entry: ConfigEntry) -> list[str]:
|
|||
class PiHoleEntity(CoordinatorEntity):
|
||||
"""Representation of a Pi-hole entity."""
|
||||
|
||||
_attr_icon: str = "mdi:pi-hole"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: Hole,
|
||||
|
@ -174,11 +176,6 @@ class PiHoleEntity(CoordinatorEntity):
|
|||
self._name = name
|
||||
self._server_unique_id = server_unique_id
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Icon to use in the frontend, if any."""
|
||||
return "mdi:pi-hole"
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information of the entity."""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Constants for the pi_hole integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.sensor import SensorEntityDescription
|
||||
|
@ -29,56 +30,63 @@ DATA_KEY_API = "api"
|
|||
DATA_KEY_COORDINATOR = "coordinator"
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
@dataclass
|
||||
class PiHoleSensorEntityDescription(SensorEntityDescription):
|
||||
"""Describes PiHole sensor entity."""
|
||||
|
||||
icon: str = "mdi:pi-hole"
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[PiHoleSensorEntityDescription, ...] = (
|
||||
PiHoleSensorEntityDescription(
|
||||
key="ads_blocked_today",
|
||||
name="Ads Blocked Today",
|
||||
unit_of_measurement="ads",
|
||||
icon="mdi:close-octagon-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="ads_percentage_today",
|
||||
name="Ads Percentage Blocked Today",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:close-octagon-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="clients_ever_seen",
|
||||
name="Seen Clients",
|
||||
unit_of_measurement="clients",
|
||||
icon="mdi:account-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="dns_queries_today",
|
||||
name="DNS Queries Today",
|
||||
unit_of_measurement="queries",
|
||||
icon="mdi:comment-question-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="domains_being_blocked",
|
||||
name="Domains Blocked",
|
||||
unit_of_measurement="domains",
|
||||
icon="mdi:block-helper",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="queries_cached",
|
||||
name="DNS Queries Cached",
|
||||
unit_of_measurement="queries",
|
||||
icon="mdi:comment-question-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="queries_forwarded",
|
||||
name="DNS Queries Forwarded",
|
||||
unit_of_measurement="queries",
|
||||
icon="mdi:comment-question-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="unique_clients",
|
||||
name="DNS Unique Clients",
|
||||
unit_of_measurement="clients",
|
||||
icon="mdi:account-outline",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
PiHoleSensorEntityDescription(
|
||||
key="unique_domains",
|
||||
name="DNS Unique Domains",
|
||||
unit_of_measurement="domains",
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
from hole import Hole
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -19,6 +19,7 @@ from .const import (
|
|||
DATA_KEY_COORDINATOR,
|
||||
DOMAIN as PIHOLE_DOMAIN,
|
||||
SENSOR_TYPES,
|
||||
PiHoleSensorEntityDescription,
|
||||
)
|
||||
|
||||
|
||||
|
@ -44,13 +45,15 @@ async def async_setup_entry(
|
|||
class PiHoleSensor(PiHoleEntity, SensorEntity):
|
||||
"""Representation of a Pi-hole sensor."""
|
||||
|
||||
entity_description: PiHoleSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: Hole,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
name: str,
|
||||
server_unique_id: str,
|
||||
description: SensorEntityDescription,
|
||||
description: PiHoleSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize a Pi-hole sensor."""
|
||||
super().__init__(api, coordinator, name, server_unique_id)
|
||||
|
@ -58,6 +61,7 @@ class PiHoleSensor(PiHoleEntity, SensorEntity):
|
|||
|
||||
self._attr_name = f"{name} {description.name}"
|
||||
self._attr_unique_id = f"{self._server_unique_id}/{description.name}"
|
||||
self._attr_icon = description.icon # Necessary to overwrite inherited value
|
||||
|
||||
@property
|
||||
def state(self) -> Any:
|
||||
|
|
Loading…
Add table
Reference in a new issue