mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-13 01:03:45 +01:00
An inverter profile describes the technical data of an inverter model: its nominal AC power, the DC→AC and AC→DC efficiency curves over the load fraction (AC power relative to the nominal power), the AC charge power limit of the model, whether that limit also limits PV charging, and an optional power derating over the ambient temperature. Curves are read linearly and clamped at their ends, so every lookup yields a value. The packaged profile generic-hybrid has typical hybrid inverter efficiencies, no nominal power (the inverter device has to provide it) and full power up to 45 degC. Inverter settings name their profile (inverter_profile, default generic-hybrid) and hold the differences of the unit in profile_adjustment: nominal_power_w (replaces the profile value, required for a generic profile), max_power_w and max_ac_charge_power_w (installation limits that can only lower; an AC charge limit of 0 disables AC charging). The effective parameters are resolved at the ambient temperature of the inverter, given by the new measurement key <device_id>-temperature-degc (45 degC without a fresh value); the power derating lowers the maximum power and the AC charge limit. Optimization parameters are always valid: the GENETIC and GENETIC0 parameter preparation resolve the inverter with resolve_current_operating_parameters_or_defaults, which never raises. An unusable profile gives the generic-hybrid profile, a missing nominal power the fallback of 10000 W, an inverter derated to zero power the parameters at 45 degC, and no usable profile at all the profile adjustment with constant efficiency; each is logged as error. The GENETIC inverter takes the AC→DC efficiency curve of the profile, solved exactly on each linear piece of the curve (about 2 % longer runs); GENETIC0 keeps constant efficiencies and no longer replaces the configured inverters with the demo inverter; a battery, electric vehicle or inverter that cannot be prepared is left out of the GENETIC0 run, never replaced by a demo device. Configurations migrate: max_power_w becomes profile_adjustment.nominal_power_w, max_ac_charge_power_w moves into the adjustment, an ac_to_dc_efficiency of 0 keeps AC charging disabled, and the efficiency fields are dropped with an error log, as for batteries, so the profile efficiencies apply. Home Assistant config paths follow. Additional changes - Move the curve algorithms of the battery profile into profilecurve, so battery and inverter profiles share them; the battery profile keeps its document format and classes. - Move ProfileBaseModel, the strict base of profile documents, into profilestore. - Serve inverter profiles through the profile REST API. Refuse to delete a profile that a configured device uses and that has no packaged profile to revert to (409). - Share the measurement access of the device settings in devicemeasurement. - Rename check_battery_profiles to check_device_profiles; the device profile check at configuration setup covers inverters, too. - Document inverter profiles, their configuration, defaults and sharing; regenerate the configuration and OpenAPI documentation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
120 lines
4.7 KiB
Python
120 lines
4.7 KiB
Python
"""Contracts shared by the configuration, tariff and optimizer PRs."""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from akkudoktoreos.optimization.genetic0.genetic0params import (
|
|
Genetic0EnergyManagementParameters,
|
|
)
|
|
from akkudoktoreos.optimization.genetic.geneticparams import (
|
|
GeneticEnergyManagementParameters,
|
|
)
|
|
from akkudoktoreos.optimization.optimization import OptimizationAlgorithm
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"model", [GeneticEnergyManagementParameters, Genetic0EnergyManagementParameters]
|
|
)
|
|
@pytest.mark.parametrize("tariff", [0.00008, [0.00008, -0.00002]])
|
|
def test_energy_parameter_aliases_preserve_wh_prices(model, tariff):
|
|
raw = {
|
|
"pv_prognose_wh": [250.0, 0.0],
|
|
"gesamtlast": [125.0, 125.0],
|
|
"strompreis_euro_pro_wh": [0.0003, -0.0001],
|
|
"einspeiseverguetung_euro_pro_wh": tariff,
|
|
"preis_euro_pro_wh_akku": 0.00005,
|
|
}
|
|
params = model.model_validate(raw)
|
|
data = params.model_dump(mode="json")
|
|
pairs = {
|
|
"pv_prognose_wh": "pv_forecast_wh",
|
|
"gesamtlast": "total_load",
|
|
"strompreis_euro_pro_wh": "electricity_price_per_wh",
|
|
"einspeiseverguetung_euro_pro_wh": "feed_in_tariff_per_wh",
|
|
"preis_euro_pro_wh_akku": "price_per_wh_battery",
|
|
}
|
|
for deprecated, canonical in pairs.items():
|
|
assert data[deprecated] == data[canonical] == raw[deprecated]
|
|
assert (
|
|
model.model_validate({pairs[k]: v for k, v in raw.items()}).model_dump(mode="json") == data
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("algorithm", list(OptimizationAlgorithm))
|
|
async def test_algorithm_result_endpoint_keeps_solution_types_separate(monkeypatch, algorithm):
|
|
from akkudoktoreos.server import eos
|
|
|
|
genetic, genetic0 = object(), object()
|
|
fake = SimpleNamespace(
|
|
genetic_solution=Mock(return_value=genetic),
|
|
genetic0_solution=Mock(return_value=genetic0),
|
|
)
|
|
monkeypatch.setattr(eos, "get_ems", lambda: fake)
|
|
monkeypatch.setattr(
|
|
eos,
|
|
"get_config",
|
|
lambda: SimpleNamespace(optimization=SimpleNamespace(algorithms=["GENETIC", "GENETIC0"])),
|
|
)
|
|
result = await eos.fastapi_energy_management_optimization_solution_algorithm_get(algorithm)
|
|
if algorithm == OptimizationAlgorithm.GENETIC:
|
|
assert result is genetic
|
|
fake.genetic_solution.assert_called_once_with()
|
|
fake.genetic0_solution.assert_not_called()
|
|
else:
|
|
assert result is genetic0
|
|
fake.genetic0_solution.assert_called_once_with()
|
|
fake.genetic_solution.assert_not_called()
|
|
|
|
|
|
@pytest.mark.parametrize("algorithm", ["genetic", "genetic0"])
|
|
def test_device_maps_feed_algorithm_specific_converters(algorithm):
|
|
from akkudoktoreos.devices.devices import DevicesCommonSettings
|
|
|
|
settings = DevicesCommonSettings.model_validate(
|
|
{
|
|
"batteries": {
|
|
"storage": {"profile_adjustment": {"nominal_capacity_wh": 12000, "max_charge_power_w": 3200}}
|
|
},
|
|
"electric_vehicles": {
|
|
"car": {"profile_adjustment": {"nominal_capacity_wh": 60000, "max_charge_power_w": 7000}}
|
|
},
|
|
"inverters": {"inverter": {"battery_id": "storage", "profile_adjustment": {"nominal_power_w": 5000}}},
|
|
"home_appliances": {
|
|
"washer": {
|
|
"consumption_wh": 1800,
|
|
"duration_h": 2,
|
|
"num_cycles": 2,
|
|
"min_cycle_gap_h": 1,
|
|
}
|
|
},
|
|
}
|
|
)
|
|
assert settings.batteries is not None
|
|
assert settings.electric_vehicles is not None
|
|
assert settings.inverters is not None
|
|
battery = getattr(settings.batteries["storage"], "to_" + algorithm + "_pv_bat_param")()
|
|
ev = getattr(settings.electric_vehicles["car"], "to_" + algorithm + "_ev_bat_param")()
|
|
inverter = getattr(settings.inverters["inverter"], "to_" + algorithm + "_param")()
|
|
appliance = getattr(settings.home_appliances["washer"], "to_" + algorithm + "_param")()
|
|
assert (battery.device_id, ev.device_id, inverter.device_id, appliance.device_id) == (
|
|
"storage",
|
|
"car",
|
|
"inverter",
|
|
"washer",
|
|
)
|
|
assert battery.capacity_wh == 12000
|
|
assert battery.max_charge_power_w == 3200
|
|
assert ev.capacity_wh == 60000
|
|
assert ev.max_charge_power_w == 7000
|
|
assert inverter.max_power_wh == 5000
|
|
assert inverter.battery_id == "storage"
|
|
assert appliance.consumption_wh == 1800
|
|
assert appliance.duration_h == 2
|
|
assert settings.batteries["storage"].measurement_key_soc_factor == "storage-soc-factor"
|
|
if algorithm == "genetic":
|
|
assert appliance.num_cycles == 2
|
|
assert appliance.min_cycle_gap_h == 1
|