Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->
- 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.

## Bug Fixes

Expand Down
25 changes: 25 additions & 0 deletions src/frequenz/gridpool/_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@

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

import logging

from frequenz.client.assets import AssetsApiClient
from frequenz.client.assets.electrical_component import (
Breaker,
ComponentConnection,
ElectricalComponent,
)
from frequenz.client.common.microgrid import MicrogridId
from frequenz.client.common.microgrid.electrical_components import ElectricalComponentId
from frequenz.microgrid_component_graph import ComponentGraph

_logger = logging.getLogger(__name__)


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

breakers = [c for c in components if isinstance(c, Breaker)]
connected_breakers = [
b
for b in breakers
if any(
b.id in (c.source, c.destination) for c in connections if c is not None
)
]

if connected_breakers:
_logger.warning(
"The following breakers are connected to other components, "
+ "which is not supported by the component graph generator and may "
+ "lead to graph traversal issues: %s",
[b.id for b in connected_breakers],
)
elif breakers:
_logger.debug("Dropping unconnected breakers: %s", [b.id for b in breakers])
components = [c for c in components if not isinstance(c, Breaker)]

graph = ComponentGraph[
ElectricalComponent, ComponentConnection, ElectricalComponentId
](components, connections)
Expand Down
Loading