Skip to content

Commit 7feb797

Browse files
Add a Fuse class and use it in Grid
This commit introduces a class to represent fuses. Fuses have just one property representing their rated max current. If the current flowing through a fuse is greater than this limit, then the fuse will break the circuit. This commit also introduces using a Fuse object to represent the allowed max current at a grid connection point. Signed-off-by: Tiyash Basu <[email protected]>
1 parent 3517f3a commit 7feb797

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ This release replaces the `@actor` decorator with a new `Actor` class.
9292

9393
- `Actor`: This new class inherits from `BackgroundService` and it replaces the `@actor` decorator.
9494

95-
- Calling `microgrid.initialize()` now also initializes the microgrid's grid connection point as a singleton object of a newly added type `Grid`. This object can be obtained by calling `microgrid.grid.get()`. This object exposes the max current that can course through the grid connection point, which is useful for the power distribution algorithm. The max current is provided by the Microgrid API, and can be obtained by calling `microgrid.grid.get().max_current`.
95+
- Calling `microgrid.initialize()` now also initializes the microgrid's grid connection point as a singleton object of a newly added type `Grid`. This object can be obtained by calling `microgrid.grid.get()`. This object exposes the max current that can course through the grid connection point, which is useful for the power distribution algorithm. The max current is provided by the Microgrid API, and can be obtained by calling `microgrid.grid.get().fuse.max_current`.
9696
Note that a microgrid is allowed to have zero or one grid connection point. Microgrids configured as islands will have zero grid connection points, and microgrids configured as grid-connected will have one grid connection point.
9797

98+
- A new class `Fuse` has been added to represent fuses. This class has a member variable `max_current` which represents the maximum current that can course through the fuse. If the current flowing through a fuse is greater than this limit, then the fuse will break the circuit.
99+
100+
98101
## Bug Fixes
99102

100103
- Fixes a bug in the ring buffer updating the end timestamp of gaps when they are outdated.

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
from ..actor import ResamplerConfig
11-
from . import _data_pipeline, client, component, connection_manager, grid
11+
from . import _data_pipeline, client, component, connection_manager, fuse, grid
1212
from ._data_pipeline import battery_pool, ev_charger_pool, logical_meter
1313
from ._graph import ComponentGraph
1414

@@ -37,6 +37,7 @@ async def initialize(host: str, port: int, resampler_config: ResamplerConfig) ->
3737
"component",
3838
"battery_pool",
3939
"ev_charger_pool",
40+
"fuse",
4041
"grid",
4142
"logical_meter",
4243
]

src/frequenz/sdk/microgrid/fuse.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# License: MIT
2+
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Fuse data class."""
5+
6+
from dataclasses import dataclass
7+
8+
from ..timeseries import Current
9+
10+
11+
@dataclass(frozen=True)
12+
class Fuse:
13+
"""Fuse data class."""
14+
15+
max_current: Current
16+
"""Rated current of the fuse."""

src/frequenz/sdk/microgrid/grid.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@
1111
from dataclasses import dataclass
1212
from typing import Iterable, Optional
1313

14+
from ..timeseries import Current
1415
from .component import Component
1516
from .component._component import ComponentCategory
17+
from .fuse import Fuse
1618

1719

1820
@dataclass(frozen=True)
1921
class Grid:
20-
"""A grid connection point.
22+
"""A grid connection point."""
2123

22-
Attributes:
23-
max_current: The maximum current that can course through the grid
24-
connection point, in Amperes.
25-
"""
26-
27-
max_current: float
24+
fuse: Fuse
25+
"""The fuse protecting the grid connection point."""
2826

2927

3028
_GRID: Optional[Grid] = None
@@ -60,7 +58,8 @@ def initialize(components: Iterable[Component]) -> None:
6058
)
6159
else:
6260
max_current = grid_connections[0].metadata.max_current # type: ignore
63-
_GRID = Grid(max_current)
61+
fuse = Fuse(Current.from_amperes(max_current))
62+
_GRID = Grid(fuse)
6463

6564

6665
def get() -> Optional[Grid]:

tests/microgrid/test_grid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
from frequenz.sdk import microgrid
99
from frequenz.sdk.microgrid.component import Component, ComponentCategory, GridMetadata
10+
from frequenz.sdk.microgrid.fuse import Fuse
1011
from frequenz.sdk.microgrid.grid import Grid
12+
from frequenz.sdk.timeseries import Current
1113

1214

1315
async def test_grid() -> None:
@@ -53,7 +55,11 @@ async def test_grid() -> None:
5355
microgrid.grid.initialize(components)
5456

5557
grid = microgrid.grid.get()
56-
assert grid == Grid(max_current=123.0)
5758

58-
max_current = grid.max_current
59-
assert max_current == 123.0
59+
expected_fuse_current = Current.from_amperes(123.0)
60+
expected_fuse = Fuse(expected_fuse_current)
61+
62+
assert grid == Grid(fuse=expected_fuse)
63+
64+
fuse_current = grid.fuse.max_current
65+
assert fuse_current == expected_fuse_current

0 commit comments

Comments
 (0)