Skip to content

Commit 437487e

Browse files
committed
Accept a in_shifting_group parameter, when creating a *_pool
And propagate it all the way to the power manager. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent ab22157 commit 437487e

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ReportRequest:
3333
priority: int
3434
"""The priority of the actor ."""
3535

36+
in_shifting_group: bool
37+
"""Whether the proposal gets sent to the shifting group of the power manager."""
38+
3639
def get_channel_name(self) -> str:
3740
"""Get the channel name for the report request.
3841
@@ -216,6 +219,9 @@ class Proposal:
216219
request_timeout: datetime.timedelta = datetime.timedelta(seconds=5.0)
217220
"""The maximum amount of time to wait for the request to be fulfilled."""
218221

222+
in_shifting_group: bool
223+
"""Whether the proposal gets sent to the shifting group of the power manager."""
224+
219225
def __lt__(self, other: Proposal) -> bool:
220226
"""Compare two proposals by their priority.
221227

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def ev_charger_pool(
199199
priority: int,
200200
component_ids: abc.Set[int] | None = None,
201201
name: str | None = None,
202+
in_shifting_group: bool = False,
202203
) -> EVChargerPool:
203204
"""Return the corresponding EVChargerPool instance for the given ids.
204205
@@ -211,6 +212,8 @@ def ev_charger_pool(
211212
EVChargerPool.
212213
name: An optional name used to identify this instance of the pool or a
213214
corresponding actor in the logs.
215+
in_shifting_group: Whether the power requests get sent to the shifting group
216+
in the PowerManager or not.
214217
215218
Returns:
216219
An EVChargerPool instance.
@@ -264,6 +267,7 @@ def ev_charger_pool(
264267
pool_ref_store=self._ev_charger_pool_reference_stores[ref_store_key],
265268
name=name,
266269
priority=priority,
270+
in_shifting_group=in_shifting_group,
267271
)
268272

269273
def pv_pool(
@@ -272,6 +276,7 @@ def pv_pool(
272276
priority: int,
273277
component_ids: abc.Set[int] | None = None,
274278
name: str | None = None,
279+
in_shifting_group: bool = False,
275280
) -> PVPool:
276281
"""Return a new `PVPool` instance for the given ids.
277282
@@ -284,6 +289,8 @@ def pv_pool(
284289
`PVPool`.
285290
name: An optional name used to identify this instance of the pool or a
286291
corresponding actor in the logs.
292+
in_shifting_group: Whether the power requests get sent to the shifting group
293+
in the PowerManager or not.
287294
288295
Returns:
289296
A `PVPool` instance.
@@ -334,6 +341,7 @@ def pv_pool(
334341
pool_ref_store=self._pv_pool_reference_stores[ref_store_key],
335342
name=name,
336343
priority=priority,
344+
in_shifting_group=in_shifting_group,
337345
)
338346

339347
def battery_pool(
@@ -342,6 +350,7 @@ def battery_pool(
342350
priority: int,
343351
component_ids: abc.Set[int] | None = None,
344352
name: str | None = None,
353+
in_shifting_group: bool = False,
345354
) -> BatteryPool:
346355
"""Return a new `BatteryPool` instance for the given ids.
347356
@@ -354,6 +363,8 @@ def battery_pool(
354363
`BatteryPool`.
355364
name: An optional name used to identify this instance of the pool or a
356365
corresponding actor in the logs.
366+
in_shifting_group: Whether the power requests get sent to the shifting group
367+
in the PowerManager or not.
357368
358369
Returns:
359370
A `BatteryPool` instance.
@@ -409,6 +420,7 @@ def battery_pool(
409420
pool_ref_store=self._battery_pool_reference_stores[ref_store_key],
410421
name=name,
411422
priority=priority,
423+
in_shifting_group=in_shifting_group,
412424
)
413425

414426
def _data_sourcing_request_sender(self) -> Sender[ComponentMetricRequest]:
@@ -519,6 +531,7 @@ def ev_charger_pool(
519531
priority: int,
520532
component_ids: abc.Set[int] | None = None,
521533
name: str | None = None,
534+
in_shifting_group: bool = False,
522535
) -> EVChargerPool:
523536
"""Return a new `EVChargerPool` instance for the given parameters.
524537
@@ -544,12 +557,17 @@ def ev_charger_pool(
544557
component graph are used.
545558
name: An optional name used to identify this instance of the pool or a
546559
corresponding actor in the logs.
560+
in_shifting_group: Whether the power requests get sent to the shifting group
561+
in the PowerManager or not.
547562
548563
Returns:
549564
An `EVChargerPool` instance.
550565
"""
551566
return _get().ev_charger_pool(
552-
priority=priority, component_ids=component_ids, name=name
567+
priority=priority,
568+
component_ids=component_ids,
569+
name=name,
570+
in_shifting_group=in_shifting_group,
553571
)
554572

555573

@@ -558,6 +576,7 @@ def battery_pool(
558576
priority: int,
559577
component_ids: abc.Set[int] | None = None,
560578
name: str | None = None,
579+
in_shifting_group: bool = False,
561580
) -> BatteryPool:
562581
"""Return a new `BatteryPool` instance for the given parameters.
563582
@@ -583,12 +602,17 @@ def battery_pool(
583602
graph are used.
584603
name: An optional name used to identify this instance of the pool or a
585604
corresponding actor in the logs.
605+
in_shifting_group: Whether the power requests get sent to the shifting group
606+
in the PowerManager or not.
586607
587608
Returns:
588609
A `BatteryPool` instance.
589610
"""
590611
return _get().battery_pool(
591-
priority=priority, component_ids=component_ids, name=name
612+
priority=priority,
613+
component_ids=component_ids,
614+
name=name,
615+
in_shifting_group=in_shifting_group,
592616
)
593617

594618

@@ -597,6 +621,7 @@ def pv_pool(
597621
priority: int,
598622
component_ids: abc.Set[int] | None = None,
599623
name: str | None = None,
624+
in_shifting_group: bool = False,
600625
) -> PVPool:
601626
"""Return a new `PVPool` instance for the given parameters.
602627
@@ -622,11 +647,18 @@ def pv_pool(
622647
graph are used.
623648
name: An optional name used to identify this instance of the pool or a
624649
corresponding actor in the logs.
650+
in_shifting_group: Whether the power requests get sent to the shifting group
651+
in the PowerManager or not.
625652
626653
Returns:
627654
A `PVPool` instance.
628655
"""
629-
return _get().pv_pool(priority=priority, component_ids=component_ids, name=name)
656+
return _get().pv_pool(
657+
priority=priority,
658+
component_ids=component_ids,
659+
name=name,
660+
in_shifting_group=in_shifting_group,
661+
)
630662

631663

632664
def grid() -> Grid:

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
pool_ref_store: BatteryPoolReferenceStore,
6060
name: str | None,
6161
priority: int,
62+
in_shifting_group: bool,
6263
):
6364
"""Create a BatteryPool instance.
6465
@@ -72,11 +73,14 @@ def __init__(
7273
name: An optional name used to identify this instance of the pool or a
7374
corresponding actor in the logs.
7475
priority: The priority of the actor using this wrapper.
76+
in_shifting_group: Whether the power requests get sent to the shifting group
77+
in the PowerManager or not.
7578
"""
7679
self._pool_ref_store = pool_ref_store
7780
unique_id = str(uuid.uuid4())
7881
self._source_id = unique_id if name is None else f"{name}-{unique_id}"
7982
self._priority = priority
83+
self._in_shifting_group = in_shifting_group
8084

8185
async def propose_power(
8286
self,
@@ -130,6 +134,7 @@ async def propose_power(
130134
priority=self._priority,
131135
creation_time=asyncio.get_running_loop().time(),
132136
request_timeout=request_timeout,
137+
in_shifting_group=self._in_shifting_group,
133138
)
134139
)
135140

@@ -176,6 +181,7 @@ async def propose_charge(
176181
priority=self._priority,
177182
creation_time=asyncio.get_running_loop().time(),
178183
request_timeout=request_timeout,
184+
in_shifting_group=self._in_shifting_group,
179185
)
180186
)
181187

@@ -224,6 +230,7 @@ async def propose_discharge(
224230
priority=self._priority,
225231
creation_time=asyncio.get_running_loop().time(),
226232
request_timeout=request_timeout,
233+
in_shifting_group=self._in_shifting_group,
227234
)
228235
)
229236

@@ -382,6 +389,7 @@ def power_status(self) -> ReceiverFetcher[BatteryPoolReport]:
382389
source_id=self._source_id,
383390
priority=self._priority,
384391
component_ids=self._pool_ref_store._batteries,
392+
in_shifting_group=self._in_shifting_group,
385393
)
386394
self._pool_ref_store._power_bounds_subs[sub.get_channel_name()] = (
387395
asyncio.create_task(

src/frequenz/sdk/timeseries/ev_charger_pool/_ev_charger_pool.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__( # pylint: disable=too-many-arguments
4545
pool_ref_store: EVChargerPoolReferenceStore,
4646
name: str | None,
4747
priority: int,
48+
in_shifting_group: bool,
4849
) -> None:
4950
"""Create an `EVChargerPool` instance.
5051
@@ -58,11 +59,14 @@ def __init__( # pylint: disable=too-many-arguments
5859
name: An optional name used to identify this instance of the pool or a
5960
corresponding actor in the logs.
6061
priority: The priority of the actor using this wrapper.
62+
in_shifting_group: Whether the power requests get sent to the shifting group
63+
in the PowerManager or not.
6164
"""
6265
self._pool_ref_store = pool_ref_store
6366
unique_id = str(uuid.uuid4())
6467
self._source_id = unique_id if name is None else f"{name}-{unique_id}"
6568
self._priority = priority
69+
self._in_shifting_group = in_shifting_group
6670

6771
async def propose_power(
6872
self,
@@ -128,6 +132,7 @@ async def propose_power(
128132
priority=self._priority,
129133
creation_time=asyncio.get_running_loop().time(),
130134
request_timeout=request_timeout,
135+
in_shifting_group=self._in_shifting_group,
131136
)
132137
)
133138

@@ -210,6 +215,7 @@ def power_status(self) -> ReceiverFetcher[EVChargerPoolReport]:
210215
source_id=self._source_id,
211216
priority=self._priority,
212217
component_ids=self._pool_ref_store.component_ids,
218+
in_shifting_group=self._in_shifting_group,
213219
)
214220
self._pool_ref_store.power_bounds_subs[sub.get_channel_name()] = (
215221
asyncio.create_task(

src/frequenz/sdk/timeseries/pv_pool/_pv_pool.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__( # pylint: disable=too-many-arguments
3838
pool_ref_store: PVPoolReferenceStore,
3939
name: str | None,
4040
priority: int,
41+
in_shifting_group: bool,
4142
) -> None:
4243
"""Initialize the instance.
4344
@@ -50,11 +51,14 @@ def __init__( # pylint: disable=too-many-arguments
5051
pool_ref_store: The reference store for the PV pool.
5152
name: The name of the PV pool.
5253
priority: The priority of the PV pool.
54+
in_shifting_group: Whether the power requests get sent to the shifting group
55+
in the PowerManager or not.
5356
"""
5457
self._pool_ref_store = pool_ref_store
5558
unique_id = uuid.uuid4()
5659
self._source_id = str(unique_id) if name is None else f"{name}-{unique_id}"
5760
self._priority = priority
61+
self._in_shifting_group = in_shifting_group
5862

5963
async def propose_power(
6064
self,
@@ -117,6 +121,7 @@ async def propose_power(
117121
priority=self._priority,
118122
creation_time=asyncio.get_running_loop().time(),
119123
request_timeout=request_timeout,
124+
in_shifting_group=self._in_shifting_group,
120125
)
121126
)
122127

@@ -171,6 +176,7 @@ def power_status(self) -> ReceiverFetcher[PVPoolReport]:
171176
source_id=self._source_id,
172177
priority=self._priority,
173178
component_ids=self._pool_ref_store.component_ids,
179+
in_shifting_group=self._in_shifting_group,
174180
)
175181
self._pool_ref_store.power_bounds_subs[sub.get_channel_name()] = (
176182
asyncio.create_task(

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def tgt_power( # pylint: disable=too-many-arguments
5353
if creation_time is not None
5454
else asyncio.get_event_loop().time()
5555
),
56+
in_shifting_group=False,
5657
),
5758
self._system_bounds,
5859
must_send,

0 commit comments

Comments
 (0)