Skip to content

Commit 3b27f3c

Browse files
committed
Always require a priority argument in microgrid.*_pool methods
This forces users to think about how their actor interacts with other actors and how to prioritize their power proposals. Earlier priority was assigned to the lowest possible value by default. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 7a612ed commit 3b27f3c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from __future__ import annotations
1212

1313
import logging
14-
import sys
1514
import typing
1615
from collections import abc
1716
from dataclasses import dataclass
@@ -185,21 +184,21 @@ def producer(self) -> Producer:
185184

186185
def ev_charger_pool(
187186
self,
187+
priority: int,
188188
component_ids: abc.Set[int] | None = None,
189189
name: str | None = None,
190-
priority: int = -sys.maxsize - 1,
191190
) -> EVChargerPool:
192191
"""Return the corresponding EVChargerPool instance for the given ids.
193192
194193
If an EVChargerPool instance for the given ids doesn't exist, a new one is
195194
created and returned.
196195
197196
Args:
197+
priority: The priority of the actor making the call.
198198
component_ids: Optional set of IDs of EV Chargers to be managed by the
199199
EVChargerPool.
200200
name: An optional name used to identify this instance of the pool or a
201201
corresponding actor in the logs.
202-
priority: The priority of the actor making the call.
203202
204203
Returns:
205204
An EVChargerPool instance.
@@ -255,21 +254,21 @@ def ev_charger_pool(
255254

256255
def pv_pool(
257256
self,
257+
priority: int,
258258
component_ids: abc.Set[int] | None = None,
259259
name: str | None = None,
260-
priority: int = -sys.maxsize - 1,
261260
) -> PVPool:
262261
"""Return a new `PVPool` instance for the given ids.
263262
264263
If a `PVPoolReferenceStore` instance for the given PV inverter ids doesn't
265264
exist, a new one is created and used for creating the `PVPool`.
266265
267266
Args:
267+
priority: The priority of the actor making the call.
268268
component_ids: Optional set of IDs of PV inverters to be managed by the
269269
`PVPool`.
270270
name: An optional name used to identify this instance of the pool or a
271271
corresponding actor in the logs.
272-
priority: The priority of the actor making the call.
273272
274273
Returns:
275274
A `PVPool` instance.
@@ -331,21 +330,21 @@ def grid(self) -> Grid:
331330

332331
def battery_pool(
333332
self,
333+
priority: int,
334334
component_ids: abc.Set[int] | None = None,
335335
name: str | None = None,
336-
priority: int = -sys.maxsize - 1,
337336
) -> BatteryPool:
338337
"""Return a new `BatteryPool` instance for the given ids.
339338
340339
If a `BatteryPoolReferenceStore` instance for the given battery ids doesn't
341340
exist, a new one is created and used for creating the `BatteryPool`.
342341
343342
Args:
343+
priority: The priority of the actor making the call.
344344
component_ids: Optional set of IDs of batteries to be managed by the
345345
`BatteryPool`.
346346
name: An optional name used to identify this instance of the pool or a
347347
corresponding actor in the logs.
348-
priority: The priority of the actor making the call.
349348
350349
Returns:
351350
A `BatteryPool` instance.
@@ -505,9 +504,9 @@ def producer() -> Producer:
505504

506505

507506
def ev_charger_pool(
507+
priority: int,
508508
component_ids: abc.Set[int] | None = None,
509509
name: str | None = None,
510-
priority: int = -sys.maxsize - 1,
511510
) -> EVChargerPool:
512511
"""Return a new `EVChargerPool` instance for the given parameters.
513512
@@ -528,23 +527,23 @@ def ev_charger_pool(
528527
power.
529528
530529
Args:
530+
priority: The priority of the actor making the call.
531531
component_ids: Optional set of IDs of EV Chargers to be managed by the
532532
EVChargerPool. If not specified, all EV Chargers available in the
533533
component graph are used.
534534
name: An optional name used to identify this instance of the pool or a
535535
corresponding actor in the logs.
536-
priority: The priority of the actor making the call.
537536
538537
Returns:
539538
An `EVChargerPool` instance.
540539
"""
541-
return _get().ev_charger_pool(component_ids, name, priority)
540+
return _get().ev_charger_pool(priority, component_ids, name)
542541

543542

544543
def battery_pool(
544+
priority: int,
545545
component_ids: abc.Set[int] | None = None,
546546
name: str | None = None,
547-
priority: int = -sys.maxsize - 1,
548547
) -> BatteryPool:
549548
"""Return a new `BatteryPool` instance for the given parameters.
550549
@@ -565,23 +564,23 @@ def battery_pool(
565564
power.
566565
567566
Args:
567+
priority: The priority of the actor making the call.
568568
component_ids: Optional set of IDs of batteries to be managed by the
569569
`BatteryPool`. If not specified, all batteries available in the component
570570
graph are used.
571571
name: An optional name used to identify this instance of the pool or a
572572
corresponding actor in the logs.
573-
priority: The priority of the actor making the call.
574573
575574
Returns:
576575
A `BatteryPool` instance.
577576
"""
578-
return _get().battery_pool(component_ids, name, priority)
577+
return _get().battery_pool(priority, component_ids, name)
579578

580579

581580
def pv_pool(
581+
priority: int,
582582
component_ids: abc.Set[int] | None = None,
583583
name: str | None = None,
584-
priority: int = -sys.maxsize - 1,
585584
) -> PVPool:
586585
"""Return a new `PVPool` instance for the given parameters.
587586
@@ -602,17 +601,17 @@ def pv_pool(
602601
power.
603602
604603
Args:
604+
priority: The priority of the actor making the call.
605605
component_ids: Optional set of IDs of PV inverters to be managed by the
606606
`PVPool`. If not specified, all PV inverters available in the component
607607
graph are used.
608608
name: An optional name used to identify this instance of the pool or a
609609
corresponding actor in the logs.
610-
priority: The priority of the actor making the call.
611610
612611
Returns:
613612
A `PVPool` instance.
614613
"""
615-
return _get().pv_pool(component_ids, name, priority)
614+
return _get().pv_pool(priority, component_ids, name)
616615

617616

618617
def grid() -> Grid:

0 commit comments

Comments
 (0)