From f92da26c042bc85290e3bcd9eb1737c338676d08 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 11 Oct 2022 13:03:48 -0600 Subject: [PATCH] Add config entry to Ridwell diagnostics (#80120) --- .../components/ridwell/diagnostics.py | 24 ++++++++++++++++--- tests/components/ridwell/test_diagnostics.py | 17 ++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/ridwell/diagnostics.py b/homeassistant/components/ridwell/diagnostics.py index 3f29165842f..b4832770409 100644 --- a/homeassistant/components/ridwell/diagnostics.py +++ b/homeassistant/components/ridwell/diagnostics.py @@ -4,12 +4,24 @@ from __future__ import annotations import dataclasses from typing import Any +from homeassistant.components.diagnostics import async_redact_data from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME from homeassistant.core import HomeAssistant from . import RidwellData from .const import DOMAIN +CONF_TITLE = "title" + +TO_REDACT = { + CONF_PASSWORD, + # Config entry title and unique ID may contain sensitive data: + CONF_TITLE, + CONF_UNIQUE_ID, + CONF_USERNAME, +} + async def async_get_config_entry_diagnostics( hass: HomeAssistant, entry: ConfigEntry @@ -17,6 +29,12 @@ async def async_get_config_entry_diagnostics( """Return diagnostics for a config entry.""" data: RidwellData = hass.data[DOMAIN][entry.entry_id] - return { - "data": [dataclasses.asdict(event) for event in data.coordinator.data.values()] - } + return async_redact_data( + { + "entry": entry.as_dict(), + "data": [ + dataclasses.asdict(event) for event in data.coordinator.data.values() + ], + }, + TO_REDACT, + ) diff --git a/tests/components/ridwell/test_diagnostics.py b/tests/components/ridwell/test_diagnostics.py index 8427fa13e11..96d1531ac84 100644 --- a/tests/components/ridwell/test_diagnostics.py +++ b/tests/components/ridwell/test_diagnostics.py @@ -1,10 +1,25 @@ """Test Ridwell diagnostics.""" +from homeassistant.components.diagnostics import REDACTED + from tests.components.diagnostics import get_diagnostics_for_config_entry async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell): """Test config entry diagnostics.""" assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { + "entry": { + "entry_id": config_entry.entry_id, + "version": 2, + "domain": "ridwell", + "title": REDACTED, + "data": {"username": REDACTED, "password": REDACTED}, + "options": {}, + "pref_disable_new_entities": False, + "pref_disable_polling": False, + "source": "user", + "unique_id": REDACTED, + "disabled_by": None, + }, "data": [ { "_async_request": None, @@ -31,5 +46,5 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell) "repr": "", }, } - ] + ], }