Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Diagnostics support for Forecast.Solar integration."""
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.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
9 from homeassistant.core import HomeAssistant
10 
11 from . import ForecastSolarConfigEntry
12 
13 TO_REDACT = {
14  CONF_API_KEY,
15  CONF_LATITUDE,
16  CONF_LONGITUDE,
17 }
18 
19 
21  hass: HomeAssistant, entry: ForecastSolarConfigEntry
22 ) -> dict[str, Any]:
23  """Return diagnostics for a config entry."""
24  coordinator = entry.runtime_data
25 
26  return {
27  "entry": {
28  "title": entry.title,
29  "data": async_redact_data(entry.data, TO_REDACT),
30  "options": async_redact_data(entry.options, TO_REDACT),
31  },
32  "data": {
33  "energy_production_today": coordinator.data.energy_production_today,
34  "energy_production_today_remaining": coordinator.data.energy_production_today_remaining,
35  "energy_production_tomorrow": coordinator.data.energy_production_tomorrow,
36  "energy_current_hour": coordinator.data.energy_current_hour,
37  "power_production_now": coordinator.data.power_production_now,
38  "watts": {
39  watt_datetime.isoformat(): watt_value
40  for watt_datetime, watt_value in coordinator.data.watts.items()
41  },
42  "wh_days": {
43  wh_datetime.isoformat(): wh_value
44  for wh_datetime, wh_value in coordinator.data.wh_days.items()
45  },
46  "wh_period": {
47  wh_datetime.isoformat(): wh_value
48  for wh_datetime, wh_value in coordinator.data.wh_period.items()
49  },
50  },
51  "account": {
52  "type": coordinator.data.account_type.value,
53  "rate_limit": coordinator.data.api_rate_limit,
54  "timezone": coordinator.data.timezone,
55  },
56  }
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
Definition: util.py:14
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ForecastSolarConfigEntry entry)
Definition: diagnostics.py:22