Skip to content

Commit fe9953d

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

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
6969
This is the main power consumer at the site of a microgrid, and often the
7070
{{glossary("load")}} the microgrid is built to support. The power drawn by the consumer
71-
is available through
72-
[`consumer_power`][frequenz.sdk.timeseries.logical_meter.LogicalMeter.consumer_power]
71+
is available through [`consumer_power`][frequenz.sdk.timeseries.consumer.Consumer.power]
7372
7473
In locations without a consumer, this method streams zero values.
7574
@@ -126,6 +125,7 @@
126125
from . import _data_pipeline, client, component, connection_manager, metadata
127126
from ._data_pipeline import (
128127
battery_pool,
128+
consumer,
129129
ev_charger_pool,
130130
frequency,
131131
grid,
@@ -150,6 +150,7 @@ async def initialize(host: str, port: int, resampler_config: ResamplerConfig) ->
150150
"initialize",
151151
"client",
152152
"component",
153+
"consumer",
153154
"battery_pool",
154155
"ev_charger_pool",
155156
"grid",

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from ..timeseries.battery_pool._battery_pool_reference_store import (
4747
BatteryPoolReferenceStore,
4848
)
49+
from ..timeseries.consumer import Consumer
4950
from ..timeseries.ev_charger_pool import EVChargerPool
5051
from ..timeseries.logical_meter import LogicalMeter
5152

@@ -118,6 +119,7 @@ def __init__(
118119
self._power_managing_actor: _power_managing.PowerManagingActor | None = None
119120

120121
self._logical_meter: LogicalMeter | None = None
122+
self._consumer: Consumer | None = None
121123
self._grid: Grid | None = None
122124
self._ev_charger_pools: dict[frozenset[int], EVChargerPool] = {}
123125
self._battery_pools: dict[frozenset[int], BatteryPoolReferenceStore] = {}
@@ -169,6 +171,23 @@ def logical_meter(self) -> LogicalMeter:
169171
)
170172
return self._logical_meter
171173

174+
def consumer(self) -> Consumer:
175+
"""Return the consumer instance.
176+
177+
If a Consumer instance doesn't exist, a new one is created and returned.
178+
179+
Returns:
180+
A Consumer instance.
181+
"""
182+
from ..timeseries.consumer import Consumer
183+
184+
if self._consumer is None:
185+
self._consumer = Consumer(
186+
channel_registry=self._channel_registry,
187+
resampler_subscription_sender=self._resampling_request_sender(),
188+
)
189+
return self._consumer
190+
172191
def ev_charger_pool(
173192
self,
174193
ev_charger_ids: set[int] | None = None,
@@ -447,6 +466,11 @@ def logical_meter() -> LogicalMeter:
447466
return _get().logical_meter()
448467

449468

469+
def consumer() -> Consumer:
470+
"""Return the [`Consumption`][frequenz.sdk.timeseries.consumer.Consumer] measuring point."""
471+
return _get().consumer()
472+
473+
450474
def ev_charger_pool(ev_charger_ids: set[int] | None = None) -> EVChargerPool:
451475
"""Return the corresponding EVChargerPool instance for the given ids.
452476

0 commit comments

Comments
 (0)