Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Provides diagnostics for Tesla Fleet."""
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 TeslaFleetConfigEntry
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", "serial_number"]
29 
30 
32  hass: HomeAssistant, entry: TeslaFleetConfigEntry
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  }
39  for x in entry.runtime_data.vehicles
40  ]
41  energysites = [
42  {
43  "live": async_redact_data(x.live_coordinator.data, ENERGY_LIVE_REDACT),
44  "info": async_redact_data(x.info_coordinator.data, ENERGY_INFO_REDACT),
45  }
46  for x in entry.runtime_data.energysites
47  ]
48 
49  # Return only the relevant children
50  return {
51  "vehicles": vehicles,
52  "energysites": energysites,
53  "scopes": entry.runtime_data.scopes,
54  }
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
Definition: util.py:14
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, TeslaFleetConfigEntry entry)
Definition: diagnostics.py:33