mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-13 09:13:30 +01:00
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:
co-authored by
Claude Opus 5.5
parent
e255f987bf
commit
faf37abfe7
@@ -9,6 +9,7 @@ from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from akkudoktoreos.devices.profile.batteryprofile import BatteryProfileSettings
|
||||
from akkudoktoreos.devices.profile.inverterprofile import InverterProfileSettings
|
||||
from akkudoktoreos.devices.profile.profilestore import ProfileStore, get_profile_store
|
||||
from akkudoktoreos.server.rest.error import register_problem_handlers
|
||||
from akkudoktoreos.server.rest.profile import router
|
||||
@@ -60,6 +61,16 @@ class TestRead:
|
||||
assert response.json()["chemistry"] == "LFP"
|
||||
BatteryProfileSettings.model_validate(response.json())
|
||||
|
||||
def test_inverter_profiles(self, client):
|
||||
assert "inverter" in client.get("/v1/profile").json()
|
||||
listed = client.get("/v1/profile/inverter").json()
|
||||
assert {"name": "generic-hybrid", "source": "package", "packaged": True} in listed
|
||||
schema = client.get("/v1/profile/inverter/schema").json()
|
||||
assert "power_derating" in schema["properties"]
|
||||
response = client.get("/v1/profile/inverter/generic-hybrid")
|
||||
assert response.status_code == 200
|
||||
InverterProfileSettings.model_validate(response.json())
|
||||
|
||||
def test_errors_are_problem_details(self, client):
|
||||
response = client.get("/v1/profile/nope")
|
||||
assert response.headers["content-type"] == "application/problem+json"
|
||||
@@ -169,6 +180,48 @@ class TestDelete:
|
||||
def test_delete_of_a_missing_profile_is_404(self, client):
|
||||
assert client.delete("/v1/profile/battery/does-not-exist").status_code == 404
|
||||
|
||||
@pytest.mark.parametrize("devices", ["batteries", "electric_vehicles"])
|
||||
def test_delete_of_a_battery_profile_in_use_is_409(
|
||||
self, client, config_eos, generic_lfp, devices
|
||||
):
|
||||
client.put("/v1/profile/battery/my-battery", json=generic_lfp)
|
||||
config_eos.merge_settings_from_dict(
|
||||
{"devices": {devices: {"unit1": {"device_id": "unit1", "battery_profile": "my-battery"}}}}
|
||||
)
|
||||
response = client.delete("/v1/profile/battery/my-battery")
|
||||
assert response.status_code == 409
|
||||
assert response.json()["title"] == "Profile in use"
|
||||
assert "unit1" in response.json()["detail"]
|
||||
assert client.get("/v1/profile/battery/my-battery").status_code == 200
|
||||
|
||||
def test_delete_of_an_inverter_profile_in_use_is_409(self, client, config_eos):
|
||||
generic_hybrid = client.get("/v1/profile/inverter/generic-hybrid").json()
|
||||
client.put("/v1/profile/inverter/my-inverter", json=generic_hybrid)
|
||||
config_eos.merge_settings_from_dict(
|
||||
{
|
||||
"devices": {
|
||||
"inverters": {
|
||||
"inverter1": {"device_id": "inverter1", "inverter_profile": "my-inverter"}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
response = client.delete("/v1/profile/inverter/my-inverter")
|
||||
assert response.status_code == 409
|
||||
assert "inverter1" in response.json()["detail"]
|
||||
# A battery profile of the same name is not in use.
|
||||
assert client.delete("/v1/profile/battery/my-inverter").status_code == 404
|
||||
|
||||
def test_delete_of_an_override_in_use_reverts_to_the_packaged_profile(
|
||||
self, client, config_eos, generic_lfp
|
||||
):
|
||||
client.put("/v1/profile/battery/generic-lfp", json=generic_lfp)
|
||||
config_eos.merge_settings_from_dict(
|
||||
{"devices": {"batteries": {"battery1": {"device_id": "battery1"}}}}
|
||||
)
|
||||
assert config_eos.devices.batteries["battery1"].battery_profile == "generic-lfp"
|
||||
assert client.delete("/v1/profile/battery/generic-lfp").status_code == 200
|
||||
|
||||
|
||||
def test_eos_app_serves_the_profile_api(config_eos):
|
||||
from akkudoktoreos.server.eos import app
|
||||
|
||||
Reference in New Issue
Block a user