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