Use entry.as_dict() in IQVIA diagnostics (#80113)

This commit is contained in:
Aaron Bach 2022-10-11 10:13:58 -06:00 committed by GitHub
parent 0f002e7044
commit c05390e09b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 39 deletions

View File

@ -3,11 +3,32 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import DOMAIN from .const import CONF_ZIP_CODE, DOMAIN
CONF_CITY = "City"
CONF_DISPLAY_LOCATION = "DisplayLocation"
CONF_MARKET = "Market"
CONF_TITLE = "title"
CONF_ZIP_CAP = "ZIP"
CONF_STATE_CAP = "State"
TO_REDACT = {
CONF_CITY,
CONF_DISPLAY_LOCATION,
CONF_MARKET,
CONF_STATE_CAP,
# Config entry title and unique ID may contain sensitive data:
CONF_TITLE,
CONF_UNIQUE_ID,
CONF_ZIP_CAP,
CONF_ZIP_CODE,
}
async def async_get_config_entry_diagnostics( async def async_get_config_entry_diagnostics(
@ -17,12 +38,12 @@ async def async_get_config_entry_diagnostics(
coordinators: dict[str, DataUpdateCoordinator] = hass.data[DOMAIN][entry.entry_id] coordinators: dict[str, DataUpdateCoordinator] = hass.data[DOMAIN][entry.entry_id]
return { return {
"entry": { "entry": async_redact_data(entry.as_dict(), TO_REDACT),
"title": entry.title, "data": async_redact_data(
"data": dict(entry.data), {
}, data_type: coordinator.data
"data": { for data_type, coordinator in coordinators.items()
data_type: coordinator.data },
for data_type, coordinator in coordinators.items() TO_REDACT,
}, ),
} }

View File

@ -1,4 +1,6 @@
"""Test IQVIA diagnostics.""" """Test IQVIA diagnostics."""
from homeassistant.components.diagnostics import REDACTED
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
@ -6,19 +8,26 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": { "entry": {
"title": "Mock Title", "entry_id": config_entry.entry_id,
"data": { "version": 1,
"zip_code": "12345", "domain": "iqvia",
}, "title": REDACTED,
"data": {"zip_code": REDACTED},
"options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
}, },
"data": { "data": {
"allergy_average_forecasted": { "allergy_average_forecasted": {
"Type": "pollen", "Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00", "ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": { "Location": {
"ZIP": "12345", "ZIP": REDACTED,
"City": "SCHENECTADY", "City": REDACTED,
"State": "NY", "State": REDACTED,
"periods": [ "periods": [
{"Period": "2018-06-12T13:47:12.897", "Index": 6.6}, {"Period": "2018-06-12T13:47:12.897", "Index": 6.6},
{"Period": "2018-06-13T13:47:12.897", "Index": 6.3}, {"Period": "2018-06-13T13:47:12.897", "Index": 6.3},
@ -26,16 +35,16 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
{"Period": "2018-06-15T13:47:12.897", "Index": 7.6}, {"Period": "2018-06-15T13:47:12.897", "Index": 7.6},
{"Period": "2018-06-16T13:47:12.897", "Index": 7.3}, {"Period": "2018-06-16T13:47:12.897", "Index": 7.3},
], ],
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
}, },
}, },
"allergy_index": { "allergy_index": {
"Type": "pollen", "Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00", "ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": { "Location": {
"ZIP": "12345", "ZIP": REDACTED,
"City": "SCHENECTADY", "City": REDACTED,
"State": "NY", "State": REDACTED,
"periods": [ "periods": [
{ {
"Triggers": [ "Triggers": [
@ -113,12 +122,12 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Index": 6.3, "Index": 6.3,
}, },
], ],
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
}, },
}, },
"allergy_outlook": { "allergy_outlook": {
"Market": "SCHENECTADY, CO", "Market": REDACTED,
"ZIP": "12345", "ZIP": REDACTED,
"TrendID": 4, "TrendID": 4,
"Trend": "subsiding", "Trend": "subsiding",
"Outlook": "The amount of pollen in the air for Wednesday...", "Outlook": "The amount of pollen in the air for Wednesday...",
@ -128,9 +137,9 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Type": "asthma", "Type": "asthma",
"ForecastDate": "2018-10-28T00:00:00-04:00", "ForecastDate": "2018-10-28T00:00:00-04:00",
"Location": { "Location": {
"ZIP": "12345", "ZIP": REDACTED,
"City": "SCHENECTADY", "City": REDACTED,
"State": "NY", "State": REDACTED,
"periods": [ "periods": [
{ {
"Period": "2018-10-28T05:45:01.45", "Period": "2018-10-28T05:45:01.45",
@ -154,16 +163,16 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Idx": "5.5", "Idx": "5.5",
}, },
], ],
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
}, },
}, },
"asthma_index": { "asthma_index": {
"Type": "asthma", "Type": "asthma",
"ForecastDate": "2018-10-29T00:00:00-04:00", "ForecastDate": "2018-10-29T00:00:00-04:00",
"Location": { "Location": {
"ZIP": "12345", "ZIP": REDACTED,
"City": "SCHENECTADY", "City": REDACTED,
"State": "NY", "State": REDACTED,
"periods": [ "periods": [
{ {
"Triggers": [ "Triggers": [
@ -225,32 +234,32 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Idx": "4.6", "Idx": "4.6",
}, },
], ],
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
}, },
}, },
"disease_average_forecasted": { "disease_average_forecasted": {
"Type": "cold", "Type": "cold",
"ForecastDate": "2018-06-12T00:00:00-04:00", "ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": { "Location": {
"ZIP": "12345", "ZIP": REDACTED,
"City": "SCHENECTADY", "City": REDACTED,
"State": "NY", "State": REDACTED,
"periods": [ "periods": [
{"Period": "2018-06-12T05:13:51.817", "Index": 2.4}, {"Period": "2018-06-12T05:13:51.817", "Index": 2.4},
{"Period": "2018-06-13T05:13:51.817", "Index": 2.5}, {"Period": "2018-06-13T05:13:51.817", "Index": 2.5},
{"Period": "2018-06-14T05:13:51.817", "Index": 2.5}, {"Period": "2018-06-14T05:13:51.817", "Index": 2.5},
{"Period": "2018-06-15T05:13:51.817", "Index": 2.5}, {"Period": "2018-06-15T05:13:51.817", "Index": 2.5},
], ],
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
}, },
}, },
"disease_index": { "disease_index": {
"ForecastDate": "2019-04-07T00:00:00-04:00", "ForecastDate": "2019-04-07T00:00:00-04:00",
"Location": { "Location": {
"City": "SCHENECTADY", "City": REDACTED,
"DisplayLocation": "Schenectady, NY", "DisplayLocation": REDACTED,
"State": "NY", "State": REDACTED,
"ZIP": "12345", "ZIP": REDACTED,
"periods": [ "periods": [
{ {
"Idx": "6.8", "Idx": "6.8",