Add diagnostics to PI-Hole (#91383)
This commit is contained in:
parent
d5a6840588
commit
fe2c11a698
3 changed files with 108 additions and 0 deletions
28
homeassistant/components/pi_hole/diagnostics.py
Normal file
28
homeassistant/components/pi_hole/diagnostics.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""Diagnostics support for the Pi-hole integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from hole import Hole
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DATA_KEY_API, DOMAIN
|
||||
|
||||
TO_REDACT = {CONF_API_KEY}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
api: Hole = hass.data[DOMAIN][entry.entry_id][DATA_KEY_API]
|
||||
|
||||
return {
|
||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||
"data": api.data,
|
||||
"versions": api.versions,
|
||||
}
|
49
tests/components/pi_hole/snapshots/test_diagnostics.ambr
Normal file
49
tests/components/pi_hole/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,49 @@
|
|||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'ads_blocked_today': 0,
|
||||
'ads_percentage_today': 0,
|
||||
'clients_ever_seen': 0,
|
||||
'dns_queries_today': 0,
|
||||
'domains_being_blocked': 0,
|
||||
'queries_cached': 0,
|
||||
'queries_forwarded': 0,
|
||||
'status': 'disabled',
|
||||
'unique_clients': 0,
|
||||
'unique_domains': 0,
|
||||
}),
|
||||
'entry': dict({
|
||||
'data': dict({
|
||||
'api_key': '**REDACTED**',
|
||||
'host': '1.2.3.4:80',
|
||||
'location': 'admin',
|
||||
'name': 'Pi-Hole',
|
||||
'ssl': False,
|
||||
'verify_ssl': True,
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'pi_hole',
|
||||
'entry_id': 'pi_hole_mock_entry',
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'Mock Title',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
'versions': dict({
|
||||
'FTL_current': 'v5.10',
|
||||
'FTL_latest': 'v5.11',
|
||||
'FTL_update': True,
|
||||
'core_current': 'v5.5',
|
||||
'core_latest': 'v5.6',
|
||||
'core_update': True,
|
||||
'web_current': 'v5.7',
|
||||
'web_latest': 'v5.8',
|
||||
'web_update': True,
|
||||
}),
|
||||
})
|
||||
# ---
|
31
tests/components/pi_hole/test_diagnostics.py
Normal file
31
tests/components/pi_hole/test_diagnostics.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""Test pi_hole component."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import pi_hole
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import CONFIG_DATA_DEFAULTS, _create_mocked_hole, _patch_init_hole
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Tests diagnostics."""
|
||||
mocked_hole = _create_mocked_hole()
|
||||
entry = MockConfigEntry(
|
||||
domain=pi_hole.DOMAIN, data=CONFIG_DATA_DEFAULTS, entry_id="pi_hole_mock_entry"
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
with _patch_init_hole(mocked_hole):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot
|
Loading…
Add table
Reference in a new issue