Skip to content

Commit 12749c1

Browse files
committed
Respect exclusion bounds in PowerDistributingActor._check_request
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent db23e32 commit 12749c1

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,27 @@ def _check_request(self, request: Request) -> Optional[Result]:
517517
)
518518
return Error(request=request, msg=msg)
519519

520-
if not request.adjust_power:
521-
if request.power < 0:
522-
bound = self._get_lower_bound(
523-
request.batteries, request.include_broken_batteries
524-
)
525-
if request.power < bound:
526-
return OutOfBound(request=request, bound=bound)
527-
else:
528-
bound = self._get_upper_bound(
529-
request.batteries, request.include_broken_batteries
530-
)
531-
if request.power > bound:
532-
return OutOfBound(request=request, bound=bound)
520+
bounds = self._get_bounds(request.batteries, request.include_broken_batteries)
521+
if request.adjust_power:
522+
# Automatic power adjustments can only bring down the requested power down
523+
# to the inclusion bounds.
524+
#
525+
# If the requested power is in the exclusion bounds, it is NOT possible to
526+
# increase it so that it is outside the exclusion bounds.
527+
if (
528+
request.power > bounds.exclusion_lower
529+
and request.power < bounds.exclusion_upper
530+
):
531+
return OutOfBound(request=request, bound=bounds)
532+
else:
533+
in_lower_range = (
534+
bounds.inclusion_lower <= request.power <= bounds.exclusion_lower
535+
)
536+
in_upper_range = (
537+
bounds.exclusion_upper <= request.power <= bounds.inclusion_upper
538+
)
539+
if not (in_lower_range or in_upper_range):
540+
return OutOfBound(request=request, bound=bounds)
533541

534542
return None
535543

src/frequenz/sdk/actor/power_distributing/result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class OutOfBound(Result):
9595
`adjust_power = False` and the requested power is not within the batteries bounds.
9696
"""
9797

98-
bound: float
99-
"""The total power bound for the requested batteries.
98+
bound: PowerBounds
99+
"""The power bounds for the requested batteries.
100100
101101
If the requested power negative, then this value is the lower bound.
102102
Otherwise it is upper bound.

0 commit comments

Comments
 (0)