Skip to content

Commit 630d344

Browse files
committed
Start PowerDistributingActor only if there are batteries present
... in the microgrid, according to the ComponentGraph. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 4cdecb1 commit 630d344

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010

1111
from __future__ import annotations
1212

13+
import logging
1314
import typing
1415
from collections import abc
1516
from dataclasses import dataclass
1617

1718
from frequenz.channels import Bidirectional, Broadcast, Sender
1819

20+
from . import connection_manager
21+
from .component import ComponentCategory
22+
23+
logger = logging.getLogger(__name__)
24+
1925
# A number of imports had to be done inside functions where they are used, to break
2026
# import cycles.
2127
#
@@ -101,7 +107,6 @@ def logical_meter(self) -> LogicalMeter:
101107
Returns:
102108
A logical meter instance.
103109
"""
104-
from ..microgrid import connection_manager
105110
from ..timeseries.logical_meter import LogicalMeter
106111

107112
if self._logical_meter is None:
@@ -196,6 +201,16 @@ def _start_power_distributing_actor(self) -> None:
196201
if self._power_distributing_actor:
197202
return
198203

204+
component_graph = connection_manager.get().component_graph
205+
if not component_graph.components(
206+
component_category={ComponentCategory.BATTERY}
207+
):
208+
logger.warning(
209+
"No batteries found in the component graph. "
210+
"The power distributing actor will not be started."
211+
)
212+
return
213+
199214
from ..actor.power_distributing import PowerDistributingActor
200215

201216
# The PowerDistributingActor is started with only a single default user channel.

0 commit comments

Comments
 (0)