diff --git a/homeassistant/components/webmin/diagnostics.py b/homeassistant/components/webmin/diagnostics.py new file mode 100644 index 00000000000000..86e2c9eef62eb8 --- /dev/null +++ b/homeassistant/components/webmin/diagnostics.py @@ -0,0 +1,35 @@ +"""Diagnostics support for Webmin.""" +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME +from homeassistant.core import HomeAssistant + +from .const import DOMAIN +from .coordinator import WebminUpdateCoordinator + +TO_REDACT = { + CONF_HOST, + CONF_UNIQUE_ID, + CONF_USERNAME, + CONF_PASSWORD, + "address", + "address6", + "ether", + "broadcast", + "device", + "dir", + "title", + "entry_id", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: WebminUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + return async_redact_data( + {"entry": entry.as_dict(), "data": coordinator.data}, TO_REDACT + ) diff --git a/tests/components/webmin/snapshots/test_diagnostics.ambr b/tests/components/webmin/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000000..f227f6332fe252 --- /dev/null +++ b/tests/components/webmin/snapshots/test_diagnostics.ambr @@ -0,0 +1,138 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'data': dict({ + 'active_interfaces': list([ + dict({ + 'address': '**REDACTED**', + 'address6': '**REDACTED**', + 'broadcast': '**REDACTED**', + 'edit': 1, + 'fullname': 'lo', + 'index': 0, + 'mtu': 65536, + 'name': 'lo', + 'netmask': '255.0.0.0', + 'netmask6': list([ + 128, + ]), + 'scope6': list([ + 'host', + ]), + 'up': 1, + }), + dict({ + 'address6': '**REDACTED**', + 'edit': 1, + 'ether': '**REDACTED**', + 'fullname': 'enp6s0', + 'index': 1, + 'mtu': 1500, + 'name': 'enp6s0', + 'netmask6': list([ + ]), + 'scope6': list([ + ]), + 'up': 1, + }), + dict({ + 'address': '**REDACTED**', + 'address6': '**REDACTED**', + 'broadcast': '**REDACTED**', + 'edit': 1, + 'ether': '**REDACTED**', + 'fullname': 'eno1', + 'index': 2, + 'mtu': 1500, + 'name': 'eno1', + 'netmask': '255.255.255.0', + 'netmask6': list([ + 64, + ]), + 'scope6': list([ + 'link', + ]), + 'up': 1, + }), + ]), + 'free_space': 8641328926720, + 'fs': list([ + dict({ + 'device': '**REDACTED**', + 'dir': '**REDACTED**', + 'free': 174511820800, + 'ifree': 15091734, + 'itotal': 15482880, + 'iused': 391146, + 'iused_percent': 3, + 'total': 248431161344, + 'type': 'ext4', + 'used': 61225123840, + 'used_percent': 26, + }), + dict({ + 'device': '**REDACTED**', + 'dir': '**REDACTED**', + 'free': 1044483624960, + 'ifree': 183131475, + 'itotal': 183140352, + 'iused': 8877, + 'iused_percent': 1, + 'total': 5952635744256, + 'type': 'ext4', + 'used': 4608079593472, + 'used_percent': 82, + }), + dict({ + 'device': '**REDACTED**', + 'dir': '**REDACTED**', + 'free': 7422333480960, + 'ifree': 362787383, + 'itotal': 366198784, + 'iused': 3411401, + 'iused_percent': 1, + 'total': 11903838912512, + 'type': 'ext4', + 'used': 3881508986880, + 'used_percent': 35, + }), + ]), + 'load_15m': 1.0, + 'load_1m': 0.98, + 'load_5m': 1.02, + 'mem_free': 26162544, + 'mem_total': 32767008, + 'swap_free': 1953088, + 'swap_total': 1953088, + 'total_space': 18104905818112, + 'uptime': dict({ + 'days': 3, + 'minutes': 23, + 'seconds': 12, + }), + 'used_space': 8550813704192, + }), + 'entry': dict({ + 'data': dict({ + }), + 'disabled_by': None, + 'domain': 'webmin', + 'entry_id': '**REDACTED**', + 'minor_version': 1, + 'options': dict({ + 'host': '**REDACTED**', + 'password': '**REDACTED**', + 'port': 10000, + 'ssl': True, + 'username': '**REDACTED**', + 'verify_ssl': False, + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': '**REDACTED**', + 'unique_id': None, + 'version': 1, + }), + }) +# --- diff --git a/tests/components/webmin/test_diagnostics.py b/tests/components/webmin/test_diagnostics.py new file mode 100644 index 00000000000000..33a349878d1b83 --- /dev/null +++ b/tests/components/webmin/test_diagnostics.py @@ -0,0 +1,23 @@ +"""Tests for the diagnostics data provided by the Webmin integration.""" +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from .conftest import async_init_integration + +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: + """Test diagnostics.""" + assert ( + await get_diagnostics_for_config_entry( + hass, hass_client, await async_init_integration(hass) + ) + == snapshot + )