Skip to content

Commit 5af26d8

Browse files
authored
Generalize PowerDistributingActor (#786)
All the battery-specific logic has been moved into a `BatteryManager` (which implements `ComponentManager`). This includes - component status tracking - bounds tracking - distribution algorithm - control methods This allows us to add `ComponentManager` implementations for additional component categories, that can be used with the PowerDistributingActor.
2 parents 0e19bf4 + 96815f0 commit 5af26d8

File tree

19 files changed

+998
-805
lines changed

19 files changed

+998
-805
lines changed

RELEASE_NOTES.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66

77
## Upgrading
88

9-
- The `BatteryPool.power_status` method now streams objects of type `BatteryPoolReport`. They're identical to the previous `Report` objects, except for the name of the class.
9+
- The `BatteryPool.power_status` method now streams objects of type `BatteryPoolReport`, replacing the previous `Report` objects.
10+
11+
- In `BatteryPoolReport.distribution_result`,
12+
* the following fields have been renamed:
13+
+ `Result.succeeded_batteries``Result.succeeded_components`
14+
+ `Result.failed_batteries``Result.failed_components`
15+
+ `Request.batteries``Request.component_ids`
16+
* and the following fields are now type-hinted as `collections.abc.Set`, to clearly indicate that they are read-only:
17+
+ `Result.succeeded_components`
18+
+ `Result.failed_components`
19+
1020

1121
## New Features
1222

benchmarks/power_distribution/power_distributor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def run_test( # pylint: disable=too-many-locals
117117
async with PowerDistributingActor(
118118
requests_receiver=power_request_channel.new_receiver(),
119119
results_sender=power_result_channel.new_sender(),
120-
battery_status_sender=battery_status_channel.new_sender(),
120+
component_pool_status_sender=battery_status_channel.new_sender(),
121121
):
122122
tasks: list[Coroutine[Any, Any, list[Result]]] = []
123123
tasks.append(send_requests(batteries, num_requests))

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def _send_updated_target_power(
171171
await self._power_distributing_requests_sender.send(
172172
power_distributing.Request(
173173
power=target_power,
174-
batteries=component_ids,
174+
component_ids=component_ids,
175175
request_timeout=request_timeout,
176176
adjust_power=True,
177177
)
@@ -229,10 +229,12 @@ async def _run(self) -> None:
229229
)
230230

231231
result = selected.value
232-
self._distribution_results[frozenset(result.request.batteries)] = result
232+
self._distribution_results[
233+
frozenset(result.request.component_ids)
234+
] = result
233235
match result:
234236
case power_distributing.PartialFailure(request):
235237
await self._send_updated_target_power(
236-
frozenset(request.batteries), None, must_send=True
238+
frozenset(request.component_ids), None, must_send=True
237239
)
238-
await self._send_reports(frozenset(result.request.batteries))
240+
await self._send_reports(frozenset(result.request.component_ids))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# License: MIT
2+
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Interfaces for the power distributing actor with different component types."""
5+
6+
from ._battery_manager import BatteryManager
7+
from ._component_manager import ComponentManager
8+
9+
__all__ = [
10+
"BatteryManager",
11+
"ComponentManager",
12+
]

0 commit comments

Comments
 (0)