mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-13 09:13:30 +01:00
fix(config): validate prediction providers before the prediction exists
The provider settings (weather, PV forecast, load, electricity price, feed-in tariff, electricity fee) validate their provider id against the providers of the prediction instance. While the configuration is created, that instance does not exist yet, and the validation falls back to fixed lists. These were incomplete: weather knew only 'WeatherImport', load lacked 'LoadAkkudoktorAdjusted'. A configuration file with e.g. weather provider 'OpenMeteo' then fails to load: Provider 'OpenMeteo' is not a valid weather provider: ['WeatherImport'] This is hidden today because ConfigEOS.documentation_mode() is always true (_force_documentation_mode is a pydantic private attribute, whose class attribute is a truthy descriptor), and get_prediction() then creates the prediction instance on access. Once documentation mode is enabled only explicitly, the configuration does not load. Derive the provider ids from the provider classes instead (prediction_provider_ids). They no longer depend on whether the prediction instance exists, so the validation is the same before and after initialization. Additional changes - Add the test fixture uncreated_config, which lets get_config(init=True) create a new configuration from the config file and restores the old one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4475774c06
commit
a0e57a18b7
@@ -209,3 +209,34 @@ async def test_empty_providers(prediction, forecast_providers):
|
||||
|
||||
# Cleanup after Test
|
||||
prediction.providers = providers_bkup
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"provider_type",
|
||||
[
|
||||
"WeatherProvider",
|
||||
"PVForecastProvider",
|
||||
"LoadProvider",
|
||||
"ElecPriceProvider",
|
||||
"FeedInTariffProvider",
|
||||
"ElecFeeProvider",
|
||||
],
|
||||
)
|
||||
def test_provider_ids_without_prediction_instance(prediction, provider_type):
|
||||
"""The ids from the provider classes match the providers of the prediction."""
|
||||
import importlib
|
||||
|
||||
from akkudoktoreos.prediction.prediction import prediction_provider_ids
|
||||
|
||||
module_name = {
|
||||
"WeatherProvider": "weatherabc",
|
||||
"PVForecastProvider": "pvforecastabc",
|
||||
"LoadProvider": "loadabc",
|
||||
"ElecPriceProvider": "elecpriceabc",
|
||||
"FeedInTariffProvider": "feedintariffabc",
|
||||
"ElecFeeProvider": "elecfeeabc",
|
||||
}[provider_type]
|
||||
base = getattr(importlib.import_module(f"akkudoktoreos.prediction.{module_name}"), provider_type)
|
||||
expected = {p.provider_id() for p in prediction.providers if isinstance(p, base)}
|
||||
assert expected
|
||||
assert set(prediction_provider_ids(base)) == expected
|
||||
|
||||
Reference in New Issue
Block a user