Skip to content

Commit 0927cb9

Browse files
committed
Expose power distribution results from PVPool and EVChargerPool
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 2a93619 commit 0927cb9

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ def new_ev_charger_pool(
269269
power_manager_bounds_subs_sender=(
270270
self._ev_power_wrapper.bounds_subscription_channel.new_sender()
271271
),
272+
power_distribution_results_fetcher=(
273+
self._ev_power_wrapper.distribution_results_fetcher()
274+
),
272275
component_ids=component_ids,
273276
)
274277
)
@@ -343,6 +346,9 @@ def new_pv_pool(
343346
power_manager_bounds_subs_sender=(
344347
self._pv_power_wrapper.bounds_subscription_channel.new_sender()
345348
),
349+
power_distribution_results_fetcher=(
350+
self._pv_power_wrapper.distribution_results_fetcher()
351+
),
346352
component_ids=component_ids,
347353
)
348354

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import uuid
99
from collections import abc
1010

11-
from ..._internal._channels import ReceiverFetcher
12-
from ...actor import _power_managing
11+
from ..._internal._channels import ReceiverFetcher, ReceiverFetcherWith
12+
from ...actor import _power_managing, power_distributing
1313
from ...timeseries import Bounds
1414
from .._base_types import SystemBounds
1515
from .._quantities import Current, Power
@@ -227,6 +227,21 @@ def power_status(self) -> ReceiverFetcher[EVChargerPoolReport]:
227227

228228
return channel
229229

230+
@property
231+
def power_distribution_results(self) -> ReceiverFetcher[power_distributing.Result]:
232+
"""Get a receiver to receive power distribution results.
233+
234+
Returns:
235+
A receiver that will stream power distribution results for the pool's set of
236+
EV chargers.
237+
"""
238+
return ReceiverFetcherWith(
239+
self._pool_ref_store.power_distribution_results_fetcher,
240+
lambda recv: recv.filter(
241+
lambda x: x.request.component_ids == self._pool_ref_store.component_ids
242+
),
243+
)
244+
230245
async def stop(self) -> None:
231246
"""Stop all tasks and channels owned by the EVChargerPool."""
232247
await self._pool_ref_store.stop()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
"""Manages shared state/tasks for a set of EV chargers."""
55

6-
76
import asyncio
87
import uuid
98
from collections import abc
109

1110
from frequenz.channels import Broadcast, Receiver, Sender
1211
from frequenz.client.microgrid import ComponentCategory
1312

13+
from ..._internal._channels import ReceiverFetcher
1414
from ...actor import ChannelRegistry, ComponentMetricRequest
1515
from ...actor._power_managing._base_classes import Proposal, ReportRequest
16-
from ...actor.power_distributing import ComponentPoolStatus
16+
from ...actor.power_distributing import ComponentPoolStatus, Result
1717
from ...microgrid import connection_manager
1818
from .._base_types import SystemBounds
1919
from ..formula_engine._formula_engine_pool import FormulaEnginePool
@@ -40,6 +40,7 @@ def __init__( # pylint: disable=too-many-arguments
4040
status_receiver: Receiver[ComponentPoolStatus],
4141
power_manager_requests_sender: Sender[Proposal],
4242
power_manager_bounds_subs_sender: Sender[ReportRequest],
43+
power_distribution_results_fetcher: ReceiverFetcher[Result],
4344
component_ids: abc.Set[int] | None = None,
4445
):
4546
"""Create an instance of the class.
@@ -55,6 +56,8 @@ def __init__( # pylint: disable=too-many-arguments
5556
requests to the power managing actor.
5657
power_manager_bounds_subs_sender: A Channel sender for sending power bounds
5758
subscription requests to the power managing actor.
59+
power_distribution_results_fetcher: A ReceiverFetcher for the results from
60+
the power distributing actor.
5861
component_ids: An optional list of component_ids belonging to this pool. If
5962
not specified, IDs of all EV Chargers in the microgrid will be fetched
6063
from the component graph.
@@ -64,6 +67,7 @@ def __init__( # pylint: disable=too-many-arguments
6467
self.status_receiver = status_receiver
6568
self.power_manager_requests_sender = power_manager_requests_sender
6669
self.power_manager_bounds_subs_sender = power_manager_bounds_subs_sender
70+
self.power_distribution_results_fetcher = power_distribution_results_fetcher
6771

6872
if component_ids is not None:
6973
self.component_ids: frozenset[int] = frozenset(component_ids)

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import uuid
88
from collections import abc
99

10-
from ..._internal._channels import ReceiverFetcher
11-
from ...actor import _power_managing
10+
from ..._internal._channels import ReceiverFetcher, ReceiverFetcherWith
11+
from ...actor import _power_managing, power_distributing
1212
from ...timeseries import Bounds
1313
from .._base_types import SystemBounds
1414
from .._quantities import Power
@@ -186,6 +186,21 @@ def power_status(self) -> ReceiverFetcher[PVPoolReport]:
186186

187187
return channel
188188

189+
@property
190+
def power_distribution_results(self) -> ReceiverFetcher[power_distributing.Result]:
191+
"""Get a receiver to receive power distribution results.
192+
193+
Returns:
194+
A receiver that will stream power distribution results for the pool's set of
195+
PV inverters.
196+
"""
197+
return ReceiverFetcherWith(
198+
self._pool_ref_store.power_distribution_results_fetcher,
199+
lambda recv: recv.filter(
200+
lambda x: x.request.component_ids == self._pool_ref_store.component_ids
201+
),
202+
)
203+
189204
async def stop(self) -> None:
190205
"""Stop all tasks and channels owned by the PVPool."""
191206
await self._pool_ref_store.stop()

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
from frequenz.channels import Broadcast, Receiver, Sender
1212
from frequenz.client.microgrid import ComponentCategory, InverterType
1313

14+
from ..._internal._channels import ReceiverFetcher
1415
from ...actor import ChannelRegistry, ComponentMetricRequest
1516
from ...actor._power_managing._base_classes import Proposal, ReportRequest
16-
from ...actor.power_distributing import ComponentPoolStatus
17+
from ...actor.power_distributing import ComponentPoolStatus, Result
1718
from ...microgrid import connection_manager
1819
from .._base_types import SystemBounds
1920
from ..formula_engine._formula_engine_pool import FormulaEnginePool
@@ -40,6 +41,7 @@ def __init__( # pylint: disable=too-many-arguments
4041
status_receiver: Receiver[ComponentPoolStatus],
4142
power_manager_requests_sender: Sender[Proposal],
4243
power_manager_bounds_subs_sender: Sender[ReportRequest],
44+
power_distribution_results_fetcher: ReceiverFetcher[Result],
4345
component_ids: abc.Set[int] | None = None,
4446
):
4547
"""Initialize this instance.
@@ -55,6 +57,8 @@ def __init__( # pylint: disable=too-many-arguments
5557
requests to the power managing actor.
5658
power_manager_bounds_subs_sender: A Channel sender for sending power bounds
5759
subscription requests to the power managing actor.
60+
power_distribution_results_fetcher: A ReceiverFetcher for the results from
61+
the power distributing actor.
5862
component_ids: An optional list of component_ids belonging to this pool. If
5963
not specified, IDs of all PV inverters in the microgrid will be fetched
6064
from the component graph.
@@ -64,6 +68,7 @@ def __init__( # pylint: disable=too-many-arguments
6468
self.status_receiver = status_receiver
6569
self.power_manager_requests_sender = power_manager_requests_sender
6670
self.power_manager_bounds_subs_sender = power_manager_bounds_subs_sender
71+
self.power_distribution_results_fetcher = power_distribution_results_fetcher
6772

6873
if component_ids is not None:
6974
self.component_ids: frozenset[int] = frozenset(component_ids)

0 commit comments

Comments
 (0)