Add diagnostics to AdGuard Home (#189118)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Joost Lekkerkerker
2026-10-28 14:09:27 +01:00
committed by GitHub
co-authored by Claude
parent 551882a447
commit 768cd699ef
3 changed files with 168 additions and 0 deletions
@@ -0,0 +1,77 @@
"""Diagnostics support for AdGuard Home."""
from typing import Any
from homeassistant.const import CONF_SSL, CONF_VERIFY_SSL
from homeassistant.core import HomeAssistant
from .coordinator import AdGuardConfigEntry
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: AdGuardConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
data = entry.runtime_data
state = data.state.data
statistics = data.statistics.data
update = data.update.data
# Addresses, domains, clients and upstreams are left out, as they are private.
return {
"config_entry": {
"source": entry.source,
CONF_SSL: entry.data[CONF_SSL],
CONF_VERIFY_SSL: entry.data[CONF_VERIFY_SSL],
},
"status": {
"version": str(state.status.version),
"supported": state.status.supported,
"running": state.status.running,
"language": state.status.language,
"dhcp_available": state.status.dhcp_available,
"protection_enabled": state.status.protection_enabled,
"protection_resumes_in": (
str(resumes_in)
if (resumes_in := state.status.protection_resumes_in)
else None
),
},
"features": {
"filtering": {
"enabled": state.filtering.enabled,
"update_interval": str(state.filtering.update_interval),
},
"parental": state.parental,
"query_log": {
"enabled": state.query_log.enabled,
"retention": str(state.query_log.retention),
"anonymize_client_ip": state.query_log.anonymize_client_ip,
},
"safe_browsing": state.safe_browsing,
"safe_search": state.safe_search.to_dict(),
},
"statistics": {
"dns_queries": statistics.stats.dns_queries,
"blocked_filtering": statistics.stats.blocked_filtering,
"blocked_safebrowsing": statistics.stats.blocked_safebrowsing,
"blocked_parental": statistics.stats.blocked_parental,
"enforced_safesearch": statistics.stats.enforced_safesearch,
"avg_processing_time": str(statistics.stats.avg_processing_time),
"time_unit": statistics.stats.time_unit,
},
"blocklists": [
{
"id": blocklist.id,
"name": blocklist.name,
"enabled": blocklist.enabled,
"rules_count": blocklist.rules_count,
"last_updated": blocklist.last_updated,
}
for blocklist in statistics.blocklists
],
"update": {
"last_update_success": data.update.last_update_success,
"available": update.to_dict() if update else None,
},
}
@@ -0,0 +1,70 @@
# serializer version: 1
# name: test_diagnostics
dict({
'blocklists': list([
dict({
'enabled': True,
'id': 1,
'last_updated': None,
'name': 'AdGuard DNS filter',
'rules_count': 100,
}),
]),
'config_entry': dict({
'source': 'user',
'ssl': True,
'verify_ssl': True,
}),
'features': dict({
'filtering': dict({
'enabled': True,
'update_interval': '1 day, 0:00:00',
}),
'parental': True,
'query_log': dict({
'anonymize_client_ip': False,
'enabled': True,
'retention': '90 days, 0:00:00',
}),
'safe_browsing': True,
'safe_search': dict({
'bing': False,
'duckduckgo': False,
'ecosia': False,
'enabled': True,
'google': False,
'pixabay': False,
'yandex': False,
'youtube': False,
}),
}),
'statistics': dict({
'avg_processing_time': '0:00:00.031410',
'blocked_filtering': 1337,
'blocked_parental': 13,
'blocked_safebrowsing': 42,
'dns_queries': 666,
'enforced_safesearch': 18,
'time_unit': 'hours',
}),
'status': dict({
'dhcp_available': False,
'language': 'en',
'protection_enabled': True,
'protection_resumes_in': None,
'running': True,
'supported': False,
'version': 'v0.107.50',
}),
'update': dict({
'available': dict({
'announcement': 'AdGuard Home v0.107.59 is now available!',
'announcement_url': 'https://github.com/AdguardTeam/AdGuardHome/releases/tag/v0.107.59',
'can_autoupdate': True,
'disabled': False,
'new_version': 'v0.107.59',
}),
'last_update_success': True,
}),
})
# ---
@@ -0,0 +1,21 @@
"""Tests for the AdGuard Home diagnostics."""
from pytest_homeassistant.common import MockConfigEntry
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
from pytest_homeassistant.typing import ClientSessionGenerator
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
assert (
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
== snapshot
)