Skip to content

Commit a602746

Browse files
committed
Fix uses of Connection as if they were tuples
The `Connection` type in the external microgrid API is a dataclass instead of a tuple, so we need to convert it when a tuple is expected. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7847a88 commit a602746

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/frequenz/sdk/microgrid/component_graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"""
2323

2424
import asyncio
25+
import dataclasses
2526
import logging
2627
from abc import ABC, abstractmethod
2728
from collections.abc import Callable, Iterable
@@ -513,7 +514,7 @@ def refresh_from(
513514
for component in components:
514515
new_graph.add_node(component.component_id, **asdict(component))
515516

516-
new_graph.add_edges_from(connections)
517+
new_graph.add_edges_from(dataclasses.astuple(c) for c in connections)
517518

518519
# check if we can construct a valid ComponentGraph
519520
# from the new NetworkX graph data

tests/microgrid/test_graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def test_graph_correction(self) -> None:
14311431
}
14321432
assert len(graph.components()) == len(expected)
14331433
assert set(graph.components()) == expected
1434-
assert list(graph.connections()) == [(1, 2)]
1434+
assert list(graph.connections()) == [Connection(1, 2)]
14351435

14361436
# invalid graph data that (for now at least)
14371437
# cannot be corrected
@@ -1445,7 +1445,7 @@ def test_graph_correction(self) -> None:
14451445
# graph is still in last known good state
14461446
assert len(graph.components()) == len(expected)
14471447
assert set(graph.components()) == expected
1448-
assert list(graph.connections()) == [(1, 2)]
1448+
assert list(graph.connections()) == [Connection(1, 2)]
14491449

14501450
# invalid graph data where there is no grid
14511451
# endpoint but a node has the magic value 0
@@ -1462,7 +1462,7 @@ def test_graph_correction(self) -> None:
14621462
# graph is still in last known good state
14631463
assert len(graph.components()) == len(expected)
14641464
assert set(graph.components()) == expected
1465-
assert list(graph.connections()) == [(1, 2)]
1465+
assert list(graph.connections()) == [Connection(1, 2)]
14661466

14671467
# with the callback, this can be corrected
14681468
graph.refresh_from(
@@ -1477,4 +1477,4 @@ def test_graph_correction(self) -> None:
14771477
assert len(graph.components()) == len(expected)
14781478
assert set(graph.components()) == expected
14791479

1480-
assert list(graph.connections()) == [(0, 8)]
1480+
assert list(graph.connections()) == [Connection(0, 8)]

0 commit comments

Comments
 (0)