Skip to content

Commit d55eb48

Browse files
committed
Pass through zero-power requests from PowerManager
Instead of adjusting them to the exclusion bounds, because the API accepts zero power values even when there are exclusion bounds. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent d32719f commit d55eb48

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/frequenz/sdk/actor/_power_managing/_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def clamp_to_bounds( # pylint: disable=too-many-return-statements
138138

139139
# If the given value is within the exclusion bounds and the exclusion bounds are
140140
# within the given bounds, clamp the given value to the closest exclusion bound.
141-
if exclusion_bounds is not None:
141+
if exclusion_bounds is not None and not value.isclose(Power.zero()):
142142
if exclusion_bounds.lower < value < exclusion_bounds.upper:
143143
return exclusion_bounds.lower, exclusion_bounds.upper
144144

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ async def test_matryoshka_with_excl_3() -> None:
313313
)
314314

315315
tester = StatefulTester(batteries, system_bounds)
316+
tester.tgt_power(priority=2, power=10.0, bounds=(None, None), expected=30.0)
317+
tester.tgt_power(priority=2, power=-10.0, bounds=(None, None), expected=-30.0)
318+
tester.tgt_power(priority=2, power=0.0, bounds=(None, None), expected=0.0)
319+
tester.tgt_power(priority=3, power=20.0, bounds=(None, None), expected=None)
320+
tester.tgt_power(priority=1, power=-20.0, bounds=(None, None), expected=-30.0)
321+
tester.tgt_power(priority=3, power=None, bounds=(None, None), expected=None)
322+
tester.tgt_power(priority=1, power=None, bounds=(None, None), expected=0.0)
316323

317324
tester.tgt_power(priority=2, power=25.0, bounds=(25.0, 50.0), expected=30.0)
318325
tester.bounds(priority=2, expected_power=30.0, expected_bounds=(-200.0, 200.0))

tests/actor/_power_managing/test_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_adjust_to_bounds() -> None:
5858
inclusion_bounds=(-200.0, 200.0),
5959
exclusion_bounds=(-30.0, 30.0),
6060
)
61-
tester.case(0.0, -30.0, 30.0)
61+
tester.case(0.0, 0.0, 0.0)
6262
tester.case(-210.0, -200.0, None)
6363
tester.case(220.0, None, 200.0)
6464
tester.case(-20.0, -30.0, 30.0)

0 commit comments

Comments
 (0)