@@ -30,9 +30,7 @@ async def async_setup_entry(
|
||||
AdGuardQueriesCounterSensor(coordinator, api),
|
||||
AdGuardBlockedCounterSensor(coordinator, api),
|
||||
AdGuardBlockingPercentageSensor(coordinator, api),
|
||||
AdGuardRuleCountSensor(coordinator, api),
|
||||
AdGuardClientCountSensor(coordinator, api),
|
||||
AdGuardUpstreamAverageTimeSensor(coordinator, api),
|
||||
]
|
||||
|
||||
async_add_entities(entities)
|
||||
@@ -71,16 +69,6 @@ class AdGuardQueriesCounterSensor(AdGuardBaseSensor):
|
||||
stats = self.coordinator.statistics
|
||||
return stats.get("num_dns_queries", 0)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return additional state attributes."""
|
||||
stats = self.coordinator.statistics
|
||||
return {
|
||||
"queries_today": stats.get("num_dns_queries_today", 0),
|
||||
"queries_blocked_today": stats.get("num_blocked_filtering_today", 0),
|
||||
"last_updated": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
|
||||
|
||||
class AdGuardBlockedCounterSensor(AdGuardBaseSensor):
|
||||
"""Sensor to track blocked queries count."""
|
||||
@@ -128,25 +116,6 @@ class AdGuardBlockingPercentageSensor(AdGuardBaseSensor):
|
||||
return round(percentage, 2)
|
||||
|
||||
|
||||
class AdGuardRuleCountSensor(AdGuardBaseSensor):
|
||||
"""Sensor to track filtering rules count."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_rules_count"
|
||||
self._attr_name = "AdGuard Rules Count"
|
||||
self._attr_icon = "mdi:format-list-numbered"
|
||||
self._attr_state_class = SensorStateClass.MEASUREMENT
|
||||
self._attr_native_unit_of_measurement = "rules"
|
||||
|
||||
@property
|
||||
def native_value(self) -> int | None:
|
||||
"""Return the state of the sensor."""
|
||||
stats = self.coordinator.statistics
|
||||
return stats.get("filtering_rules_count", 0)
|
||||
|
||||
|
||||
class AdGuardClientCountSensor(AdGuardBaseSensor):
|
||||
"""Sensor to track active clients count."""
|
||||
|
||||
@@ -163,23 +132,3 @@ class AdGuardClientCountSensor(AdGuardBaseSensor):
|
||||
def native_value(self) -> int | None:
|
||||
"""Return the state of the sensor."""
|
||||
return len(self.coordinator.clients)
|
||||
|
||||
|
||||
class AdGuardUpstreamAverageTimeSensor(AdGuardBaseSensor):
|
||||
"""Sensor to track upstream servers average response time."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_upstream_response_time"
|
||||
self._attr_name = "AdGuard Upstream Response Time"
|
||||
self._attr_icon = "mdi:timer"
|
||||
self._attr_state_class = SensorStateClass.MEASUREMENT
|
||||
self._attr_native_unit_of_measurement = "ms"
|
||||
self._attr_device_class = SensorDeviceClass.DURATION
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
stats = self.coordinator.statistics
|
||||
return stats.get("avg_processing_time", 0)
|
||||
|
Reference in New Issue
Block a user