Fix AdGuard Home rules count sensor (#75879)
parent
10356b9379
commit
6ba0b9cff2
|
@ -26,7 +26,7 @@ PARALLEL_UPDATES = 4
|
||||||
class AdGuardHomeEntityDescriptionMixin:
|
class AdGuardHomeEntityDescriptionMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_fn: Callable[[AdGuardHome], Callable[[], Coroutine[Any, Any, int | float]]]
|
value_fn: Callable[[AdGuardHome], Coroutine[Any, Any, int | float]]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -42,56 +42,56 @@ SENSORS: tuple[AdGuardHomeEntityDescription, ...] = (
|
||||||
name="DNS queries",
|
name="DNS queries",
|
||||||
icon="mdi:magnify",
|
icon="mdi:magnify",
|
||||||
native_unit_of_measurement="queries",
|
native_unit_of_measurement="queries",
|
||||||
value_fn=lambda adguard: adguard.stats.dns_queries,
|
value_fn=lambda adguard: adguard.stats.dns_queries(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="blocked_filtering",
|
key="blocked_filtering",
|
||||||
name="DNS queries blocked",
|
name="DNS queries blocked",
|
||||||
icon="mdi:magnify-close",
|
icon="mdi:magnify-close",
|
||||||
native_unit_of_measurement="queries",
|
native_unit_of_measurement="queries",
|
||||||
value_fn=lambda adguard: adguard.stats.blocked_filtering,
|
value_fn=lambda adguard: adguard.stats.blocked_filtering(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="blocked_percentage",
|
key="blocked_percentage",
|
||||||
name="DNS queries blocked ratio",
|
name="DNS queries blocked ratio",
|
||||||
icon="mdi:magnify-close",
|
icon="mdi:magnify-close",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
value_fn=lambda adguard: adguard.stats.blocked_percentage,
|
value_fn=lambda adguard: adguard.stats.blocked_percentage(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="blocked_parental",
|
key="blocked_parental",
|
||||||
name="Parental control blocked",
|
name="Parental control blocked",
|
||||||
icon="mdi:human-male-girl",
|
icon="mdi:human-male-girl",
|
||||||
native_unit_of_measurement="requests",
|
native_unit_of_measurement="requests",
|
||||||
value_fn=lambda adguard: adguard.stats.replaced_parental,
|
value_fn=lambda adguard: adguard.stats.replaced_parental(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="blocked_safebrowsing",
|
key="blocked_safebrowsing",
|
||||||
name="Safe browsing blocked",
|
name="Safe browsing blocked",
|
||||||
icon="mdi:shield-half-full",
|
icon="mdi:shield-half-full",
|
||||||
native_unit_of_measurement="requests",
|
native_unit_of_measurement="requests",
|
||||||
value_fn=lambda adguard: adguard.stats.replaced_safebrowsing,
|
value_fn=lambda adguard: adguard.stats.replaced_safebrowsing(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="enforced_safesearch",
|
key="enforced_safesearch",
|
||||||
name="Safe searches enforced",
|
name="Safe searches enforced",
|
||||||
icon="mdi:shield-search",
|
icon="mdi:shield-search",
|
||||||
native_unit_of_measurement="requests",
|
native_unit_of_measurement="requests",
|
||||||
value_fn=lambda adguard: adguard.stats.replaced_safesearch,
|
value_fn=lambda adguard: adguard.stats.replaced_safesearch(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="average_speed",
|
key="average_speed",
|
||||||
name="Average processing speed",
|
name="Average processing speed",
|
||||||
icon="mdi:speedometer",
|
icon="mdi:speedometer",
|
||||||
native_unit_of_measurement=TIME_MILLISECONDS,
|
native_unit_of_measurement=TIME_MILLISECONDS,
|
||||||
value_fn=lambda adguard: adguard.stats.avg_processing_time,
|
value_fn=lambda adguard: adguard.stats.avg_processing_time(),
|
||||||
),
|
),
|
||||||
AdGuardHomeEntityDescription(
|
AdGuardHomeEntityDescription(
|
||||||
key="rules_count",
|
key="rules_count",
|
||||||
name="Rules count",
|
name="Rules count",
|
||||||
icon="mdi:counter",
|
icon="mdi:counter",
|
||||||
native_unit_of_measurement="rules",
|
native_unit_of_measurement="rules",
|
||||||
value_fn=lambda adguard: adguard.stats.avg_processing_time,
|
value_fn=lambda adguard: adguard.filtering.rules_count(allowlist=False),
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -144,7 +144,7 @@ class AdGuardHomeSensor(AdGuardHomeEntity, SensorEntity):
|
||||||
|
|
||||||
async def _adguard_update(self) -> None:
|
async def _adguard_update(self) -> None:
|
||||||
"""Update AdGuard Home entity."""
|
"""Update AdGuard Home entity."""
|
||||||
value = await self.entity_description.value_fn(self.adguard)()
|
value = await self.entity_description.value_fn(self.adguard)
|
||||||
self._attr_native_value = value
|
self._attr_native_value = value
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
self._attr_native_value = f"{value:.2f}"
|
self._attr_native_value = f"{value:.2f}"
|
||||||
|
|
Loading…
Reference in New Issue