First commit
This commit is contained in:
58
custom_components/open_meteo_solar_forecast/diagnostics.py
Normal file
58
custom_components/open_meteo_solar_forecast/diagnostics.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Diagnostics support for Open-Meteo Solar Forecast integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from open_meteo_solar_forecast import Estimate
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_API_KEY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: DataUpdateCoordinator[Estimate] = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return {
|
||||
"entry": {
|
||||
"title": entry.title,
|
||||
"data": async_redact_data(entry.data, TO_REDACT),
|
||||
"options": async_redact_data(entry.options, TO_REDACT),
|
||||
},
|
||||
"data": {
|
||||
"energy_production_today": coordinator.data.energy_production_today,
|
||||
"energy_production_today_remaining": coordinator.data.energy_production_today_remaining,
|
||||
"energy_production_tomorrow": coordinator.data.energy_production_tomorrow,
|
||||
"energy_current_hour": coordinator.data.energy_current_hour,
|
||||
"power_production_now": coordinator.data.power_production_now,
|
||||
"watts": {
|
||||
watt_datetime.isoformat(): watt_value
|
||||
for watt_datetime, watt_value in coordinator.data.watts.items()
|
||||
},
|
||||
"wh_days": {
|
||||
wh_datetime.isoformat(): wh_value
|
||||
for wh_datetime, wh_value in coordinator.data.wh_days.items()
|
||||
},
|
||||
"wh_period": {
|
||||
wh_datetime.isoformat(): wh_value
|
||||
for wh_datetime, wh_value in coordinator.data.wh_period.items()
|
||||
},
|
||||
},
|
||||
"account": {
|
||||
"timezone": coordinator.data.timezone,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user