Skip to content

Commit 693116d

Browse files
committed
Use match for better readability
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 6336816 commit 693116d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/frequenz/sdk/timeseries/grid.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,29 @@ def initialize(
194194

195195
fuse: Fuse | None = None
196196

197-
if grid_connections_count == 0:
198-
fuse = Fuse(max_current=Current.zero())
199-
_logger.info(
200-
"No grid connection found for this microgrid. This is normal for an islanded microgrid."
201-
)
202-
elif grid_connections_count > 1:
203-
raise RuntimeError(
204-
f"Expected at most one grid connection, got {grid_connections_count}"
205-
)
206-
else:
207-
if grid_connections[0].metadata is None:
208-
raise RuntimeError("Grid metadata is None")
209-
210-
if grid_connections[0].metadata.fuse is not None:
211-
fuse = Fuse(
212-
max_current=Current.from_amperes(
213-
grid_connections[0].metadata.fuse.max_current
214-
)
197+
match grid_connections_count:
198+
case 0:
199+
fuse = Fuse(max_current=Current.zero())
200+
_logger.info(
201+
"No grid connection found for this microgrid. This is normal for an islanded microgrid."
215202
)
203+
case 1:
204+
if grid_connections[0].metadata is None:
205+
raise RuntimeError("Grid metadata is None")
206+
207+
if grid_connections[0].metadata.fuse is not None:
208+
fuse = Fuse(
209+
max_current=Current.from_amperes(
210+
grid_connections[0].metadata.fuse.max_current
211+
)
212+
)
216213

217-
if fuse is None:
218-
_logger.warning("The grid connection point does not have a fuse")
214+
if fuse is None:
215+
_logger.warning("The grid connection point does not have a fuse")
216+
case _:
217+
raise RuntimeError(
218+
f"Expected at most one grid connection, got {grid_connections_count}"
219+
)
219220

220221
namespace = f"grid-{uuid.uuid4()}"
221222
formula_pool = FormulaEnginePool(

0 commit comments

Comments
 (0)