Skip to content

Commit a8bf82d

Browse files
committed
Send requests to PowerDistributor even if target power hasn't changed
This is required until #293 is done. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent d5be4e1 commit a8bf82d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,19 @@ async def _run(self) -> None:
181181
proposal = selected.value
182182
if proposal.battery_ids not in self._bound_tracker_tasks:
183183
self._add_bounds_tracker(proposal.battery_ids)
184-
await self._send_updated_target_power(proposal.battery_ids, proposal)
184+
185+
# TODO: must_send=True forces a new request to # pylint: disable=fixme
186+
# be sent to the PowerDistributor, even if there's no change in power.
187+
#
188+
# This is needed because requests would expire in the microgrid service
189+
# otherwise.
190+
#
191+
# This can be removed as soon as
192+
# https://github.com/frequenz-floss/frequenz-sdk-python/issues/293 is
193+
# implemented.
194+
await self._send_updated_target_power(
195+
proposal.battery_ids, proposal, must_send=True
196+
)
185197
await self._send_reports(proposal.battery_ids)
186198

187199
elif selected_from(selected, self._bounds_subscription_receiver):

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def test_tgt_power(
3131
power: float | None,
3232
bounds: tuple[float | None, float | None],
3333
expected: float | None,
34+
must_send: bool = False,
3435
) -> None:
3536
nonlocal call_count
3637
call_count += 1
@@ -47,6 +48,7 @@ def test_tgt_power(
4748
priority=priority,
4849
),
4950
system_bounds,
51+
must_send,
5052
)
5153
assert tgt_power == (
5254
Power.from_watts(expected) if expected is not None else None
@@ -72,6 +74,9 @@ def test_bounds(
7274
test_bounds(priority=1, expected_power=25.0, expected_bounds=(25.0, 50.0))
7375

7476
test_tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=None)
77+
test_tgt_power(
78+
priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0, must_send=True
79+
)
7580
test_bounds(priority=1, expected_power=25.0, expected_bounds=(25.0, 50.0))
7681

7782
test_tgt_power(priority=3, power=10.0, bounds=(10.0, 15.0), expected=15.0)

0 commit comments

Comments
 (0)