2024-12-15 14:40:03 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
|
2025-12-30 22:08:21 +01:00
|
|
|
from pydantic import Field, computed_field, field_validator
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel
|
2026-02-22 14:12:42 +01:00
|
|
|
from akkudoktoreos.core.coreabc import get_prediction
|
2025-03-27 21:53:01 +01:00
|
|
|
from akkudoktoreos.prediction.elecpriceabc import ElecPriceProvider
|
2026-08-23 02:26:16 +02:00
|
|
|
from akkudoktoreos.prediction.elecpriceakkudoktor import (
|
|
|
|
|
ElecPriceAkkudoktorCommonSettings,
|
|
|
|
|
)
|
2025-11-16 13:26:18 +01:00
|
|
|
from akkudoktoreos.prediction.elecpriceenergycharts import (
|
|
|
|
|
ElecPriceEnergyChartsCommonSettings,
|
|
|
|
|
)
|
2026-03-11 17:18:45 +01:00
|
|
|
from akkudoktoreos.prediction.elecpricefixed import ElecPriceFixedCommonSettings
|
2025-01-12 05:19:37 +01:00
|
|
|
from akkudoktoreos.prediction.elecpriceimport import ElecPriceImportCommonSettings
|
2026-08-23 02:26:16 +02:00
|
|
|
from akkudoktoreos.prediction.elecpricesmard import ElecPriceSMARDCommonSettings
|
2026-07-20 13:43:43 +02:00
|
|
|
from akkudoktoreos.prediction.elecpricetibber import ElecPriceTibberCommonSettings
|
2025-03-27 21:53:01 +01:00
|
|
|
|
|
|
|
|
|
2026-02-22 14:12:42 +01:00
|
|
|
def elecprice_provider_ids() -> list[str]:
|
|
|
|
|
"""Valid elecprice provider ids."""
|
|
|
|
|
try:
|
|
|
|
|
prediction_eos = get_prediction()
|
2026-07-20 01:11:33 +02:00
|
|
|
except Exception:
|
2026-07-20 13:43:43 +02:00
|
|
|
# Prediction may not be initialized. Return static built-in provider ids.
|
|
|
|
|
return [
|
|
|
|
|
"ElecPriceAkkudoktor",
|
|
|
|
|
"ElecPriceEnergyCharts",
|
|
|
|
|
"ElecPriceFixed",
|
2026-08-23 02:26:16 +02:00
|
|
|
"ElecPriceSMARD",
|
2026-07-20 13:43:43 +02:00
|
|
|
"ElecPriceImport",
|
|
|
|
|
"ElecPriceTibber",
|
|
|
|
|
]
|
2026-02-22 14:12:42 +01:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
provider.provider_id()
|
|
|
|
|
for provider in prediction_eos.providers
|
|
|
|
|
if isinstance(provider, ElecPriceProvider)
|
|
|
|
|
]
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ElecPriceCommonSettings(SettingsBaseModel):
|
2025-01-15 00:54:45 +01:00
|
|
|
"""Electricity Price Prediction Configuration."""
|
|
|
|
|
|
2025-01-18 14:26:34 +01:00
|
|
|
provider: Optional[str] = Field(
|
2025-01-15 00:54:45 +01:00
|
|
|
default=None,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={
|
|
|
|
|
"description": "Electricity price provider id of provider to be used.",
|
|
|
|
|
"examples": ["ElecPriceAkkudoktor"],
|
|
|
|
|
},
|
2024-12-30 00:50:54 +01:00
|
|
|
)
|
2026-03-11 17:18:45 +01:00
|
|
|
|
2026-08-23 02:26:16 +02:00
|
|
|
akkudoktor: ElecPriceAkkudoktorCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceAkkudoktorCommonSettings,
|
|
|
|
|
json_schema_extra={"description": "Akkudoktor electricity price provider settings."},
|
2025-09-14 23:53:41 +02:00
|
|
|
)
|
2025-01-12 05:19:37 +01:00
|
|
|
|
2026-03-11 17:18:45 +01:00
|
|
|
elecpricefixed: ElecPriceFixedCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceFixedCommonSettings,
|
|
|
|
|
json_schema_extra={"description": "Fixed electricity price provider settings."},
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-16 13:26:18 +01:00
|
|
|
elecpriceimport: ElecPriceImportCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceImportCommonSettings,
|
2026-07-20 14:37:03 +02:00
|
|
|
json_schema_extra={"description": "Electricity price import provider settings."},
|
2025-11-16 13:26:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
energycharts: ElecPriceEnergyChartsCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceEnergyChartsCommonSettings,
|
|
|
|
|
json_schema_extra={"description": "Energy Charts provider settings."},
|
2025-01-15 00:54:45 +01:00
|
|
|
)
|
2025-03-27 21:53:01 +01:00
|
|
|
|
2026-08-23 02:26:16 +02:00
|
|
|
smard: ElecPriceSMARDCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceSMARDCommonSettings,
|
|
|
|
|
json_schema_extra={"description": "SMARD electricity price provider settings."},
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-20 13:43:43 +02:00
|
|
|
tibber: ElecPriceTibberCommonSettings = Field(
|
|
|
|
|
default_factory=ElecPriceTibberCommonSettings,
|
|
|
|
|
json_schema_extra={"description": "Tibber electricity price provider settings."},
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-30 22:08:21 +01:00
|
|
|
@computed_field # type: ignore[prop-decorator]
|
|
|
|
|
@property
|
|
|
|
|
def providers(self) -> list[str]:
|
|
|
|
|
"""Available electricity price provider ids."""
|
2026-02-22 14:12:42 +01:00
|
|
|
return elecprice_provider_ids()
|
2025-12-30 22:08:21 +01:00
|
|
|
|
2025-03-27 21:53:01 +01:00
|
|
|
# Validators
|
|
|
|
|
@field_validator("provider", mode="after")
|
|
|
|
|
@classmethod
|
|
|
|
|
def validate_provider(cls, value: Optional[str]) -> Optional[str]:
|
2026-02-22 14:12:42 +01:00
|
|
|
if value is None or value in elecprice_provider_ids():
|
2025-03-27 21:53:01 +01:00
|
|
|
return value
|
|
|
|
|
raise ValueError(
|
2026-02-22 14:12:42 +01:00
|
|
|
f"Provider '{value}' is not a valid electricity price provider: {elecprice_provider_ids()}."
|
2025-03-27 21:53:01 +01:00
|
|
|
)
|