Nested config, devices registry

* All config now nested.
    - Use default config from model field default values. If providers
      should be enabled by default, non-empty default config file could
      be provided again.
    - Environment variable support with EOS_ prefix and __ between levels,
      e.g. EOS_SERVER__EOS_SERVER_PORT=8503 where all values are case
      insensitive.
      For more information see:
      https://docs.pydantic.dev/latest/concepts/pydantic_settings/#parsing-environment-variable-values
    - Use devices as registry for configured devices. DeviceBase as base
      class with for now just initializion support (in the future expand
      to operations during optimization).
    - Strip down ConfigEOS to the only configuration instance. Reload
      from file or reset to defaults is possible.

 * Fix multi-initialization of derived SingletonMixin classes.
This commit is contained in:
Dominique Lasserre
2025-01-12 05:19:37 +01:00
parent f09658578a
commit be26457563
72 changed files with 1297 additions and 1712 deletions

View File

@@ -24,9 +24,13 @@ FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA = DIR_TESTDATA.joinpath("weatherforecas
def weather_provider(config_eos):
"""Fixture to create a WeatherProvider instance."""
settings = {
"weather_provider": "ClearOutside",
"latitude": 50.0,
"longitude": 10.0,
"weather": {
"weather_provider": "ClearOutside",
},
"prediction": {
"latitude": 50.0,
"longitude": 10.0,
},
}
config_eos.merge_settings_from_dict(settings)
return WeatherClearOutside()
@@ -69,7 +73,9 @@ def test_singleton_instance(weather_provider):
def test_invalid_provider(weather_provider, config_eos):
"""Test requesting an unsupported weather_provider."""
settings = {
"weather_provider": "<invalid>",
"weather": {
"weather_provider": "<invalid>",
}
}
config_eos.merge_settings_from_dict(settings)
assert not weather_provider.enabled()
@@ -78,9 +84,13 @@ def test_invalid_provider(weather_provider, config_eos):
def test_invalid_coordinates(weather_provider, config_eos):
"""Test invalid coordinates raise ValueError."""
settings = {
"weather_provider": "ClearOutside",
"latitude": 1000.0,
"longitude": 1000.0,
"weather": {
"weather_provider": "ClearOutside",
},
"prediction": {
"latitude": 1000.0,
"longitude": 1000.0,
},
}
with pytest.raises(
ValueError, # match="Latitude '1000' and/ or longitude `1000` out of valid range."
@@ -150,8 +160,8 @@ def test_update_data(mock_get, weather_provider, sample_clearout_1_html, sample_
weather_provider.update_data()
# Check for correct prediction time window
assert weather_provider.config.prediction_hours == 48
assert weather_provider.config.prediction_historic_hours == 48
assert weather_provider.config.prediction.prediction_hours == 48
assert weather_provider.config.prediction.prediction_historic_hours == 48
assert compare_datetimes(weather_provider.start_datetime, expected_start).equal
assert compare_datetimes(weather_provider.end_datetime, expected_end).equal
assert compare_datetimes(weather_provider.keep_datetime, expected_keep).equal