Skip to content

surplus charging: fix set current in case of raw_power_left == 0#3384

Open
LKuemmel wants to merge 2 commits into
openWB:masterfrom
LKuemmel:fixes
Open

surplus charging: fix set current in case of raw_power_left == 0#3384
LKuemmel wants to merge 2 commits into
openWB:masterfrom
LKuemmel:fixes

Conversation

@LKuemmel
Copy link
Copy Markdown
Contributor

@LKuemmel LKuemmel added this to the 2.2.0-Patch.1 milestone May 22, 2026
@LKuemmel LKuemmel requested a review from Copilot May 22, 2026 10:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_power to treat raw_power_left == 0 as a limiting case and return zero currents.
  • Change power/dimming checks from truthiness to explicit comparisons (> 0, is not None) so that 0 is handled.
  • Extend unit tests for _limit_by_power with a raw_power_left == 0 case.

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 thread packages/control/loadmanagement.py Outdated
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)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_left can become <= 0 (e.g. feed_in_yield configured higher than the remaining surplus). In that case the subsequent proportional scaling uses a negative raw_power_left and will produce negative phase currents. Clamp raw_power_left to >= 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants