2021-08-25 18:37:03 +00:00
|
|
|
"""Energy platform."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2021-08-25 18:37:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2024-05-25 08:54:38 +00:00
|
|
|
from .coordinator import ForecastSolarDataUpdateCoordinator
|
2021-08-25 18:37:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_get_solar_forecast(
|
|
|
|
hass: HomeAssistant, config_entry_id: str
|
|
|
|
) -> dict[str, dict[str, float | int]] | None:
|
|
|
|
"""Get solar forecast for a config entry ID."""
|
2024-05-25 08:54:38 +00:00
|
|
|
if (
|
|
|
|
entry := hass.config_entries.async_get_entry(config_entry_id)
|
|
|
|
) is None or not isinstance(entry.runtime_data, ForecastSolarDataUpdateCoordinator):
|
2021-08-25 18:37:03 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
return {
|
|
|
|
"wh_hours": {
|
|
|
|
timestamp.isoformat(): val
|
2024-05-25 08:54:38 +00:00
|
|
|
for timestamp, val in entry.runtime_data.data.wh_period.items()
|
2021-08-25 18:37:03 +00:00
|
|
|
}
|
|
|
|
}
|