Skip to content

Commit 29aa8e8

Browse files
committed
Add boiler plate to setup PowerDistributingActor to DataPipeline
This sets up a single-user PowerDistributingActor. Multiple usecase actors will be supported once PowerManager is implemented. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent fb3972d commit 29aa8e8

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
import typing
1414
from dataclasses import dataclass
15+
from datetime import timedelta
1516

16-
from frequenz.channels import Broadcast, Sender
17+
from frequenz.channels import Bidirectional, Broadcast, Sender
1718

1819
# A number of imports had to be done inside functions where they are used, to break
1920
# import cycles.
@@ -26,6 +27,12 @@
2627
DataSourcingActor,
2728
ResamplerConfig,
2829
)
30+
from ..actor.power_distributing import (
31+
BatteryStatus,
32+
PowerDistributingActor,
33+
Request,
34+
Result,
35+
)
2936
from ..timeseries.ev_charger_pool import EVChargerPool
3037
from ..timeseries.logical_meter import LogicalMeter
3138

@@ -70,6 +77,13 @@ def __init__(
7077

7178
self._data_sourcing_actor: _ActorInfo | None = None
7279
self._resampling_actor: _ActorInfo | None = None
80+
81+
self._power_distribution_channel = Bidirectional["Request", "Result"](
82+
"Default", "Power Distributing Actor"
83+
)
84+
85+
self._power_distributing_actor: "PowerDistributingActor" | None = None
86+
7387
self._logical_meter: "LogicalMeter" | None = None
7488
self._ev_charger_pools: dict[frozenset[int], "EVChargerPool"] = {}
7589

@@ -123,6 +137,32 @@ def ev_charger_pool(
123137
)
124138
return self._ev_charger_pools[key]
125139

140+
def power_distributing_handle(self) -> Bidirectional.Handle[Request, Result]:
141+
"""Return the handle to the power distributing actor.
142+
143+
Returns:
144+
A Bidirectional handle to communicate with the power distributing actor.
145+
"""
146+
if not self._power_distributing_actor:
147+
self._start_power_distributing_actor()
148+
149+
return self._power_distribution_channel.client_handle
150+
151+
def _start_power_distributing_actor(self) -> None:
152+
"""Start the power distributing actor if it is not already running."""
153+
if self._power_distributing_actor:
154+
return
155+
156+
from ..actor.power_distributing import PowerDistributingActor
157+
158+
# The PowerDistributingActor is started with only a single default user channel.
159+
# Until the PowerManager is implemented, support for multiple use-case actors
160+
# will not be available in the high level interface.
161+
self._power_distributing_actor = PowerDistributingActor(
162+
users_channels={"default": self._power_distribution_channel.service_handle},
163+
battery_status_sender=self._battery_status_channel.new_sender(),
164+
)
165+
126166
def _data_sourcing_request_sender(self) -> Sender[ComponentMetricRequest]:
127167
"""Return a Sender for sending requests to the data sourcing actor.
128168

0 commit comments

Comments
 (0)