Use `entry.as_dict()` in AirVisual diagnostics (#80109)

pull/80121/head
Aaron Bach 2022-10-11 09:26:57 -06:00 committed by GitHub
parent f2207af1c9
commit b41cd57c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions

View File

@ -5,13 +5,20 @@ 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, CONF_STATE
from homeassistant.const import (
CONF_API_KEY,
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_STATE,
CONF_UNIQUE_ID,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import CONF_CITY, CONF_COUNTRY, DOMAIN
CONF_COORDINATES = "coordinates"
CONF_TITLE = "title"
TO_REDACT = {
CONF_API_KEY,
@ -21,6 +28,9 @@ TO_REDACT = {
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_STATE,
# Config entry title and unique ID may contain sensitive data:
CONF_TITLE,
CONF_UNIQUE_ID,
}
@ -31,10 +41,6 @@ async def async_get_config_entry_diagnostics(
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
return {
"entry": {
"title": entry.title,
"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(coordinator.data["data"], TO_REDACT),
}

View File

@ -8,20 +8,28 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_airvisua
"""Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": {
"title": "Mock Title",
"entry_id": config_entry.entry_id,
"version": 2,
"domain": "airvisual",
"title": REDACTED,
"data": {
"api_key": REDACTED,
"integration_type": "Geographical Location by Latitude/Longitude",
"api_key": REDACTED,
"latitude": REDACTED,
"longitude": REDACTED,
},
"options": {
"show_on_map": True,
},
"options": {"show_on_map": True},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
},
"data": {
"city": REDACTED,
"state": REDACTED,
"country": REDACTED,
"location": {"type": "Point", "coordinates": REDACTED},
"current": {
"weather": {
"ts": "2021-09-03T21:00:00.000Z",
@ -40,10 +48,5 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_airvisua
"maincn": "p2",
},
},
"location": {
"coordinates": REDACTED,
"type": "Point",
},
"state": REDACTED,
},
}