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

pull/80121/head
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 homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
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(
@ -17,12 +38,12 @@ async def async_get_config_entry_diagnostics(
coordinators: dict[str, DataUpdateCoordinator] = hass.data[DOMAIN][entry.entry_id]
return {
"entry": {
"title": entry.title,
"data": dict(entry.data),
},
"data": {
data_type: coordinator.data
for data_type, coordinator in coordinators.items()
},
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
"data": async_redact_data(
{
data_type: coordinator.data
for data_type, coordinator in coordinators.items()
},
TO_REDACT,
),
}

View File

@ -1,4 +1,6 @@
"""Test IQVIA diagnostics."""
from homeassistant.components.diagnostics import REDACTED
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."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": {
"title": "Mock Title",
"data": {
"zip_code": "12345",
},
"entry_id": config_entry.entry_id,
"version": 1,
"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": {
"allergy_average_forecasted": {
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"ZIP": REDACTED,
"City": REDACTED,
"State": REDACTED,
"periods": [
{"Period": "2018-06-12T13:47:12.897", "Index": 6.6},
{"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-16T13:47:12.897", "Index": 7.3},
],
"DisplayLocation": "Schenectady, NY",
"DisplayLocation": REDACTED,
},
},
"allergy_index": {
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"ZIP": REDACTED,
"City": REDACTED,
"State": REDACTED,
"periods": [
{
"Triggers": [
@ -113,12 +122,12 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Index": 6.3,
},
],
"DisplayLocation": "Schenectady, NY",
"DisplayLocation": REDACTED,
},
},
"allergy_outlook": {
"Market": "SCHENECTADY, CO",
"ZIP": "12345",
"Market": REDACTED,
"ZIP": REDACTED,
"TrendID": 4,
"Trend": "subsiding",
"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",
"ForecastDate": "2018-10-28T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"ZIP": REDACTED,
"City": REDACTED,
"State": REDACTED,
"periods": [
{
"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",
},
],
"DisplayLocation": "Schenectady, NY",
"DisplayLocation": REDACTED,
},
},
"asthma_index": {
"Type": "asthma",
"ForecastDate": "2018-10-29T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"ZIP": REDACTED,
"City": REDACTED,
"State": REDACTED,
"periods": [
{
"Triggers": [
@ -225,32 +234,32 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"Idx": "4.6",
},
],
"DisplayLocation": "Schenectady, NY",
"DisplayLocation": REDACTED,
},
},
"disease_average_forecasted": {
"Type": "cold",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"ZIP": REDACTED,
"City": REDACTED,
"State": REDACTED,
"periods": [
{"Period": "2018-06-12T05:13:51.817", "Index": 2.4},
{"Period": "2018-06-13T05: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},
],
"DisplayLocation": "Schenectady, NY",
"DisplayLocation": REDACTED,
},
},
"disease_index": {
"ForecastDate": "2019-04-07T00:00:00-04:00",
"Location": {
"City": "SCHENECTADY",
"DisplayLocation": "Schenectady, NY",
"State": "NY",
"ZIP": "12345",
"City": REDACTED,
"DisplayLocation": REDACTED,
"State": REDACTED,
"ZIP": REDACTED,
"periods": [
{
"Idx": "6.8",