Skip to content

Commit d32719f

Browse files
authored
Rename ComponentGraph.components() parameters to be plural (#791)
2 parents 9febd66 + 3d06478 commit d32719f

File tree

17 files changed

+60
-50
lines changed

17 files changed

+60
-50
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
grid_current_recv = grid.current.new_receiver()
4545
```
4646

47+
- The `ComponentGraph.components()` parameters `component_id` and `component_category` were renamed to `component_ids` and `component_categories`, respectively.
48+
4749
## New Features
4850

4951
<!-- Here goes the main new features and examples or instructions on how to use them -->

benchmarks/power_distribution/power_distributor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async def run() -> None:
141141
)
142142

143143
all_batteries: set[Component] = connection_manager.get().component_graph.components(
144-
component_category={ComponentCategory.BATTERY}
144+
component_categories={ComponentCategory.BATTERY}
145145
)
146146
batteries_ids = {c.component_id for c in all_batteries}
147147
# Take some time to get data from components

src/frequenz/sdk/actor/power_distributing/_component_managers/_battery_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(
128128
):
129129
"""Initialize the battery data manager."""
130130
self._batteries = connection_manager.get().component_graph.components(
131-
component_category={ComponentCategory.BATTERY}
131+
component_categories={ComponentCategory.BATTERY}
132132
)
133133
self._battery_ids = {battery.component_id for battery in self._batteries}
134134

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def _start_power_managing_actor(self) -> None:
271271
# constraint needs to be relaxed if the actor is extended to support other
272272
# components.
273273
if not component_graph.components(
274-
component_category={ComponentCategory.BATTERY}
274+
component_categories={ComponentCategory.BATTERY}
275275
):
276276
_logger.warning(
277277
"No batteries found in the component graph. "
@@ -306,7 +306,7 @@ def _start_power_distributing_actor(self) -> None:
306306

307307
component_graph = connection_manager.get().component_graph
308308
if not component_graph.components(
309-
component_category={ComponentCategory.BATTERY}
309+
component_categories={ComponentCategory.BATTERY}
310310
):
311311
_logger.warning(
312312
"No batteries found in the component graph. "

src/frequenz/sdk/microgrid/component_graph.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ class ComponentGraph(ABC):
4545
@abstractmethod
4646
def components(
4747
self,
48-
component_id: set[int] | None = None,
49-
component_category: set[ComponentCategory] | None = None,
48+
component_ids: set[int] | None = None,
49+
component_categories: set[ComponentCategory] | None = None,
5050
) -> set[Component]:
5151
"""Fetch the components of the microgrid.
5252
5353
Args:
54-
component_id: filter out any components not matching one of the provided IDs
55-
component_category: filter out any components not matching one of the
54+
component_ids: filter out any components not matching one of the provided IDs
55+
component_categories: filter out any components not matching one of the
5656
provided types
5757
5858
Returns:
5959
Set of the components currently connected to the microgrid, filtered by
60-
the provided `component_id` and `component_category` values.
60+
the provided `component_ids` and `component_categories` values.
6161
"""
6262

6363
@abstractmethod
@@ -331,31 +331,31 @@ def __init__(
331331

332332
def components(
333333
self,
334-
component_id: set[int] | None = None,
335-
component_category: set[ComponentCategory] | None = None,
334+
component_ids: set[int] | None = None,
335+
component_categories: set[ComponentCategory] | None = None,
336336
) -> set[Component]:
337337
"""Fetch the components of the microgrid.
338338
339339
Args:
340-
component_id: filter out any components not matching one of the provided IDs
341-
component_category: filter out any components not matching one of the
340+
component_ids: filter out any components not matching one of the provided IDs
341+
component_categories: filter out any components not matching one of the
342342
provided types
343343
344344
Returns:
345345
Set of the components currently connected to the microgrid, filtered by
346-
the provided `component_id` and `component_category` values.
346+
the provided `component_ids` and `component_categories` values.
347347
"""
348-
if component_id is None:
348+
if component_ids is None:
349349
# If any node has not node[1], then it will not pass validations step.
350350
selection: Iterable[Component] = map(
351351
lambda node: Component(**(node[1])), self._graph.nodes(data=True)
352352
)
353353
else:
354-
valid_ids = filter(self._graph.has_node, component_id)
354+
valid_ids = filter(self._graph.has_node, component_ids)
355355
selection = map(lambda idx: Component(**self._graph.nodes[idx]), valid_ids)
356356

357-
if component_category is not None:
358-
types: set[ComponentCategory] = component_category
357+
if component_categories is not None:
358+
types: set[ComponentCategory] = component_categories
359359
selection = filter(lambda c: c.category in types, selection)
360360

361361
return set(selection)
@@ -832,7 +832,7 @@ def _validate_grid_endpoint(self) -> None:
832832
it has no successors in the graph (i.e. it is not connected to
833833
anything)
834834
"""
835-
grid = list(self.components(component_category={ComponentCategory.GRID}))
835+
grid = list(self.components(component_categories={ComponentCategory.GRID}))
836836

837837
if len(grid) == 0:
838838
# it's OK to not have a grid endpoint as long as other properties
@@ -865,7 +865,7 @@ def _validate_intermediary_components(self) -> None:
865865
or zero successors
866866
"""
867867
intermediary_components = list(
868-
self.components(component_category={ComponentCategory.INVERTER})
868+
self.components(component_categories={ComponentCategory.INVERTER})
869869
)
870870

871871
missing_predecessors = list(
@@ -893,7 +893,7 @@ def _validate_leaf_components(self) -> None:
893893
"""
894894
leaf_components = list(
895895
self.components(
896-
component_category={
896+
component_categories={
897897
ComponentCategory.BATTERY,
898898
ComponentCategory.EV_CHARGER,
899899
}

src/frequenz/sdk/timeseries/battery_pool/_battery_pool_reference_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _get_all_batteries(self) -> frozenset[int]:
126126
{
127127
battery.component_id
128128
for battery in graph.components(
129-
component_category={ComponentCategory.BATTERY}
129+
component_categories={ComponentCategory.BATTERY}
130130
)
131131
}
132132
)

src/frequenz/sdk/timeseries/ev_charger_pool/_ev_charger_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
self._component_ids = {
112112
evc.component_id
113113
for evc in graph.components(
114-
component_category={ComponentCategory.EV_CHARGER}
114+
component_categories={ComponentCategory.EV_CHARGER}
115115
)
116116
}
117117
self._state_tracker: StateTracker | None = None

src/frequenz/sdk/timeseries/ev_charger_pool/_set_current_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def _run(self) -> None:
8787
"""
8888
api_client = connection_manager.get().api_client
8989
graph = connection_manager.get().component_graph
90-
meters = graph.components(component_category={ComponentCategory.METER})
90+
meters = graph.components(component_categories={ComponentCategory.METER})
9191
if not meters:
9292
err = "No meters found in the component graph."
9393
_logger.error(err)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _get_grid_component(self) -> component.Component:
107107
grid_component = next(
108108
iter(
109109
component_graph.components(
110-
component_category={component.ComponentCategory.GRID}
110+
component_categories={component.ComponentCategory.GRID}
111111
)
112112
),
113113
None,

src/frequenz/sdk/timeseries/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def initialize(
145145

146146
grid_connections = list(
147147
connection_manager.get().component_graph.components(
148-
component_category={ComponentCategory.GRID},
148+
component_categories={ComponentCategory.GRID},
149149
)
150150
)
151151

0 commit comments

Comments
 (0)