Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Provides diagnostics for Teslemetry."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from homeassistant.components.diagnostics import async_redact_data
8 from homeassistant.core import HomeAssistant
9 
10 from . import TeslemetryConfigEntry
11 
12 VEHICLE_REDACT = [
13  "id",
14  "user_id",
15  "vehicle_id",
16  "vin",
17  "tokens",
18  "id_s",
19  "drive_state_active_route_latitude",
20  "drive_state_active_route_longitude",
21  "drive_state_latitude",
22  "drive_state_longitude",
23  "drive_state_native_latitude",
24  "drive_state_native_longitude",
25 ]
26 
27 ENERGY_LIVE_REDACT = ["vin"]
28 ENERGY_INFO_REDACT = ["installation_date"]
29 
30 
32  hass: HomeAssistant, entry: TeslemetryConfigEntry
33 ) -> dict[str, Any]:
34  """Return diagnostics for a config entry."""
35  vehicles = [
36  {
37  "data": async_redact_data(x.coordinator.data, VEHICLE_REDACT),
38  # Stream diag will go here when implemented
39  }
40  for x in entry.runtime_data.vehicles
41  ]
42  energysites = [
43  {
44  "live": async_redact_data(x.live_coordinator.data, ENERGY_LIVE_REDACT),
45  "info": async_redact_data(x.info_coordinator.data, ENERGY_INFO_REDACT),
46  }
47  for x in entry.runtime_data.energysites
48  ]
49 
50  # Return only the relevant children
51  return {
52  "vehicles": vehicles,
53  "energysites": energysites,
54  "scopes": entry.runtime_data.scopes,
55  }
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
Definition: util.py:14
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, TeslemetryConfigEntry entry)
Definition: diagnostics.py:33