Add config entry to Ridwell diagnostics (#80120)
This commit is contained in:
parent
cc13641f29
commit
f92da26c04
2 changed files with 37 additions and 4 deletions
|
@ -4,12 +4,24 @@ from __future__ import annotations
|
||||||
import dataclasses
|
import dataclasses
|
||||||
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_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import RidwellData
|
from . import RidwellData
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
CONF_TITLE = "title"
|
||||||
|
|
||||||
|
TO_REDACT = {
|
||||||
|
CONF_PASSWORD,
|
||||||
|
# Config entry title and unique ID may contain sensitive data:
|
||||||
|
CONF_TITLE,
|
||||||
|
CONF_UNIQUE_ID,
|
||||||
|
CONF_USERNAME,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
@ -17,6 +29,12 @@ async def async_get_config_entry_diagnostics(
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
data: RidwellData = hass.data[DOMAIN][entry.entry_id]
|
data: RidwellData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
return {
|
return async_redact_data(
|
||||||
"data": [dataclasses.asdict(event) for event in data.coordinator.data.values()]
|
{
|
||||||
}
|
"entry": entry.as_dict(),
|
||||||
|
"data": [
|
||||||
|
dataclasses.asdict(event) for event in data.coordinator.data.values()
|
||||||
|
],
|
||||||
|
},
|
||||||
|
TO_REDACT,
|
||||||
|
)
|
||||||
|
|
|
@ -1,10 +1,25 @@
|
||||||
"""Test Ridwell diagnostics."""
|
"""Test Ridwell 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
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell):
|
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell):
|
||||||
"""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_id": config_entry.entry_id,
|
||||||
|
"version": 2,
|
||||||
|
"domain": "ridwell",
|
||||||
|
"title": REDACTED,
|
||||||
|
"data": {"username": REDACTED, "password": REDACTED},
|
||||||
|
"options": {},
|
||||||
|
"pref_disable_new_entities": False,
|
||||||
|
"pref_disable_polling": False,
|
||||||
|
"source": "user",
|
||||||
|
"unique_id": REDACTED,
|
||||||
|
"disabled_by": None,
|
||||||
|
},
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"_async_request": None,
|
"_async_request": None,
|
||||||
|
@ -31,5 +46,5 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell)
|
||||||
"repr": "<EventState.INITIALIZED: 'initialized'>",
|
"repr": "<EventState.INITIALIZED: 'initialized'>",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue