surplus charging: fix set current in case of raw_power_left == 0#3384
Open
LKuemmel wants to merge 2 commits into
Open
surplus charging: fix set current in case of raw_power_left == 0#3384LKuemmel wants to merge 2 commits into
LKuemmel wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to fix surplus charging behavior so that when raw_power_left == 0 the computed available currents are set to 0 (instead of leaving the previous currents), and to ensure “0” values from dimming/power-left signals are handled explicitly rather than treated as “no value”.
Changes:
- Update
_limit_by_powerto treatraw_power_left == 0as a limiting case and return zero currents. - Change power/dimming checks from truthiness to explicit comparisons (
> 0,is not None) so that0is handled. - Extend unit tests for
_limit_by_powerwith araw_power_left == 0case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/control/loadmanagement.py | Adjusts power- and dimming-based limiting logic to handle 0 values explicitly. |
| packages/control/loadmanagement_test.py | Updates _limit_by_power tests and adds a regression case for raw_power_left == 0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+105
to
+123
| @@ -117,7 +117,10 @@ def _limit_by_power(self, | |||
| log.debug(f"Leistungsüberschreitung auf {raw_power_left}W korrigieren: {available_currents}") | |||
| limit = LoadmanagementLimit(LimitingValue.POWER.value.format(get_component_name_by_id(counter.num)), | |||
| LimitingValue.POWER) | |||
| return currents, limit | |||
| return currents, limit | |||
| else: | |||
| return [0]*3, LoadmanagementLimit(LimitingValue.POWER.value.format(get_component_name_by_id(counter.num)), | |||
| LimitingValue.POWER) | |||
Comment on lines
27
to
36
| def test_limit_by_power(available_currents: List[float], | ||
| raw_power_left: float, | ||
| expected_currents: List[float], | ||
| expected_ret: List[float], | ||
| monkeypatch): | ||
| # setup | ||
| counter_name_mock = Mock(return_value=COUNTER_NAME) | ||
| monkeypatch.setattr(loadmanagement, "get_component_name_by_id", counter_name_mock) | ||
| # evaluation | ||
| currents = Loadmanagement()._limit_by_power(Counter(0), available_currents, 230, raw_power_left, None) | ||
| ret = Loadmanagement()._limit_by_power(Counter(0), available_currents, 230, raw_power_left, None) | ||
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/control/loadmanagement.py:115
- After subtracting
feed_in,raw_power_leftcan become <= 0 (e.g. feed_in_yield configured higher than the remaining surplus). In that case the subsequent proportional scaling uses a negativeraw_power_leftand will produce negative phase currents. Clampraw_power_leftto >= 0 after subtraction and/or short-circuit to return 0A on all phases when it becomes <= 0 (and consider adding a unit test for this case).
elif raw_power_left > 0:
if feed_in is not None:
raw_power_left = raw_power_left - feed_in
log.debug(f"Verbleibende Leistung unter Berücksichtigung der Einspeisegrenze: {raw_power_left}W")
if sum([c * cp_voltage for c in available_currents]) > raw_power_left:
for i in range(0, 3):
try:
# Am meisten belastete Phase trägt am meisten zur Leistungsreduktion bei.
currents[i] = available_currents[i] / sum(available_currents) * raw_power_left / cp_voltage
Comment on lines
+124
to
+125
| return [0]*3, LoadmanagementLimit(LimitingValue.POWER.value.format(get_component_name_by_id(counter.num)), | ||
| LimitingValue.POWER) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://forum.openwb.de/viewtopic.php?p=142924#p142924