Skip to content

Commit 0198a42

Browse files
committed
Update .component_id -> .id
The new `Component` class renamed `component_id` with `id`, so we need to update all our references. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 699780f commit 0198a42

30 files changed

+108
-122
lines changed

benchmarks/power_distribution/power_distributor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async def run() -> None:
146146
all_batteries: set[Component] = connection_manager.get().component_graph.components(
147147
component_categories={ComponentCategory.BATTERY}
148148
)
149-
batteries_ids = {c.component_id for c in all_batteries}
149+
batteries_ids = {c.id for c in all_batteries}
150150
# Take some time to get data from components
151151
await asyncio.sleep(4)
152152
with open("/dev/stdout", "w", encoding="utf-8") as csvfile:

src/frequenz/sdk/microgrid/_data_sourcing/microgrid_api_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async def _get_component_category(
170170

171171
api = connection_manager.get().api_client
172172
for comp in await api.list_components():
173-
self._comp_categories_cache[comp.component_id] = comp.category
173+
self._comp_categories_cache[comp.id] = comp.category
174174

175175
if comp_id in self._comp_categories_cache:
176176
return self._comp_categories_cache[comp_id]

src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _get_battery_inverter_mappings(
8383

8484
for battery_id in battery_ids:
8585
inverters: set[ComponentId] = set(
86-
component.component_id
86+
component.id
8787
for component in component_graph.predecessors(battery_id)
8888
if component.category == ComponentCategory.INVERTER
8989
)
@@ -96,7 +96,7 @@ def _get_battery_inverter_mappings(
9696
if bat_bats_map is not None:
9797
bat_bats_map.setdefault(battery_id, set()).update(
9898
set(
99-
component.component_id
99+
component.id
100100
for inverter in inverters
101101
for component in component_graph.successors(inverter)
102102
)
@@ -149,7 +149,7 @@ def __init__(
149149
self._batteries = connection_manager.get().component_graph.components(
150150
component_categories={ComponentCategory.BATTERY}
151151
)
152-
self._battery_ids = {battery.component_id for battery in self._batteries}
152+
self._battery_ids = {battery.id for battery in self._batteries}
153153

154154
maps = _get_battery_inverter_mappings(self._battery_ids)
155155

src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async def stop(self) -> None:
113113
def _get_ev_charger_ids(self) -> collections.abc.Set[ComponentId]:
114114
"""Return the IDs of all EV chargers present in the component graph."""
115115
return {
116-
evc.component_id
116+
evc.id
117117
for evc in connection_manager.get().component_graph.components(
118118
component_categories={ComponentCategory.EV_CHARGER}
119119
)

src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_pv_inverter_manager/_pv_inverter_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ async def _set_api_power( # pylint: disable=too-many-locals
256256
def _get_pv_inverter_ids(self) -> collections.abc.Set[ComponentId]:
257257
"""Return the IDs of all PV inverters present in the component graph."""
258258
return {
259-
inv.component_id
259+
inv.id
260260
for inv in connection_manager.get().component_graph.components(
261261
component_categories={ComponentCategory.INVERTER}
262262
)

src/frequenz/sdk/microgrid/_power_distributing/_component_status/_battery_status_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def _find_adjacent_inverter_id(self, battery_id: ComponentId) -> ComponentId | N
484484
graph = connection_manager.get().component_graph
485485
return next(
486486
(
487-
comp.component_id
487+
comp.id
488488
for comp in graph.predecessors(battery_id)
489489
if comp.category == ComponentCategory.INVERTER
490490
),

src/frequenz/sdk/microgrid/component_graph.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def refresh_from(
512512

513513
new_graph = nx.DiGraph()
514514
for component in components:
515-
new_graph.add_node(component.component_id, **{_DATA_KEY: component})
515+
new_graph.add_node(component.id, **{_DATA_KEY: component})
516516

517517
# Store the original connection object in the edge data (third item in the
518518
# tuple) so that we can retrieve it later.
@@ -588,15 +588,15 @@ def is_grid_meter(self, component: Component) -> bool:
588588
if component.category != ComponentCategory.METER:
589589
return False
590590

591-
predecessors = self.predecessors(component.component_id)
591+
predecessors = self.predecessors(component.id)
592592
if len(predecessors) != 1:
593593
return False
594594

595595
predecessor = next(iter(predecessors))
596596
if predecessor.category != ComponentCategory.GRID:
597597
return False
598598

599-
grid_successors = self.successors(predecessor.component_id)
599+
grid_successors = self.successors(predecessor.id)
600600
return len(grid_successors) == 1
601601

602602
@override
@@ -627,14 +627,14 @@ def is_pv_meter(self, component: Component) -> bool:
627627
Returns:
628628
Whether the specified component is a PV meter.
629629
"""
630-
successors = self.successors(component.component_id)
630+
successors = self.successors(component.id)
631631
return (
632632
component.category == ComponentCategory.METER
633633
and not self.is_grid_meter(component)
634634
and len(successors) > 0
635635
and all(
636636
self.is_pv_inverter(successor)
637-
for successor in self.successors(component.component_id)
637+
for successor in self.successors(component.id)
638638
)
639639
)
640640

@@ -678,7 +678,7 @@ def is_ev_charger_meter(self, component: Component) -> bool:
678678
Returns:
679679
Whether the specified component is an EV charger meter.
680680
"""
681-
successors = self.successors(component.component_id)
681+
successors = self.successors(component.id)
682682
return (
683683
component.category == ComponentCategory.METER
684684
and not self.is_grid_meter(component)
@@ -729,7 +729,7 @@ def is_battery_meter(self, component: Component) -> bool:
729729
Returns:
730730
Whether the specified component is a battery meter.
731731
"""
732-
successors = self.successors(component.component_id)
732+
successors = self.successors(component.id)
733733
return (
734734
component.category == ComponentCategory.METER
735735
and not self.is_grid_meter(component)
@@ -777,7 +777,7 @@ def is_chp_meter(self, component: Component) -> bool:
777777
Returns:
778778
Whether the specified component is a CHP meter.
779779
"""
780-
successors = self.successors(component.component_id)
780+
successors = self.successors(component.id)
781781
return (
782782
component.category == ComponentCategory.METER
783783
and not self.is_grid_meter(component)
@@ -830,7 +830,7 @@ def dfs(
830830

831831
component: set[Component] = set()
832832

833-
for successor in self.successors(current_node.component_id):
833+
for successor in self.successors(current_node.id):
834834
component.update(self.dfs(successor, visited, condition))
835835

836836
return component
@@ -876,8 +876,8 @@ def find_first_descendant_component(
876876

877877
# Sort by component ID to ensure consistent results.
878878
successors = sorted(
879-
self.successors(root_component.component_id),
880-
key=lambda comp: comp.component_id,
879+
self.successors(root_component.id),
880+
key=lambda comp: comp.id,
881881
)
882882

883883
def find_component(component_category: ComponentCategory) -> Component | None:
@@ -933,9 +933,7 @@ def _validate_graph(self) -> None:
933933

934934
# should be true as a consequence of the tree property:
935935
# there should be no unconnected components
936-
unconnected = filter(
937-
lambda c: self._graph.degree(c.component_id) == 0, self.components()
938-
)
936+
unconnected = filter(lambda c: self._graph.degree(c.id) == 0, self.components())
939937
if sum(1 for _ in unconnected) != 0:
940938
raise InvalidGraphError(
941939
"Every component must have at least one connection!"
@@ -949,7 +947,7 @@ def _validate_graph_root(self) -> None:
949947
or if there is a single such node that is not one of NONE or GRID.
950948
"""
951949
no_predecessors = filter(
952-
lambda c: self._graph.in_degree(c.component_id) == 0,
950+
lambda c: self._graph.in_degree(c.id) == 0,
953951
self.components(),
954952
)
955953

@@ -969,7 +967,7 @@ def _validate_graph_root(self) -> None:
969967
raise InvalidGraphError(f"Multiple potential root nodes: {valid_roots}")
970968

971969
root = valid_roots[0]
972-
if self._graph.out_degree(root.component_id) == 0:
970+
if self._graph.out_degree(root.id) == 0:
973971
raise InvalidGraphError(f"Graph root {root} has no successors!")
974972

975973
def _validate_grid_endpoint(self) -> None:
@@ -994,7 +992,7 @@ def _validate_grid_endpoint(self) -> None:
994992
f"Multiple grid endpoints in component graph: {grid}"
995993
)
996994

997-
grid_id = grid[0].component_id
995+
grid_id = grid[0].id
998996
if self._graph.in_degree(grid_id) > 0:
999997
grid_predecessors = list(self.predecessors(grid_id))
1000998
raise InvalidGraphError(
@@ -1022,7 +1020,7 @@ def _validate_intermediary_components(self) -> None:
10221020

10231021
missing_predecessors = list(
10241022
filter(
1025-
lambda c: sum(1 for _ in self.predecessors(c.component_id)) == 0,
1023+
lambda c: sum(1 for _ in self.predecessors(c.id)) == 0,
10261024
intermediary_components,
10271025
)
10281026
)
@@ -1054,7 +1052,7 @@ def _validate_leaf_components(self) -> None:
10541052

10551053
missing_predecessors = list(
10561054
filter(
1057-
lambda c: sum(1 for _ in self.predecessors(c.component_id)) == 0,
1055+
lambda c: sum(1 for _ in self.predecessors(c.id)) == 0,
10581056
leaf_components,
10591057
)
10601058
)
@@ -1065,7 +1063,7 @@ def _validate_leaf_components(self) -> None:
10651063

10661064
with_successors = list(
10671065
filter(
1068-
lambda c: sum(1 for _ in self.successors(c.component_id)) > 0,
1066+
lambda c: sum(1 for _ in self.successors(c.id)) > 0,
10691067
leaf_components,
10701068
)
10711069
)

src/frequenz/sdk/timeseries/_grid_frequency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
self._channel_registry: ChannelRegistry = channel_registry
6969
self._source_component: Component = source
7070
self._component_metric_request: ComponentMetricRequest = create_request(
71-
self._source_component.component_id
71+
self._source_component.id
7272
)
7373

7474
self._task: None | asyncio.Task[None] = None

src/frequenz/sdk/timeseries/_voltage_streamer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async def _send_request(self) -> None:
146146
phases_rx: list[Receiver[Sample[Quantity]]] = []
147147
for metric in metrics:
148148
req = ComponentMetricRequest(
149-
self._namespace, self._source_component.component_id, metric, None
149+
self._namespace, self._source_component.id, metric, None
150150
)
151151

152152
await self._resampler_subscription_sender.send(req)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,10 @@ def _get_all_batteries(self) -> frozenset[ComponentId]:
142142
"""
143143
graph = connection_manager.get().component_graph
144144
return frozenset(
145-
{
146-
battery.component_id
147-
for battery in graph.components(
148-
component_categories={ComponentCategory.BATTERY}
149-
)
150-
}
145+
battery.id
146+
for battery in graph.components(
147+
component_categories={ComponentCategory.BATTERY}
148+
)
151149
)
152150

153151
async def _update_battery_status(

0 commit comments

Comments
 (0)