mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-13 09:13:30 +01:00
feat(devices): add battery profiles
A battery profile describes a battery model: the charge and discharge limit
maps over temperature and SoC, the charge and discharge efficiency curves
over C-rate, the technical SoC bounds, the hard temperature cutoffs and,
for a model, its nominal capacity and power limits. EOS packages the
generic profile generic-lfp; users add their own profiles.
A battery or electric vehicle selects its profile by battery_profile and
describes how the installation differs from it in profile_adjustment
(capacity, power limits of the installation, periodic full charge). The
effective values are resolved from both at the measured operating point
(temperature, SoC, power) and shown as effective_* fields.
The GENETIC simulation uses the limits and efficiencies of the profile over
SoC, with precomputed tables as a fast path; GENETIC0 gets the values at the
operating point. Optimization parameters are always valid: a battery whose
profile is missing, unreadable or invalid uses the packaged generic-lfp
profile, and the former defaults only if that is not usable either; each is
logged as error, and an optimization run is never cancelled because of a
battery.
Additional changes
- Add a generic device profile store: user and packaged profiles, atomic
saves, compiled profiles cached per file and checked again at most once a
second, plain file names as profile names ('schema' is reserved). On
Windows, a save or read that collides with the other is retried briefly.
- Add the REST API /v1/profile to list the profile kinds and to list, read
(document and JSON schema), save and delete profiles.
- Check the hard temperature cutoffs on the exact temperature.
- Resolve inhibited charging or discharging to a power of 0, e.g. for a cold
battery; give GENETIC0 its own discharge limit for that.
- Limit generic profiles without own power limits to the former 5000 W.
- Accept only the implemented units; current limits need the nominal
voltage.
- Migrate legacy battery settings into the profile adjustment, keep the
former charge power limit as discharge limit (also for a Home Assistant
entity on it) and report dropped efficiencies as errors.
- Limit GENETIC battery discharge by the discharge power.
- Allow battery profile lookups while the configuration is created.
- Resolve a battery once per configuration dump.
- Package the bundled profiles, document battery profiles and regenerate
the configuration and OpenAPI documentation.
- Ignore the report PDFs written by the visualization tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dd41e5d57c
commit
e255f987bf
@@ -158,7 +158,9 @@ class TestGenetic0MeasuredSOC:
|
||||
"max_electric_vehicles": 0,
|
||||
"max_inverters": 1,
|
||||
"max_home_appliances": 0,
|
||||
"batteries": {"storage": {"capacity_wh": 2000, "max_charge_power_w": 1000}},
|
||||
"batteries": {
|
||||
"storage": {"profile_adjustment": {"nominal_capacity_wh": 2000, "max_charge_power_w": 1000}}
|
||||
},
|
||||
"inverters": {"inverter": {"battery_id": "storage", "max_power_w": 1000}},
|
||||
},
|
||||
}
|
||||
@@ -203,7 +205,9 @@ class TestGenetic0MeasuredSOC:
|
||||
"max_electric_vehicles": 0,
|
||||
"max_inverters": 1,
|
||||
"max_home_appliances": 0,
|
||||
"batteries": {"storage": {"capacity_wh": 2000, "max_charge_power_w": 1000}},
|
||||
"batteries": {
|
||||
"storage": {"profile_adjustment": {"nominal_capacity_wh": 2000, "max_charge_power_w": 1000}}
|
||||
},
|
||||
"inverters": {"inverter": {"battery_id": "storage", "max_power_w": 1000}},
|
||||
},
|
||||
}
|
||||
@@ -247,7 +251,9 @@ class TestGenetic0MeasuredSOC:
|
||||
"max_electric_vehicles": 0,
|
||||
"max_inverters": 1,
|
||||
"max_home_appliances": 0,
|
||||
"batteries": {"storage": {"capacity_wh": 2000, "max_charge_power_w": 1000}},
|
||||
"batteries": {
|
||||
"storage": {"profile_adjustment": {"nominal_capacity_wh": 2000, "max_charge_power_w": 1000}}
|
||||
},
|
||||
"inverters": {"inverter": {"battery_id": "storage", "max_power_w": 1000}},
|
||||
},
|
||||
}
|
||||
@@ -277,3 +283,106 @@ class TestGenetic0MeasuredSOC:
|
||||
assert parameters is not None
|
||||
assert parameters.pv_battery is not None
|
||||
assert parameters.pv_battery.initial_soc_percentage == 42
|
||||
|
||||
|
||||
class TestGenetic0DemoData:
|
||||
"""Demo device data used when no battery / electric vehicle is configured."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_demo_devices_use_nominal_capacity(self, config_eos):
|
||||
config_eos.merge_settings_from_dict(
|
||||
{
|
||||
"prediction": {"hours": 48},
|
||||
"optimization": {"genetic0": {"horizon_hours": 24}},
|
||||
"elecfee": {"provider": None},
|
||||
"devices": {
|
||||
"max_batteries": 1,
|
||||
"max_electric_vehicles": 1,
|
||||
"max_inverters": 0,
|
||||
"max_home_appliances": 0,
|
||||
"batteries": None,
|
||||
"electric_vehicles": None,
|
||||
},
|
||||
}
|
||||
)
|
||||
get_ems().set_start_datetime(to_datetime("2026-08-01T14:00:00+00:00"))
|
||||
tariff = pd.Series(
|
||||
0.00008, index=pd.date_range("2026-08-01T00:00:00Z", periods=72 * 4, freq="15min")
|
||||
)
|
||||
|
||||
async def read_array(**kwargs):
|
||||
return np.full(48, 0.0003)
|
||||
|
||||
prediction = Mock(
|
||||
update_data=AsyncMock(),
|
||||
key_to_array=AsyncMock(side_effect=read_array),
|
||||
key_to_raw_series=AsyncMock(return_value=tariff),
|
||||
)
|
||||
with patch.object(Genetic0OptimizationParameters, "prediction", prediction):
|
||||
parameters = await Genetic0OptimizationParameters.prepare()
|
||||
|
||||
assert parameters is not None
|
||||
# The demo capacities must reach the profile adjustment of the settings;
|
||||
# the generic default profile provides no capacity of its own.
|
||||
assert config_eos.devices.batteries["battery1"].profile_adjustment.nominal_capacity_wh == 8000
|
||||
assert (
|
||||
config_eos.devices.electric_vehicles["ev1"].profile_adjustment.nominal_capacity_wh
|
||||
== 50000
|
||||
)
|
||||
assert parameters.pv_battery is not None
|
||||
assert parameters.pv_battery.capacity_wh == 8000
|
||||
assert parameters.ev is not None
|
||||
assert parameters.ev.capacity_wh == 50000
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_battery_configuration_error_uses_defaults_not_demo_data(self, config_eos):
|
||||
"""A misconfigured battery keeps its configuration, with defaults for the rest."""
|
||||
from loguru import logger
|
||||
|
||||
config_eos.merge_settings_from_dict(
|
||||
{
|
||||
"prediction": {"hours": 48},
|
||||
"optimization": {"genetic0": {"horizon_hours": 24}},
|
||||
"elecfee": {"provider": None},
|
||||
"devices": {
|
||||
"max_batteries": 1,
|
||||
"max_electric_vehicles": 0,
|
||||
"max_inverters": 0,
|
||||
"max_home_appliances": 0,
|
||||
# generic-lfp provides no capacity and the adjustment none either.
|
||||
"batteries": {"storage": {"min_soc_percentage": 20}},
|
||||
"electric_vehicles": None,
|
||||
},
|
||||
}
|
||||
)
|
||||
get_ems().set_start_datetime(to_datetime("2026-08-01T14:00:00+00:00"))
|
||||
tariff = pd.Series(
|
||||
0.00008, index=pd.date_range("2026-08-01T00:00:00Z", periods=72 * 4, freq="15min")
|
||||
)
|
||||
|
||||
async def read_array(**kwargs):
|
||||
return np.full(48, 0.0003)
|
||||
|
||||
prediction = Mock(
|
||||
update_data=AsyncMock(),
|
||||
key_to_array=AsyncMock(side_effect=read_array),
|
||||
key_to_raw_series=AsyncMock(return_value=tariff),
|
||||
)
|
||||
messages: list[str] = []
|
||||
sink_id = logger.add(
|
||||
lambda message: messages.append(message.record["message"]), level="ERROR"
|
||||
)
|
||||
try:
|
||||
with patch.object(Genetic0OptimizationParameters, "prediction", prediction):
|
||||
parameters = await Genetic0OptimizationParameters.prepare()
|
||||
finally:
|
||||
logger.remove(sink_id)
|
||||
assert parameters is not None
|
||||
assert parameters.pv_battery is not None
|
||||
# The configured battery, not the demo battery: its own SoC minimum.
|
||||
assert parameters.pv_battery.device_id == "storage"
|
||||
assert parameters.pv_battery.min_soc_percentage == 20
|
||||
assert parameters.pv_battery.capacity_wh == 8000
|
||||
assert any(
|
||||
"Battery 'storage'" in m and "nominal capacity 8000 Wh" in m for m in messages
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user