mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-08-30 04:06:37 +00:00
Add new provider class for electricity fees providers. Add the generic providers: - ElecFeeFixed - ElecFeeImport The providers provide predictions for: - elecfee_consumption_amt_wh: Total fixed fee for consumed energy per Wh [amount/Wh]. This is the accumulation of all fixed per-Wh fees payable on "consumed energy - such as network charge, concession fee, and electricity charge - into a single amount. - elecfee_consumption_percent_amt: Total fixed surcharge on consumed energy, given as a percentage of the monetary amount already charged for that energy [%]. This is the accumulation of all percentage-based surcharges payable on top of the consumed-energy fee - such as VAT - into a single percentage. This is a percentage of the fee amount, not a per-Wh rate. - elecfee_feedin_amt_wh: Total fixed deduction from feed-in energy per Wh [amount/Wh]. This is the accumulation of all fixed per-Wh charges deducted from feed-in energy - such as metering fees or grid-operator handling "charges - into a single amount. Applied after the percentage-based deduction, i.e. it reduces the price by a flat amount per Wh rather than by a share of the raw price. - elecfee_feedin_percent_amt: Total percentage deducted from the raw feed-in price (spot price) [%]. This is the accumulation of all percentage-based deductions payable on the feed-in tariff - such as a marketing or balancing fee retained by the aggregator - into a single percentage. It is applied as `raw_price * (100 - percent) / 100`, i.e. it scales down the raw price rather than adding a surcharge to it. A new _apply_fee() method is added to the base class for ElecPrice and FeedInTariff to be used to add the fees in a consistent way. Fees are taken from the active ElecFee provider and applied to the raw prices given to the _apply_fee() method. The optional application of fees is added to: - ElecPriceAkkudoktor - ElecPriceFixed - ElecPriceEnergyCharts - ElecPriceSMARD - FeedInTariffEnergyCharts - FeedInTariffFixed - FeedInTariffSMARD The import providers ElecPriceImport and FeedInTariffImport do not apply fees by intentention. The following providers currently do not handle fees defined by ElecFee: - ElecPriceTibber - FeedInTariffAkkudoktor - FeedInTariffDvhubOnline - FeedInTariffTibber The tests for this feature are either added or existing tests are extended. The documentation was extended for the electricity fee provider settings. Besides this feature further improvements are added: * feat: add SMARD quarter-hour electricty price and feed-in tariff provider * feat: to_series method for TimeWindows and ValueTimeWindows Additional to to_array the time window sequence can now also produce a pandas series. Test have been extended to cover the series generation. * feat: use time windows in fixed feedin tariff provider Feedin tariff can now be configured by time windows - not a single value. * feat: EOSdash select for PVLib inverters and modules Provide PVLib inverter and module names in config selection. * feat: EOSdash lazy select for big option sets Add a new form for lazy selection of big option sets. Filtering and generation of the option set is done server-side. * fix: use raw data for ETS/ median prediction Use to raw time series data for ETS/ median prediction to avoid interference by e.g. dynamic grid charges. * fix: EOSdash config drops by type only on details resolve Drop configuration by type and path. Prevents dropping of configuration items with same type and level but different path. * fix: EOSdash configuration section closes on update Open section if searching or if last update touched this category — including updates on deeply nested sub-fields. * chore: make elecfeefixed, elecpricefixed and feedintarifffixed warn about no windows and default to 0 Missining configuration creates default 0 value and a warning instead of an exception. * fix: test setup for providers Reset db state on each test run. * chore: improve config option naming for elecpricefixed. * chore: adapt elecpricefixed test to changed time_windows naming * chore: factorized common price provider helpers to priceabc.py Factorized common price provider helpers to priceabc.py. Add tests for these helpers. Reduce/ change testing of elecpriceabc.py and feedintariffabc.py to cover only specifics. Rest of testing is already covered by test_priceabc.py. * chore: update version Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
200 lines
8.5 KiB
Python
200 lines
8.5 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from akkudoktoreos.core.coreabc import get_prediction
|
|
from akkudoktoreos.prediction.elecfeefixed import ElecFeeFixed
|
|
from akkudoktoreos.prediction.elecfeeimport import ElecFeeImport
|
|
from akkudoktoreos.prediction.elecpriceakkudoktor import ElecPriceAkkudoktor
|
|
from akkudoktoreos.prediction.elecpriceenergycharts import ElecPriceEnergyCharts
|
|
from akkudoktoreos.prediction.elecpricefixed import ElecPriceFixed
|
|
from akkudoktoreos.prediction.elecpriceimport import ElecPriceImport
|
|
from akkudoktoreos.prediction.elecpricesmard import ElecPriceSMARD
|
|
from akkudoktoreos.prediction.elecpricetibber import ElecPriceTibber
|
|
from akkudoktoreos.prediction.feedintariffakkudoktor import FeedInTariffAkkudoktor
|
|
from akkudoktoreos.prediction.feedintariffdvhubonline import FeedInTariffDvhubOnline
|
|
from akkudoktoreos.prediction.feedintariffenergycharts import FeedInTariffEnergyCharts
|
|
from akkudoktoreos.prediction.feedintarifffixed import FeedInTariffFixed
|
|
from akkudoktoreos.prediction.feedintariffimport import FeedInTariffImport
|
|
from akkudoktoreos.prediction.feedintariffsmard import FeedInTariffSMARD
|
|
from akkudoktoreos.prediction.feedintarifftibber import FeedInTariffTibber
|
|
from akkudoktoreos.prediction.loadakkudoktor import (
|
|
LoadAkkudoktor,
|
|
LoadAkkudoktorAdjusted,
|
|
)
|
|
from akkudoktoreos.prediction.loadimport import LoadImport
|
|
from akkudoktoreos.prediction.loadvrm import LoadVrm
|
|
from akkudoktoreos.prediction.prediction import (
|
|
Prediction,
|
|
PredictionCommonSettings,
|
|
)
|
|
from akkudoktoreos.prediction.pvforecastakkudoktor import PVForecastAkkudoktor
|
|
from akkudoktoreos.prediction.pvforecastforecastsolar import PVForecastForecastSolar
|
|
from akkudoktoreos.prediction.pvforecastimport import PVForecastImport
|
|
from akkudoktoreos.prediction.pvforecastpvlib import PVForecastPVLib
|
|
from akkudoktoreos.prediction.pvforecastpvnode import PVForecastPVNode
|
|
from akkudoktoreos.prediction.pvforecastsolcast import PVForecastSolcast
|
|
from akkudoktoreos.prediction.pvforecastvrm import PVForecastVrm
|
|
from akkudoktoreos.prediction.weatherbrightsky import WeatherBrightSky
|
|
from akkudoktoreos.prediction.weatherclearoutside import WeatherClearOutside
|
|
from akkudoktoreos.prediction.weatherimport import WeatherImport
|
|
from akkudoktoreos.prediction.weatheropenmeteo import WeatherOpenMeteo
|
|
|
|
|
|
@pytest.fixture
|
|
def prediction():
|
|
"""All EOS predictions."""
|
|
return get_prediction()
|
|
|
|
|
|
@pytest.fixture
|
|
def forecast_providers():
|
|
"""Fixture for singleton forecast provider instances."""
|
|
return [
|
|
WeatherBrightSky(),
|
|
WeatherClearOutside(),
|
|
WeatherImport(),
|
|
WeatherOpenMeteo(),
|
|
ElecFeeFixed(),
|
|
ElecFeeImport(),
|
|
ElecPriceAkkudoktor(),
|
|
ElecPriceEnergyCharts(),
|
|
ElecPriceFixed(),
|
|
ElecPriceImport(),
|
|
ElecPriceSMARD(),
|
|
ElecPriceTibber(),
|
|
FeedInTariffAkkudoktor(),
|
|
FeedInTariffDvhubOnline(),
|
|
FeedInTariffEnergyCharts(),
|
|
FeedInTariffFixed(),
|
|
FeedInTariffImport(),
|
|
FeedInTariffSMARD(),
|
|
FeedInTariffTibber(),
|
|
LoadAkkudoktor(),
|
|
LoadAkkudoktorAdjusted(),
|
|
LoadImport(),
|
|
LoadVrm(),
|
|
PVForecastAkkudoktor(),
|
|
PVForecastForecastSolar(),
|
|
PVForecastImport(),
|
|
PVForecastPVLib(),
|
|
PVForecastPVNode(),
|
|
PVForecastSolcast(),
|
|
PVForecastVrm(),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"field_name, invalid_value, expected_error",
|
|
[
|
|
("hours", -1, "Input should be greater than or equal to 0"),
|
|
("historic_hours", -5, "Input should be greater than or equal to 0"),
|
|
],
|
|
)
|
|
def test_prediction_common_settings_invalid(field_name, invalid_value, expected_error, config_eos):
|
|
"""Test invalid settings for PredictionCommonSettings."""
|
|
valid_data = {
|
|
"hours": 48,
|
|
"historic_hours": 24,
|
|
}
|
|
assert PredictionCommonSettings(**valid_data) is not None
|
|
valid_data[field_name] = invalid_value
|
|
|
|
with pytest.raises(ValidationError, match=expected_error):
|
|
PredictionCommonSettings(**valid_data)
|
|
|
|
|
|
def test_initialization(prediction, forecast_providers):
|
|
"""Test that Prediction is initialized with the correct providers in sequence."""
|
|
assert isinstance(prediction, Prediction)
|
|
for idx, provider in enumerate(prediction.providers):
|
|
assert provider.provider_id() == forecast_providers[idx].provider_id()
|
|
|
|
|
|
def test_provider_sequence(prediction):
|
|
"""Test the provider sequence is maintained in the Prediction instance."""
|
|
assert isinstance(prediction.providers[0], WeatherBrightSky)
|
|
assert isinstance(prediction.providers[1], WeatherClearOutside)
|
|
assert isinstance(prediction.providers[2], WeatherImport)
|
|
assert isinstance(prediction.providers[3], WeatherOpenMeteo)
|
|
assert isinstance(prediction.providers[4], ElecFeeFixed)
|
|
assert isinstance(prediction.providers[5], ElecFeeImport)
|
|
assert isinstance(prediction.providers[6], ElecPriceAkkudoktor)
|
|
assert isinstance(prediction.providers[7], ElecPriceEnergyCharts)
|
|
assert isinstance(prediction.providers[8], ElecPriceFixed)
|
|
assert isinstance(prediction.providers[9], ElecPriceImport)
|
|
assert isinstance(prediction.providers[10], ElecPriceSMARD)
|
|
assert isinstance(prediction.providers[11], ElecPriceTibber)
|
|
assert isinstance(prediction.providers[12], FeedInTariffAkkudoktor)
|
|
assert isinstance(prediction.providers[13], FeedInTariffDvhubOnline)
|
|
assert isinstance(prediction.providers[14], FeedInTariffEnergyCharts)
|
|
assert isinstance(prediction.providers[15], FeedInTariffFixed)
|
|
assert isinstance(prediction.providers[16], FeedInTariffImport)
|
|
assert isinstance(prediction.providers[17], FeedInTariffSMARD)
|
|
assert isinstance(prediction.providers[18], FeedInTariffTibber)
|
|
assert isinstance(prediction.providers[19], LoadAkkudoktor)
|
|
assert isinstance(prediction.providers[20], LoadAkkudoktorAdjusted)
|
|
assert isinstance(prediction.providers[21], LoadImport)
|
|
assert isinstance(prediction.providers[22], LoadVrm)
|
|
assert isinstance(prediction.providers[23], PVForecastAkkudoktor)
|
|
assert isinstance(prediction.providers[24], PVForecastForecastSolar)
|
|
assert isinstance(prediction.providers[25], PVForecastImport)
|
|
assert isinstance(prediction.providers[26], PVForecastPVLib)
|
|
assert isinstance(prediction.providers[27], PVForecastPVNode)
|
|
assert isinstance(prediction.providers[28], PVForecastSolcast)
|
|
assert isinstance(prediction.providers[29], PVForecastVrm)
|
|
|
|
|
|
def test_provider_by_id(prediction, forecast_providers):
|
|
"""Test that provider_by_id method returns the correct provider."""
|
|
for provider in forecast_providers:
|
|
assert prediction.provider_by_id(provider.provider_id()).provider_id() == provider.provider_id()
|
|
|
|
|
|
def test_prediction_repr(prediction):
|
|
"""Test that the Prediction instance's representation is correct."""
|
|
result = repr(prediction)
|
|
assert "Prediction([" in result
|
|
assert "ElecFeeFixed" in result
|
|
assert "ElecFeeImport" in result
|
|
assert "ElecPriceAkkudoktor" in result
|
|
assert "ElecPriceEnergyCharts" in result
|
|
assert "ElecPriceFixed" in result
|
|
assert "ElecPriceImport" in result
|
|
assert "ElecPriceSMARD" in result
|
|
assert "ElecPriceTibber" in result
|
|
assert "FeedInTariffAkkudoktor" in result
|
|
assert "FeedInTariffDvhubOnline" in result
|
|
assert "FeedInTariffEnergyCharts" in result
|
|
assert "FeedInTariffFixed" in result
|
|
assert "FeedInTariffImport" in result
|
|
assert "FeedInTariffSMARD" in result
|
|
assert "FeedInTariffTibber" in result
|
|
assert "LoadAkkudoktor" in result
|
|
assert "LoadAkkudoktorAdjusted" in result
|
|
assert "LoadImport" in result
|
|
assert "LoadVrm" in result
|
|
assert "PVForecastAkkudoktor" in result
|
|
assert "PVForecastForecastSolar" in result
|
|
assert "PVForecastImport" in result
|
|
assert "PVForecastPVLib" in result
|
|
assert "PVForecastPVNode" in result
|
|
assert "PVForecastSolcast" in result
|
|
assert "PVForecastVrm" in result
|
|
assert "WeatherBrightSky" in result
|
|
assert "WeatherClearOutside" in result
|
|
assert "WeatherImport" in result
|
|
assert "WeatherOpenMeteo" in result
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_providers(prediction, forecast_providers):
|
|
"""Test behavior when Prediction does not have providers."""
|
|
# Clear all prediction providers from prediction
|
|
providers_bkup = prediction.providers.copy()
|
|
prediction.providers.clear()
|
|
assert prediction.providers == []
|
|
await prediction.update_data() # Should not raise an error even with no providers
|
|
|
|
# Cleanup after Test
|
|
prediction.providers = providers_bkup
|