Skip to content

Commit 7d2661c

Browse files
committed
Pass through zero-power requests in the PowerDistributingActor
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent d55eb48 commit 7d2661c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,16 @@ def distribute_power(
685685
Returns:
686686
Distribution result
687687
"""
688-
if power >= 0.0:
688+
if is_close_to_zero(power):
689+
return DistributionResult(
690+
distribution={
691+
inverter.component_id: 0.0
692+
for _, inverters in components
693+
for inverter in inverters
694+
},
695+
remaining_power=0.0,
696+
)
697+
if power > 0.0:
689698
return self._distribute_consume_power(power, components)
690699
return self._distribute_supply_power(power, components)
691700

tests/actor/power_distributing/test_battery_distribution_algorithm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,11 @@ def test_scenario_1(self) -> None:
10391039

10401040
algorithm = BatteryDistributionAlgorithm()
10411041

1042+
self.assert_result(
1043+
algorithm.distribute_power(0, components),
1044+
DistributionResult({1: 0, 3: 0, 5: 0}, remaining_power=0.0),
1045+
)
1046+
10421047
self.assert_result(
10431048
algorithm.distribute_power(-300, components),
10441049
DistributionResult({1: -100, 3: -100, 5: -100}, remaining_power=0.0),

0 commit comments

Comments
 (0)