diff --git a/homeassistant/components/pure_energie/diagnostics.py b/homeassistant/components/pure_energie/diagnostics.py new file mode 100644 index 0000000000000000000000000000000000000000..b2e071d58cd727eb0af4e149cce6eb77d0972f88 --- /dev/null +++ b/homeassistant/components/pure_energie/diagnostics.py @@ -0,0 +1,36 @@ +"""Diagnostics support for Pure Energie.""" +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.const import CONF_HOST +from homeassistant.core import HomeAssistant + +from . import PureEnergieDataUpdateCoordinator +from .const import DOMAIN + +TO_REDACT = { + CONF_HOST, + "n2g_id", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: PureEnergieDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + + return { + "entry": { + "title": entry.title, + "data": async_redact_data(entry.data, TO_REDACT), + }, + "data": { + "device": async_redact_data(asdict(coordinator.data.device), TO_REDACT), + "smartbridge": asdict(coordinator.data.smartbridge), + }, + } diff --git a/tests/components/pure_energie/test_diagnostics.py b/tests/components/pure_energie/test_diagnostics.py new file mode 100644 index 0000000000000000000000000000000000000000..afb76724447ec7a26c3eb34c9bf213ab0ed01d0a --- /dev/null +++ b/tests/components/pure_energie/test_diagnostics.py @@ -0,0 +1,41 @@ +"""Tests for the diagnostics data provided by the Pure Energie integration.""" +from aiohttp import ClientSession + +from homeassistant.components.diagnostics import REDACTED +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSession, + init_integration: MockConfigEntry, +) -> None: + """Test diagnostics.""" + assert await get_diagnostics_for_config_entry( + hass, hass_client, init_integration + ) == { + "entry": { + "title": "home", + "data": { + "host": REDACTED, + }, + }, + "data": { + "device": { + "batch": "SBP-HMX-210318", + "firmware": "1.6.16", + "hardware": 1, + "manufacturer": "NET2GRID", + "model": "SBWF3102", + "n2g_id": REDACTED, + }, + "smartbridge": { + "energy_consumption_total": 17762.1, + "energy_production_total": 21214.6, + "power_flow": 338, + }, + }, + }