mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Add diagnostics to Zonneplan (#180954)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Diagnostics support for the Zonneplan integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_EMAIL, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import ZonneplanConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_EMAIL,
|
||||
CONF_TOKEN,
|
||||
"access_token",
|
||||
"refresh_token",
|
||||
"email",
|
||||
"first_name",
|
||||
"full_name",
|
||||
"initials",
|
||||
"street",
|
||||
"number",
|
||||
"addition",
|
||||
"zipcode",
|
||||
"city",
|
||||
"ean",
|
||||
"serial_number",
|
||||
"uuid",
|
||||
"external_contract_id",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ZonneplanConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = entry.runtime_data.data
|
||||
|
||||
return async_redact_data(
|
||||
{
|
||||
"entry_data": dict(entry.data),
|
||||
"account": data.account.to_dict(),
|
||||
"connections": [
|
||||
connection.to_dict()
|
||||
for connection in data.account.connections
|
||||
if data.account.connections is not None and connection is not None
|
||||
],
|
||||
"electricity_prices": (
|
||||
data.electricity_prices.to_dict() if data.electricity_prices else None
|
||||
),
|
||||
"gas_prices": data.gas_prices.to_dict() if data.gas_prices else None,
|
||||
},
|
||||
TO_REDACT,
|
||||
)
|
||||
@@ -47,7 +47,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: todo
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
docs-data-update: todo
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
"""Tests for the Zonneplan diagnostics platform."""
|
||||
|
||||
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,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the diagnostics for a config entry."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user