mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-10-08 23:46:38 +00:00
Bump Version / Bump Version Workflow (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
* fix: improve error handling for provider updates Distinguishes failures of active providers from inactive ones. Propagates errors only for enabled providers, allowing execution to continue if a non-active provider fails, which avoids unnecessary interruptions and improves robustness. * fix: add provider settings validation for forecast requests Prevents potential runtime errors by checking if provider settings are configured before accessing forecast credentials. Raises a clear error when settings are missing to help with debugging misconfigurations. * refactor(load): move provider settings to top-level fields Transitions load provider settings from a nested "provider_settings" object with provider-specific keys to dedicated top-level fields.\n\nRemoves the legacy "provider_settings" mapping and updates migration logic to ensure backward compatibility with existing configurations. * docs: update version numbers and documantation --------- Co-authored-by: Normann <github@koldrack.com>
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
"""Load forecast module for load predictions."""
|
|
|
|
from typing import Optional
|
|
|
|
from pydantic import Field, computed_field, field_validator
|
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel
|
|
from akkudoktoreos.core.coreabc import get_prediction
|
|
from akkudoktoreos.prediction.loadabc import LoadProvider
|
|
from akkudoktoreos.prediction.loadakkudoktor import LoadAkkudoktorCommonSettings
|
|
from akkudoktoreos.prediction.loadimport import LoadImportCommonSettings
|
|
from akkudoktoreos.prediction.loadvrm import LoadVrmCommonSettings
|
|
|
|
|
|
def load_providers() -> list[str]:
|
|
"""Valid load provider ids."""
|
|
try:
|
|
prediction_eos = get_prediction()
|
|
except:
|
|
# Prediction may not be initialized
|
|
# Return at least provider used in example
|
|
return ["LoadAkkudoktor", "LoadVrm", "LoadImport"]
|
|
|
|
return [
|
|
provider.provider_id()
|
|
for provider in prediction_eos.providers
|
|
if isinstance(provider, LoadProvider)
|
|
]
|
|
|
|
|
|
class LoadCommonSettings(SettingsBaseModel):
|
|
"""Load Prediction Configuration."""
|
|
|
|
provider: Optional[str] = Field(
|
|
default=None,
|
|
json_schema_extra={
|
|
"description": "Load provider id of provider to be used.",
|
|
"examples": ["LoadAkkudoktor"],
|
|
},
|
|
)
|
|
|
|
loadakkudoktor: LoadAkkudoktorCommonSettings = Field(
|
|
default_factory=LoadAkkudoktorCommonSettings,
|
|
json_schema_extra={"description": "LoadAkkudoktor provider settings."},
|
|
)
|
|
|
|
loadvrm: LoadVrmCommonSettings = Field(
|
|
default_factory=LoadVrmCommonSettings,
|
|
json_schema_extra={"description": "LoadVrm provider settings."},
|
|
)
|
|
|
|
loadimport: LoadImportCommonSettings = Field(
|
|
default_factory=LoadImportCommonSettings,
|
|
json_schema_extra={"description": "LoadImport provider settings."},
|
|
)
|
|
|
|
@computed_field # type: ignore[prop-decorator]
|
|
@property
|
|
def providers(self) -> list[str]:
|
|
"""Available load provider ids."""
|
|
return load_providers()
|
|
|
|
# Validators
|
|
@field_validator("provider", mode="after")
|
|
@classmethod
|
|
def validate_provider(cls, value: Optional[str]) -> Optional[str]:
|
|
if value is None or value in load_providers():
|
|
return value
|
|
raise ValueError(f"Provider '{value}' is not a valid load provider: {load_providers()}.")
|