From d4465e4e69eab00536f4776b5367dfcea9f9c87a Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 11 Oct 2022 12:15:21 -0600 Subject: [PATCH] Use `entry.as_dict()` in WattTime diagnostics (#80122) --- homeassistant/components/watttime/diagnostics.py | 15 ++++++++++----- tests/components/watttime/test_diagnostics.py | 13 +++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/watttime/diagnostics.py b/homeassistant/components/watttime/diagnostics.py index 080c7c37b07..2808e8e3c35 100644 --- a/homeassistant/components/watttime/diagnostics.py +++ b/homeassistant/components/watttime/diagnostics.py @@ -9,17 +9,25 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_PASSWORD, + CONF_UNIQUE_ID, CONF_USERNAME, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from .const import DOMAIN +from .const import CONF_BALANCING_AUTHORITY, CONF_BALANCING_AUTHORITY_ABBREV, DOMAIN + +CONF_TITLE = "title" TO_REDACT = { + CONF_BALANCING_AUTHORITY, + CONF_BALANCING_AUTHORITY_ABBREV, CONF_LATITUDE, CONF_LONGITUDE, CONF_PASSWORD, + # Config entry title and unique ID may contain sensitive data: + CONF_TITLE, + CONF_UNIQUE_ID, CONF_USERNAME, } @@ -32,10 +40,7 @@ async def async_get_config_entry_diagnostics( return async_redact_data( { - "entry": { - "data": dict(entry.data), - "options": dict(entry.options), - }, + "entry": entry.as_dict(), "data": coordinator.data, }, TO_REDACT, diff --git a/tests/components/watttime/test_diagnostics.py b/tests/components/watttime/test_diagnostics.py index 0d8d87203bb..e5aaf65e920 100644 --- a/tests/components/watttime/test_diagnostics.py +++ b/tests/components/watttime/test_diagnostics.py @@ -8,15 +8,24 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_watttime """Test config entry diagnostics.""" assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { "entry": { + "entry_id": config_entry.entry_id, + "version": 1, + "domain": "watttime", + "title": REDACTED, "data": { "username": REDACTED, "password": REDACTED, "latitude": REDACTED, "longitude": REDACTED, - "balancing_authority": "PJM New Jersey", - "balancing_authority_abbreviation": "PJM_NJ", + "balancing_authority": REDACTED, + "balancing_authority_abbreviation": REDACTED, }, "options": {}, + "pref_disable_new_entities": False, + "pref_disable_polling": False, + "source": "user", + "unique_id": REDACTED, + "disabled_by": None, }, "data": { "freq": "300",