Skip to content
Snippets Groups Projects
Unverified Commit 29b502bb authored by Klaas Schoute's avatar Klaas Schoute Committed by GitHub
Browse files

Add diagnostics for Pure Energie integration (#77151)

* Add diagnostics for Pure Energie integration

* Update test after feedback
parent f0646dfb
No related branches found
No related tags found
No related merge requests found
"""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),
},
}
"""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,
},
},
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment