Skip to content

Commit fefafc5

Browse files
committed
Don't pass blindly what comes from the API to Fuse
Since now we have an internal `Fuse` type that uses quantities to avoid bugs, we need to make sure to properly convert between the client's `Fuse` type and the internal one. There is also actually a bug in the old code, as the conversion to `Current` never happened. This was never caught by `mypy` because we were using the `**args` syntax to create the object, so there is no type checking of the arguments, so a bad `Fuse` was being created, with a `float` `max_current` instead of using `Current`. We now make sure the conversion is done appropriately. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 991ae71 commit fefafc5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/frequenz/sdk/timeseries/grid.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ def initialize(
195195
# instead of the expected ComponentMetadata type.
196196
metadata = grid_connections[0].metadata
197197
if isinstance(metadata, dict):
198-
fuse_dict = metadata.get("fuse", None)
199-
fuse = Fuse(**fuse_dict) if fuse_dict else None
198+
if fuse_dict := metadata.get("fuse", None):
199+
fuse = Fuse(
200+
max_current=Current.from_amperes(fuse_dict.get("max_current", 0.0))
201+
)
200202

201203
if fuse is None:
202204
_logger.warning("The grid connection point does not have a fuse")

0 commit comments

Comments
 (0)