Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Diagnostics support for PurpleAir."""
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.config_entries import ConfigEntry
9 from homeassistant.const import (
10  CONF_API_KEY,
11  CONF_LATITUDE,
12  CONF_LONGITUDE,
13  CONF_UNIQUE_ID,
14 )
15 from homeassistant.core import HomeAssistant
16 
17 from .const import DOMAIN
18 from .coordinator import PurpleAirDataUpdateCoordinator
19 
20 CONF_TITLE = "title"
21 
22 TO_REDACT = {
23  CONF_API_KEY,
24  CONF_LATITUDE,
25  CONF_LONGITUDE,
26  # Config entry title and unique ID contain the API key (whole or part):
27  CONF_TITLE,
28  CONF_UNIQUE_ID,
29 }
30 
31 
33  hass: HomeAssistant, entry: ConfigEntry
34 ) -> dict[str, Any]:
35  """Return diagnostics for a config entry."""
36  coordinator: PurpleAirDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
37  return async_redact_data(
38  {
39  "entry": entry.as_dict(),
40  "data": coordinator.data.dict(),
41  },
42  TO_REDACT,
43  )
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
Definition: util.py:14
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ConfigEntry entry)
Definition: diagnostics.py:34