|
3 | 3 |
|
4 | 4 | """Formula generation from assets API component/connection configurations.""" |
5 | 5 |
|
| 6 | +import logging |
| 7 | + |
6 | 8 | from frequenz.client.assets import AssetsApiClient |
7 | 9 | from frequenz.client.assets.electrical_component import ( |
| 10 | + Breaker, |
8 | 11 | ComponentConnection, |
9 | 12 | ElectricalComponent, |
10 | 13 | ) |
11 | 14 | from frequenz.client.common.microgrid import MicrogridId |
12 | 15 | from frequenz.client.common.microgrid.electrical_components import ElectricalComponentId |
13 | 16 | from frequenz.microgrid_component_graph import ComponentGraph |
14 | 17 |
|
| 18 | +_logger = logging.getLogger(__name__) |
| 19 | + |
15 | 20 |
|
16 | 21 | class ComponentGraphGenerator: |
17 | 22 | """Generates component graphs for microgrids using the Assets API.""" |
@@ -57,6 +62,26 @@ async def get_component_graph( |
57 | 62 | if any(c is None for c in connections): |
58 | 63 | raise ValueError("Failed to load all electrical component connections.") |
59 | 64 |
|
| 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 | + |
60 | 85 | graph = ComponentGraph[ |
61 | 86 | ElectricalComponent, ComponentConnection, ElectricalComponentId |
62 | 87 | ](components, connections) |
|
0 commit comments