feat(devices): add inverter profiles

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)
This commit is contained in:
Bobby Noelte
2026-11-11 22:08:18 +01:00
co-authored by Claude Opus 5.5
parent e255f987bf
commit faf37abfe7
45 changed files with 3235 additions and 784 deletions
+78 -1
View File
@@ -1,6 +1,7 @@
"""Configuration-owned requests and the real automatic GENETIC path."""
from types import SimpleNamespace
from typing import Any, Optional
from unittest.mock import AsyncMock, Mock, patch
import httpx
@@ -67,7 +68,12 @@ def configured_request(config_eos, monkeypatch):
}
},
"electric_vehicles": {},
"inverters": {"inverter": {"battery_id": "storage", "max_power_w": 1000}},
"inverters": {
"inverter": {
"battery_id": "storage",
"profile_adjustment": {"nominal_power_w": 1000},
}
},
"home_appliances": {},
},
}
@@ -758,3 +764,74 @@ async def test_battery_configuration_error_uses_defaults_and_logs_error(configur
and "Using defaults for the optimization: battery profile 'generic-lfp'" in m
for m in messages
)
@pytest.mark.asyncio
@pytest.mark.parametrize(
"temperature_degc, expected_max_power_w",
[(None, 1000.0), (45.0, 1000.0), (60.0, 600.0)],
)
async def test_inverter_is_derated_at_measured_temperature(
configured_request, monkeypatch, temperature_degc, expected_max_power_w
):
"""The generic profile derates above 45 degC; without a measurement 45 degC applies."""
from akkudoktoreos.devices.settings import invertermeasurement
_, _, _, data = configured_request
async def measured(key: str, target_datetime: Any) -> Optional[float]:
return temperature_degc if key == "inverter-temperature-degc" else None
monkeypatch.setattr(invertermeasurement, "get_measured_value", measured)
parameters = await ConfigOptimizationRequest.model_validate(data).resolve()
assert parameters.inverter is not None
assert parameters.inverter.max_power_wh == pytest.approx(expected_max_power_w)
assert parameters.inverter.max_ac_charge_power_w == pytest.approx(expected_max_power_w)
assert parameters.inverter.ac_to_dc_efficiency_curve is not None
@pytest.mark.asyncio
async def test_unusable_inverter_profile_falls_back_to_generic(configured_request):
"""A missing inverter profile does not cancel the parameter preparation."""
from loguru import logger
config, _, _, data = configured_request
config.merge_settings_from_dict(
{"devices": {"inverters": {"inverter": {"inverter_profile": "does-not-exist"}}}}
)
messages: list[str] = []
sink_id = logger.add(lambda message: messages.append(message.record["message"]), level="ERROR")
try:
parameters = await ConfigOptimizationRequest.model_validate(data).resolve()
finally:
logger.remove(sink_id)
assert parameters.inverter is not None
assert parameters.inverter.max_power_wh == pytest.approx(1000.0)
assert any(
"Inverter 'inverter'" in m and "inverter profile 'generic-hybrid'" in m
for m in messages
)
@pytest.mark.asyncio
async def test_inverter_without_nominal_power_uses_the_fallback_power(configured_request):
"""The run is not cancelled: the fallback nominal power applies, reported as error."""
from loguru import logger
from akkudoktoreos.devices.settings.inverterresolution import (
INVERTER_FALLBACK_NOMINAL_POWER_W,
)
config, _, _, data = configured_request
config.merge_settings_from_dict(
{"devices": {"inverters": {"inverter": {"profile_adjustment": {"nominal_power_w": None}}}}}
)
messages: list[str] = []
sink_id = logger.add(lambda message: messages.append(message.record["message"]), level="ERROR")
try:
parameters = await ConfigOptimizationRequest.model_validate(data).resolve()
finally:
logger.remove(sink_id)
assert parameters.inverter is not None
assert parameters.inverter.max_power_wh == pytest.approx(INVERTER_FALLBACK_NOMINAL_POWER_W)
assert any("nominal_power_w" in m for m in messages)