Skip to content

Commit abc3604

Browse files
authored
Add diagnostics to Volvo integration (home-assistant#153997)
1 parent 26437bb commit abc3604

File tree

3 files changed

+615
-0
lines changed

3 files changed

+615
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Volvo diagnostics."""
2+
3+
from dataclasses import asdict
4+
from typing import Any
5+
6+
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_API_KEY
7+
from homeassistant.core import HomeAssistant
8+
from homeassistant.helpers.redact import async_redact_data
9+
10+
from .const import CONF_VIN
11+
from .coordinator import VolvoConfigEntry
12+
13+
_TO_REDACT_ENTRY = [
14+
CONF_ACCESS_TOKEN,
15+
CONF_API_KEY,
16+
CONF_VIN,
17+
"id_token",
18+
"refresh_token",
19+
]
20+
21+
_TO_REDACT_DATA = [
22+
"coordinates",
23+
"heading",
24+
"vin",
25+
]
26+
27+
28+
async def async_get_config_entry_diagnostics(
29+
hass: HomeAssistant, entry: VolvoConfigEntry
30+
) -> dict[str, Any]:
31+
"""Return diagnostics for a config entry."""
32+
context = entry.runtime_data.interval_coordinators[0].context
33+
data: dict[str, dict] = {}
34+
35+
for coordinator in entry.runtime_data.interval_coordinators:
36+
data[coordinator.name] = {
37+
key: async_redact_data(asdict(value), _TO_REDACT_DATA) if value else None
38+
for key, value in coordinator.data.items()
39+
}
40+
41+
return {
42+
"entry_data": async_redact_data(entry.data, _TO_REDACT_ENTRY),
43+
"vehicle": async_redact_data(asdict(context.vehicle), _TO_REDACT_DATA),
44+
**data,
45+
}

0 commit comments

Comments
 (0)