Skip to content

Commit 0a009a3

Browse files
Expose producer component through the microgrid
Signed-off-by: Daniel Zullo <[email protected]>
1 parent fe9953d commit 0a009a3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
similarly the total CHP production in a site can be streamed through
8080
[`chp_power`][frequenz.sdk.timeseries.logical_meter.LogicalMeter.chp_power]. And total
8181
producer power is available through
82-
[`producer_power`][frequenz.sdk.timeseries.logical_meter.LogicalMeter.producer_power].
82+
[`producer_power`][frequenz.sdk.timeseries.producer.Producer.power].
8383
8484
As is the case with the other methods, if PV Arrays or CHPs are not available in a
8585
microgrid, the corresponding methods stream zero values.
@@ -130,6 +130,7 @@
130130
frequency,
131131
grid,
132132
logical_meter,
133+
producer,
133134
voltage,
134135
)
135136

@@ -157,5 +158,6 @@ async def initialize(host: str, port: int, resampler_config: ResamplerConfig) ->
157158
"frequency",
158159
"logical_meter",
159160
"metadata",
161+
"producer",
160162
"voltage",
161163
]

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from ..timeseries.consumer import Consumer
5050
from ..timeseries.ev_charger_pool import EVChargerPool
5151
from ..timeseries.logical_meter import LogicalMeter
52+
from ..timeseries.producer import Producer
5253

5354

5455
_REQUEST_RECV_BUFFER_SIZE = 500
@@ -120,6 +121,7 @@ def __init__(
120121

121122
self._logical_meter: LogicalMeter | None = None
122123
self._consumer: Consumer | None = None
124+
self._producer: Producer | None = None
123125
self._grid: Grid | None = None
124126
self._ev_charger_pools: dict[frozenset[int], EVChargerPool] = {}
125127
self._battery_pools: dict[frozenset[int], BatteryPoolReferenceStore] = {}
@@ -188,6 +190,23 @@ def consumer(self) -> Consumer:
188190
)
189191
return self._consumer
190192

193+
def producer(self) -> Producer:
194+
"""Return the producer instance.
195+
196+
If a Producer instance doesn't exist, a new one is created and returned.
197+
198+
Returns:
199+
A Producer instance.
200+
"""
201+
from ..timeseries.producer import Producer
202+
203+
if self._producer is None:
204+
self._producer = Producer(
205+
channel_registry=self._channel_registry,
206+
resampler_subscription_sender=self._resampling_request_sender(),
207+
)
208+
return self._producer
209+
191210
def ev_charger_pool(
192211
self,
193212
ev_charger_ids: set[int] | None = None,
@@ -471,6 +490,11 @@ def consumer() -> Consumer:
471490
return _get().consumer()
472491

473492

493+
def producer() -> Producer:
494+
"""Return the [`Production`][frequenz.sdk.timeseries.producer.Producer] measuring point."""
495+
return _get().producer()
496+
497+
474498
def ev_charger_pool(ev_charger_ids: set[int] | None = None) -> EVChargerPool:
475499
"""Return the corresponding EVChargerPool instance for the given ids.
476500

0 commit comments

Comments
 (0)