From 4ea46bf8418f329074bedac54635be2bc0076bbe Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 11 Oct 2022 10:17:03 -0600 Subject: [PATCH] Use `entry.as_dict()` in OpenUV diagnostics (#80115) --- .../components/openuv/diagnostics.py | 16 ++++++++---- tests/components/openuv/test_diagnostics.py | 26 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/openuv/diagnostics.py b/homeassistant/components/openuv/diagnostics.py index 02b56ce0e90..30443dd90fc 100644 --- a/homeassistant/components/openuv/diagnostics.py +++ b/homeassistant/components/openuv/diagnostics.py @@ -5,18 +5,27 @@ from typing import Any from homeassistant.components.diagnostics import async_redact_data from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE +from homeassistant.const import ( + CONF_API_KEY, + CONF_LATITUDE, + CONF_LONGITUDE, + CONF_UNIQUE_ID, +) from homeassistant.core import HomeAssistant from . import OpenUV from .const import DOMAIN CONF_COORDINATES = "coordinates" +CONF_TITLE = "title" TO_REDACT = { CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, + # Config entry title and unique ID may contain sensitive data: + CONF_TITLE, + CONF_UNIQUE_ID, } @@ -27,9 +36,6 @@ async def async_get_config_entry_diagnostics( openuv: OpenUV = hass.data[DOMAIN][entry.entry_id] return { - "entry": { - "data": async_redact_data(entry.data, TO_REDACT), - "options": async_redact_data(entry.options, TO_REDACT), - }, + "entry": async_redact_data(entry.as_dict(), TO_REDACT), "data": async_redact_data(openuv.data, TO_REDACT), } diff --git a/tests/components/openuv/test_diagnostics.py b/tests/components/openuv/test_diagnostics.py index 1196045300b..b64c48d153b 100644 --- a/tests/components/openuv/test_diagnostics.py +++ b/tests/components/openuv/test_diagnostics.py @@ -12,18 +12,30 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_openuv): ) assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { "entry": { + "entry_id": config_entry.entry_id, + "version": 2, + "domain": "openuv", + "title": REDACTED, "data": { "api_key": REDACTED, "elevation": 0, "latitude": REDACTED, "longitude": REDACTED, }, - "options": { - "from_window": 3.5, - "to_window": 3.5, - }, + "options": {"from_window": 3.5, "to_window": 3.5}, + "pref_disable_new_entities": False, + "pref_disable_polling": False, + "source": "user", + "unique_id": REDACTED, + "disabled_by": None, }, "data": { + "protection_window": { + "from_time": "2018-07-30T15:17:49.750Z", + "from_uv": 3.2509, + "to_time": "2018-07-30T22:47:49.750Z", + "to_uv": 3.6483, + }, "uv": { "uv": 8.2342, "uv_time": "2018-07-30T20:53:06.302Z", @@ -62,11 +74,5 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_openuv): }, }, }, - "protection_window": { - "from_time": "2018-07-30T15:17:49.750Z", - "from_uv": 3.2509, - "to_time": "2018-07-30T22:47:49.750Z", - "to_uv": 3.6483, - }, }, }