2024-12-15 14:40:03 +01:00
|
|
|
"""Prediction module for weather and photovoltaic forecasts.
|
|
|
|
|
|
|
|
|
|
This module provides a `Prediction` class to manage and update a sequence of
|
|
|
|
|
prediction providers. The `Prediction` class is a subclass of `PredictionContainer`
|
|
|
|
|
and is initialized with a set of forecast providers, such as `WeatherBrightSky`,
|
|
|
|
|
`WeatherClearOutside`, and `PVForecastAkkudoktor`.
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
Instantiate the `Prediction` class with the required providers, maintaining
|
|
|
|
|
the necessary order. Then call the `update` method to refresh forecasts from
|
|
|
|
|
all providers in sequence.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
# Create singleton prediction instance with prediction providers
|
|
|
|
|
from akkudoktoreos.prediction.prediction import prediction
|
|
|
|
|
|
2026-07-15 16:38:53 +02:00
|
|
|
await prediction.update_data()
|
2024-12-15 14:40:03 +01:00
|
|
|
print("Prediction:", prediction)
|
|
|
|
|
|
|
|
|
|
Classes:
|
|
|
|
|
Prediction: Manages a list of forecast providers to fetch and update predictions.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
pvforecast_akkudoktor (PVForecastAkkudoktor): Forecast provider for photovoltaic data.
|
|
|
|
|
weather_brightsky (WeatherBrightSky): Weather forecast provider using BrightSky.
|
|
|
|
|
weather_clearoutside (WeatherClearOutside): Weather forecast provider using ClearOutside.
|
|
|
|
|
"""
|
|
|
|
|
|
2026-02-22 14:12:42 +01:00
|
|
|
from typing import Optional, Union
|
2024-12-15 14:40:03 +01:00
|
|
|
|
2025-01-20 22:58:59 +01:00
|
|
|
from pydantic import Field
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel
|
|
|
|
|
from akkudoktoreos.prediction.elecpriceakkudoktor import ElecPriceAkkudoktor
|
2025-06-23 07:29:33 +02:00
|
|
|
from akkudoktoreos.prediction.elecpriceenergycharts import ElecPriceEnergyCharts
|
2026-03-11 17:18:45 +01:00
|
|
|
from akkudoktoreos.prediction.elecpricefixed import ElecPriceFixed
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.prediction.elecpriceimport import ElecPriceImport
|
2026-07-20 13:43:43 +02:00
|
|
|
from akkudoktoreos.prediction.elecpricetibber import ElecPriceTibber
|
2025-10-28 02:50:31 +01:00
|
|
|
from akkudoktoreos.prediction.feedintarifffixed import FeedInTariffFixed
|
|
|
|
|
from akkudoktoreos.prediction.feedintariffimport import FeedInTariffImport
|
2025-11-01 00:49:11 +01:00
|
|
|
from akkudoktoreos.prediction.loadakkudoktor import (
|
|
|
|
|
LoadAkkudoktor,
|
|
|
|
|
LoadAkkudoktorAdjusted,
|
|
|
|
|
)
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.prediction.loadimport import LoadImport
|
2025-07-19 08:55:16 +02:00
|
|
|
from akkudoktoreos.prediction.loadvrm import LoadVrm
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.prediction.predictionabc import PredictionContainer
|
|
|
|
|
from akkudoktoreos.prediction.pvforecastakkudoktor import PVForecastAkkudoktor
|
2026-07-17 16:51:00 +02:00
|
|
|
from akkudoktoreos.prediction.pvforecastforecastsolar import PVForecastForecastSolar
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.prediction.pvforecastimport import PVForecastImport
|
2026-07-17 16:51:00 +02:00
|
|
|
from akkudoktoreos.prediction.pvforecastpvnode import PVForecastPVNode
|
|
|
|
|
from akkudoktoreos.prediction.pvforecastsolcast import PVForecastSolcast
|
2025-07-19 08:55:16 +02:00
|
|
|
from akkudoktoreos.prediction.pvforecastvrm import PVForecastVrm
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.prediction.weatherbrightsky import WeatherBrightSky
|
|
|
|
|
from akkudoktoreos.prediction.weatherclearoutside import WeatherClearOutside
|
|
|
|
|
from akkudoktoreos.prediction.weatherimport import WeatherImport
|
2026-03-13 12:23:21 +01:00
|
|
|
from akkudoktoreos.prediction.weatheropenmeteo import WeatherOpenMeteo
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PredictionCommonSettings(SettingsBaseModel):
|
2025-12-30 22:08:21 +01:00
|
|
|
"""General Prediction Configuration."""
|
2024-12-15 14:40:03 +01:00
|
|
|
|
2025-01-18 14:26:34 +01:00
|
|
|
hours: Optional[int] = Field(
|
2025-11-10 16:57:44 +01:00
|
|
|
default=48,
|
|
|
|
|
ge=0,
|
|
|
|
|
json_schema_extra={"description": "Number of hours into the future for predictions"},
|
2024-12-15 14:40:03 +01:00
|
|
|
)
|
2025-10-28 02:50:31 +01:00
|
|
|
|
2025-01-18 14:26:34 +01:00
|
|
|
historic_hours: Optional[int] = Field(
|
2024-12-15 14:40:03 +01:00
|
|
|
default=48,
|
|
|
|
|
ge=0,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={
|
|
|
|
|
"description": "Number of hours into the past for historical predictions data"
|
|
|
|
|
},
|
2024-12-15 14:40:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Initialize forecast providers, all are singletons.
|
|
|
|
|
elecprice_akkudoktor = ElecPriceAkkudoktor()
|
2025-06-23 07:29:33 +02:00
|
|
|
elecprice_energy_charts = ElecPriceEnergyCharts()
|
2026-03-11 17:18:45 +01:00
|
|
|
elecprice_fixed = ElecPriceFixed()
|
2024-12-15 14:40:03 +01:00
|
|
|
elecprice_import = ElecPriceImport()
|
2026-07-20 13:43:43 +02:00
|
|
|
elecprice_tibber = ElecPriceTibber()
|
2025-10-28 02:50:31 +01:00
|
|
|
feedintariff_fixed = FeedInTariffFixed()
|
|
|
|
|
feedintariff_import = FeedInTariffImport()
|
2025-11-01 00:49:11 +01:00
|
|
|
loadforecast_akkudoktor = LoadAkkudoktor()
|
|
|
|
|
loadforecast_akkudoktor_adjusted = LoadAkkudoktorAdjusted()
|
|
|
|
|
loadforecast_vrm = LoadVrm()
|
|
|
|
|
loadforecast_import = LoadImport()
|
2024-12-15 14:40:03 +01:00
|
|
|
pvforecast_akkudoktor = PVForecastAkkudoktor()
|
2025-07-19 08:55:16 +02:00
|
|
|
pvforecast_vrm = PVForecastVrm()
|
2026-07-17 16:51:00 +02:00
|
|
|
pvforecast_pvnode = PVForecastPVNode()
|
|
|
|
|
pvforecast_forecastsolar = PVForecastForecastSolar()
|
|
|
|
|
pvforecast_solcast = PVForecastSolcast()
|
2024-12-15 14:40:03 +01:00
|
|
|
pvforecast_import = PVForecastImport()
|
|
|
|
|
weather_brightsky = WeatherBrightSky()
|
|
|
|
|
weather_clearoutside = WeatherClearOutside()
|
2026-03-13 12:23:21 +01:00
|
|
|
weather_openmeteo = WeatherOpenMeteo()
|
2024-12-15 14:40:03 +01:00
|
|
|
weather_import = WeatherImport()
|
|
|
|
|
|
|
|
|
|
|
2026-02-22 14:12:42 +01:00
|
|
|
def prediction_providers() -> list[
|
|
|
|
|
Union[
|
|
|
|
|
ElecPriceAkkudoktor,
|
|
|
|
|
ElecPriceEnergyCharts,
|
2026-03-11 17:18:45 +01:00
|
|
|
ElecPriceFixed,
|
2026-02-22 14:12:42 +01:00
|
|
|
ElecPriceImport,
|
2026-07-20 13:43:43 +02:00
|
|
|
ElecPriceTibber,
|
2026-02-22 14:12:42 +01:00
|
|
|
FeedInTariffFixed,
|
|
|
|
|
FeedInTariffImport,
|
|
|
|
|
LoadAkkudoktor,
|
|
|
|
|
LoadAkkudoktorAdjusted,
|
|
|
|
|
LoadVrm,
|
|
|
|
|
LoadImport,
|
|
|
|
|
PVForecastAkkudoktor,
|
|
|
|
|
PVForecastVrm,
|
2026-07-17 16:51:00 +02:00
|
|
|
PVForecastPVNode,
|
|
|
|
|
PVForecastForecastSolar,
|
|
|
|
|
PVForecastSolcast,
|
2026-02-22 14:12:42 +01:00
|
|
|
PVForecastImport,
|
|
|
|
|
WeatherBrightSky,
|
|
|
|
|
WeatherClearOutside,
|
2026-03-13 12:23:21 +01:00
|
|
|
WeatherOpenMeteo,
|
2026-02-22 14:12:42 +01:00
|
|
|
WeatherImport,
|
|
|
|
|
]
|
|
|
|
|
]:
|
2026-03-13 12:23:21 +01:00
|
|
|
"""Return list of prediction providers.
|
|
|
|
|
|
|
|
|
|
Factory for prediction container.
|
|
|
|
|
"""
|
2026-02-22 14:12:42 +01:00
|
|
|
global \
|
|
|
|
|
elecprice_akkudoktor, \
|
|
|
|
|
elecprice_energy_charts, \
|
2026-03-11 17:18:45 +01:00
|
|
|
elecprice_fixed, \
|
2026-02-22 14:12:42 +01:00
|
|
|
elecprice_import, \
|
2026-07-20 13:43:43 +02:00
|
|
|
elecprice_tibber, \
|
2026-02-22 14:12:42 +01:00
|
|
|
feedintariff_fixed, \
|
|
|
|
|
feedintariff_import, \
|
|
|
|
|
loadforecast_akkudoktor, \
|
|
|
|
|
loadforecast_akkudoktor_adjusted, \
|
|
|
|
|
loadforecast_vrm, \
|
|
|
|
|
loadforecast_import, \
|
|
|
|
|
pvforecast_akkudoktor, \
|
|
|
|
|
pvforecast_vrm, \
|
2026-07-17 16:51:00 +02:00
|
|
|
pvforecast_pvnode, \
|
|
|
|
|
pvforecast_forecastsolar, \
|
|
|
|
|
pvforecast_solcast, \
|
2026-02-22 14:12:42 +01:00
|
|
|
pvforecast_import, \
|
|
|
|
|
weather_brightsky, \
|
|
|
|
|
weather_clearoutside, \
|
2026-03-13 12:23:21 +01:00
|
|
|
weather_openmeteo, \
|
2026-02-22 14:12:42 +01:00
|
|
|
weather_import
|
|
|
|
|
|
2024-12-15 14:40:03 +01:00
|
|
|
# Care for provider sequence as providers may rely on others to be updated before.
|
2026-02-22 14:12:42 +01:00
|
|
|
return [
|
|
|
|
|
elecprice_akkudoktor,
|
|
|
|
|
elecprice_energy_charts,
|
2026-03-11 17:18:45 +01:00
|
|
|
elecprice_fixed,
|
2026-02-22 14:12:42 +01:00
|
|
|
elecprice_import,
|
2026-07-20 13:43:43 +02:00
|
|
|
elecprice_tibber,
|
2026-02-22 14:12:42 +01:00
|
|
|
feedintariff_fixed,
|
|
|
|
|
feedintariff_import,
|
|
|
|
|
loadforecast_akkudoktor,
|
|
|
|
|
loadforecast_akkudoktor_adjusted,
|
|
|
|
|
loadforecast_vrm,
|
|
|
|
|
loadforecast_import,
|
|
|
|
|
pvforecast_akkudoktor,
|
|
|
|
|
pvforecast_vrm,
|
2026-07-17 16:51:00 +02:00
|
|
|
pvforecast_pvnode,
|
|
|
|
|
pvforecast_forecastsolar,
|
|
|
|
|
pvforecast_solcast,
|
2026-02-22 14:12:42 +01:00
|
|
|
pvforecast_import,
|
|
|
|
|
weather_brightsky,
|
|
|
|
|
weather_clearoutside,
|
2026-03-13 12:23:21 +01:00
|
|
|
weather_openmeteo,
|
2026-02-22 14:12:42 +01:00
|
|
|
weather_import,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Prediction(PredictionContainer):
|
|
|
|
|
"""Prediction container to manage multiple prediction providers."""
|
|
|
|
|
|
|
|
|
|
providers: list[
|
|
|
|
|
Union[
|
|
|
|
|
ElecPriceAkkudoktor,
|
|
|
|
|
ElecPriceEnergyCharts,
|
2026-03-11 17:18:45 +01:00
|
|
|
ElecPriceFixed,
|
2026-02-22 14:12:42 +01:00
|
|
|
ElecPriceImport,
|
2026-07-20 13:43:43 +02:00
|
|
|
ElecPriceTibber,
|
2026-02-22 14:12:42 +01:00
|
|
|
FeedInTariffFixed,
|
|
|
|
|
FeedInTariffImport,
|
|
|
|
|
LoadAkkudoktor,
|
|
|
|
|
LoadAkkudoktorAdjusted,
|
|
|
|
|
LoadVrm,
|
|
|
|
|
LoadImport,
|
|
|
|
|
PVForecastAkkudoktor,
|
|
|
|
|
PVForecastVrm,
|
2026-07-17 16:51:00 +02:00
|
|
|
PVForecastPVNode,
|
|
|
|
|
PVForecastForecastSolar,
|
|
|
|
|
PVForecastSolcast,
|
2026-02-22 14:12:42 +01:00
|
|
|
PVForecastImport,
|
|
|
|
|
WeatherBrightSky,
|
|
|
|
|
WeatherClearOutside,
|
2026-03-13 12:23:21 +01:00
|
|
|
WeatherOpenMeteo,
|
2026-02-22 14:12:42 +01:00
|
|
|
WeatherImport,
|
2024-12-15 14:40:03 +01:00
|
|
|
]
|
2026-02-22 14:12:42 +01:00
|
|
|
] = Field(
|
|
|
|
|
default_factory=prediction_providers,
|
|
|
|
|
json_schema_extra={"description": "List of prediction providers"},
|
2024-12-15 14:40:03 +01:00
|
|
|
)
|