mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add diagnostics for Pure Energie integration (#77151)
* Add diagnostics for Pure Energie integration * Update test after feedback
This commit is contained in:
parent
f0646dfb42
commit
29b502bb0a
36
homeassistant/components/pure_energie/diagnostics.py
Normal file
36
homeassistant/components/pure_energie/diagnostics.py
Normal file
@ -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),
|
||||
},
|
||||
}
|
41
tests/components/pure_energie/test_diagnostics.py
Normal file
41
tests/components/pure_energie/test_diagnostics.py
Normal file
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user