diff --git a/homeassistant/components/technove/diagnostics.py b/homeassistant/components/technove/diagnostics.py new file mode 100644 index 00000000000..11a530ef263 --- /dev/null +++ b/homeassistant/components/technove/diagnostics.py @@ -0,0 +1,23 @@ +"""Diagnostics support for TechnoVE.""" + +from __future__ import annotations + +from dataclasses import asdict +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .const import DOMAIN +from .coordinator import TechnoVEDataUpdateCoordinator + +TO_REDACT = {"unique_id", "mac_address"} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: TechnoVEDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + return async_redact_data(asdict(coordinator.data.info), TO_REDACT) diff --git a/tests/components/technove/snapshots/test_diagnostics.ambr b/tests/components/technove/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..2e81f124ba5 --- /dev/null +++ b/tests/components/technove/snapshots/test_diagnostics.ambr @@ -0,0 +1,36 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'auto_charge': True, + 'conflict_in_sharing_config': False, + 'current': 23.75, + 'energy_session': 12.34, + 'energy_total': 1234, + 'high_charge_period_active': False, + 'in_sharing_mode': False, + 'is_battery_protected': False, + 'is_session_active': True, + 'is_static_ip': False, + 'is_up_to_date': True, + 'last_charge': ''' + 1701072080,0,17.39 + + ''', + 'mac_address': '**REDACTED**', + 'max_charge_percentage': 0.9, + 'max_current': 24, + 'max_station_current': 32, + 'name': 'TechnoVE Station', + 'network_ssid': 'Connecting...', + 'normal_period_active': False, + 'rssi': -82, + 'status': dict({ + '__type': "", + 'repr': "", + }), + 'time': 1701000000, + 'version': '1.82', + 'voltage_in': 238, + 'voltage_out': 238, + }) +# --- diff --git a/tests/components/technove/test_diagnostics.py b/tests/components/technove/test_diagnostics.py new file mode 100644 index 00000000000..878b084c0c3 --- /dev/null +++ b/tests/components/technove/test_diagnostics.py @@ -0,0 +1,22 @@ +"""Tests for TechnoVE diagnostics.""" + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +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, + init_integration: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, init_integration) + == snapshot + )