Skip to content

Commit 8c049ee

Browse files
authored
Hide unconnected breakers from component graph (#68)
2 parents 0455ad3 + 8cf5bcc commit 8c049ee

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
- If there are unconnected breakers at a site, they are now hidden from the component graph. If there are breakers with connections to other components, they are still sent to the component graph. This is a temporary measure until the graph traversal supports breakers.
1414

1515
## Bug Fixes
1616

src/frequenz/gridpool/_graph_generator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33

44
"""Formula generation from assets API component/connection configurations."""
55

6+
import logging
7+
68
from frequenz.client.assets import AssetsApiClient
79
from frequenz.client.assets.electrical_component import (
10+
Breaker,
811
ComponentConnection,
912
ElectricalComponent,
1013
)
1114
from frequenz.client.common.microgrid import MicrogridId
1215
from frequenz.client.common.microgrid.electrical_components import ElectricalComponentId
1316
from frequenz.microgrid_component_graph import ComponentGraph
1417

18+
_logger = logging.getLogger(__name__)
19+
1520

1621
class ComponentGraphGenerator:
1722
"""Generates component graphs for microgrids using the Assets API."""
@@ -57,6 +62,26 @@ async def get_component_graph(
5762
if any(c is None for c in connections):
5863
raise ValueError("Failed to load all electrical component connections.")
5964

65+
breakers = [c for c in components if isinstance(c, Breaker)]
66+
connected_breakers = [
67+
b
68+
for b in breakers
69+
if any(
70+
b.id in (c.source, c.destination) for c in connections if c is not None
71+
)
72+
]
73+
74+
if connected_breakers:
75+
_logger.warning(
76+
"The following breakers are connected to other components, "
77+
+ "which is not supported by the component graph generator and may "
78+
+ "lead to graph traversal issues: %s",
79+
[b.id for b in connected_breakers],
80+
)
81+
elif breakers:
82+
_logger.debug("Dropping unconnected breakers: %s", [b.id for b in breakers])
83+
components = [c for c in components if not isinstance(c, Breaker)]
84+
6085
graph = ComponentGraph[
6186
ElectricalComponent, ComponentConnection, ElectricalComponentId
6287
](components, connections)

0 commit comments

Comments
 (0)