Skip to content

Commit 1e7f54b

Browse files
committed
Accept name as parameter in call to microgrid.battery_pool()
And explicitly create a new source_id for every new instance of BatteryPoolWrapper. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent ff58218 commit 1e7f54b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,29 @@ class Proposal:
7878
"""A proposal for a battery to be charged or discharged."""
7979

8080
source_id: str
81+
"""The source ID of the actor sending the request."""
82+
8183
preferred_power: Power | None
84+
"""The preferred power to be distributed to the batteries.
85+
86+
If `None`, the preferred power of higher priority actors will get precedence.
87+
"""
88+
8289
bounds: timeseries.Bounds[Power | None]
90+
"""The power bounds for the proposal.
91+
92+
These bounds will apply to actors with a lower priority, and can be overridden by
93+
bounds from actors with a higher priority. If None, the power bounds will be set to
94+
the maximum power of the batteries in the pool. This is currently and experimental
95+
feature.
96+
"""
97+
8398
battery_ids: frozenset[int]
99+
"""The battery IDs to distribute the power to."""
100+
84101
priority: int
102+
"""The priority of the actor sending the proposal."""
103+
85104
request_timeout: datetime.timedelta = datetime.timedelta(seconds=5.0)
86105
"""The maximum amount of time to wait for the request to be fulfilled."""
87106

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def ev_charger_pool(
186186
def battery_pool(
187187
self,
188188
battery_ids: abc.Set[int] | None = None,
189-
source_id: str | None = None,
189+
name: str | None = None,
190190
priority: int = -sys.maxsize - 1,
191191
) -> BatteryPoolWrapper:
192192
"""Return the corresponding BatteryPool instance for the given ids.
@@ -199,7 +199,8 @@ def battery_pool(
199199
Args:
200200
battery_ids: Optional set of IDs of batteries to be managed by the
201201
BatteryPool.
202-
source_id: The source ID to use for the requests made with this instance.
202+
name: An optional name used to identify this instance of the pool or a
203+
corresponding actor in the logs.
203204
priority: The priority of the actor making the call.
204205
205206
Returns:
@@ -232,7 +233,7 @@ def battery_pool(
232233
batteries_id=battery_ids,
233234
)
234235

235-
return BatteryPoolWrapper(self._battery_pools[key], source_id, priority)
236+
return BatteryPoolWrapper(self._battery_pools[key], name, priority)
236237

237238
def _start_power_managing_actor(self) -> None:
238239
"""Start the power managing actor if it is not already running."""
@@ -424,27 +425,27 @@ def ev_charger_pool(ev_charger_ids: set[int] | None = None) -> EVChargerPool:
424425

425426
def battery_pool(
426427
battery_ids: abc.Set[int] | None = None,
427-
source_id: str | None = None,
428+
name: str | None = None,
428429
priority: int = -sys.maxsize - 1,
429430
) -> BatteryPoolWrapper:
430431
"""Return the corresponding BatteryPool instance for the given ids.
431432
432-
If a BatteryPool instance for the given ids doesn't exist, a new one is
433-
created and returned.
433+
If a BatteryPool instance for the given ids doesn't exist, a new one is created and
434+
returned.
434435
435436
The BatteryPool is wrapped in a new `BatteryPoolWrapper` instance each time.
436437
437438
Args:
438-
battery_ids: Optional set of IDs of batteries to be managed by the
439-
BatteryPool. If not specified, all batteries available in the
440-
component graph are used.
441-
source_id: The source ID to use for the requests made with this instance.
439+
battery_ids: Optional set of IDs of batteries to be managed by the BatteryPool.
440+
If not specified, all batteries available in the component graph are used.
441+
name: An optional name used to identify this instance of the pool or a
442+
corresponding actor in the logs.
442443
priority: The priority of the actor making the call.
443444
444445
Returns:
445446
A BatteryPool instance.
446447
"""
447-
return _get().battery_pool(battery_ids, source_id, priority)
448+
return _get().battery_pool(battery_ids, name, priority)
448449

449450

450451
def _get() -> _DataPipeline:

src/frequenz/sdk/timeseries/battery_pool/_battery_pool_wrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ class BatteryPoolWrapper:
4444
same set of batteries.
4545
"""
4646

47-
def __init__(self, battery_pool: BatteryPool, source_id: str | None, priority: int):
47+
def __init__(self, battery_pool: BatteryPool, name: str | None, priority: int):
4848
"""Create a BatteryPoolWrapper instance.
4949
5050
Args:
5151
battery_pool: The battery pool to wrap.
52-
source_id: The source ID to use for the requests made by this wrapper.
52+
name: The source ID to use for the requests made by this wrapper.
5353
priority: The priority of the actor using this wrapper.
5454
"""
5555
self._battery_pool = battery_pool
5656
unique_id = str(uuid.uuid4())
57-
self._source_id = unique_id if source_id is None else f"{source_id}-{unique_id}"
57+
self._source_id = unique_id if name is None else f"{name}-{unique_id}"
5858
self._priority = priority
5959

6060
async def propose_power(

0 commit comments

Comments
 (0)