Skip to content

Commit d3f7fdf

Browse files
Add function that returns the grid component
The code of the new function has been removed from the `_get_grid_component_successors` function such that it can be used separately. It returns the first grid element from the graph or raises if none has been found. Signed-off-by: Matthias Wende <[email protected]>
1 parent 0152770 commit d3f7fdf

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/frequenz/sdk/timeseries/_formula_engine/_formula_generators/_formula_generator.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ def _get_builder(
101101
)
102102
return builder
103103

104-
def _get_grid_component_successors(self) -> set[component.Component]:
105-
"""Get the set of grid component successors in the component graph.
104+
def _get_grid_component(self) -> component.Component:
105+
"""
106+
Get the grid component in the component graph.
106107
107108
Returns:
108-
A set of grid component successors.
109+
The first grid component found in the graph.
109110
110111
Raises:
111112
ComponentNotFound: If the grid component is not found in the component graph.
112-
ComponentNotFound: If no successor components are found in the component graph.
113113
"""
114114
component_graph = connection_manager.get().component_graph
115115
grid_component = next(
@@ -120,10 +120,22 @@ def _get_grid_component_successors(self) -> set[component.Component]:
120120
),
121121
None,
122122
)
123-
124123
if grid_component is None:
125124
raise ComponentNotFound("Grid component not found in the component graph.")
126125

126+
return grid_component
127+
128+
def _get_grid_component_successors(self) -> set[component.Component]:
129+
"""Get the set of grid component successors in the component graph.
130+
131+
Returns:
132+
A set of grid component successors.
133+
134+
Raises:
135+
ComponentNotFound: If no successor components are found in the component graph.
136+
"""
137+
grid_component = self._get_grid_component()
138+
component_graph = connection_manager.get().component_graph
127139
grid_successors = component_graph.successors(grid_component.component_id)
128140

129141
if not grid_successors:

0 commit comments

Comments
 (0)