Skip to content

Commit 338dee5

Browse files
Move Fuse to timeseries module (#781)
The Grid class is the only class that uses `Fuse` as it is used to represent the fuse of a grid. It is not a microgrid-specific class. Therefore, it is moved to the timeseries module. Fixes #771
2 parents 5af26d8 + 14f80df commit 338dee5

File tree

13 files changed

+54
-36
lines changed

13 files changed

+54
-36
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
+ `Result.failed_components`
1919

2020

21+
- The `Fuse` class has been moved to the `frequenz.sdk.timeseries` module.
22+
2123
## New Features
2224

2325
<!-- Here goes the main new features and examples or instructions on how to use them -->

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ max-attributes = 12
166166
testpaths = ["tests", "src"]
167167
asyncio_mode = "auto"
168168
required_plugins = ["pytest-asyncio", "pytest-mock"]
169+
markers = [
170+
"integration: integration tests (deselect with '-m \"not integration\"')",
171+
]
169172

170173
[tool.mypy]
171174
explicit_package_bases = true

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124

125125
from ..actor import ResamplerConfig
126126
from ..timeseries.grid import initialize as initialize_grid
127-
from . import _data_pipeline, client, component, connection_manager, fuse, metadata
127+
from . import _data_pipeline, client, component, connection_manager, metadata
128128
from ._data_pipeline import (
129129
battery_pool,
130130
ev_charger_pool,
@@ -157,7 +157,6 @@ async def initialize(host: str, port: int, resampler_config: ResamplerConfig) ->
157157
"component",
158158
"battery_pool",
159159
"ev_charger_pool",
160-
"fuse",
161160
"grid",
162161
"frequency",
163162
"logical_meter",

src/frequenz/sdk/microgrid/component/_component.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
33

44
"""Defines the components that can be used in a microgrid."""
5+
from __future__ import annotations
56

67
from dataclasses import dataclass
78
from enum import Enum
9+
from typing import TYPE_CHECKING
810

911
import frequenz.api.common.components_pb2 as components_pb
1012
import frequenz.api.microgrid.grid_pb2 as grid_pb
1113
import frequenz.api.microgrid.inverter_pb2 as inverter_pb
1214

13-
from ...timeseries import Current
14-
from ..fuse import Fuse
15+
if TYPE_CHECKING:
16+
# Break circular import
17+
from ...timeseries import Fuse
1518

1619

1720
class ComponentType(Enum):
@@ -140,6 +143,8 @@ def _component_metadata_from_protobuf(
140143
component_category: components_pb.ComponentCategory.ValueType,
141144
component_metadata: grid_pb.Metadata,
142145
) -> GridMetadata | None:
146+
from ...timeseries import Current, Fuse # pylint: disable=import-outside-toplevel
147+
143148
if component_category == components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID:
144149
max_current = Current.from_amperes(component_metadata.rated_fuse_current)
145150
fuse = Fuse(max_current)

src/frequenz/sdk/timeseries/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from .._internal._channels import ReceiverFetcher
3939
from ._base_types import UNIX_EPOCH, Bounds, Sample, Sample3Phase
40+
from ._fuse import Fuse
4041
from ._moving_window import MovingWindow
4142
from ._periodic_feature_extractor import PeriodicFeatureExtractor
4243
from ._quantities import (
@@ -53,6 +54,7 @@
5354

5455
__all__ = [
5556
"Bounds",
57+
"Fuse",
5658
"MovingWindow",
5759
"PeriodicFeatureExtractor",
5860
"ResamplerConfig",
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

44
"""Fuse data class."""
5+
from __future__ import annotations
56

67
from dataclasses import dataclass
8+
from typing import TYPE_CHECKING
79

8-
from ..timeseries import Current
10+
if TYPE_CHECKING:
11+
# Break circular import
12+
from . import Current
913

1014

1115
@dataclass(frozen=True)

src/frequenz/sdk/timeseries/formula_engine/_formula_engine_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ._resampled_formula_builder import ResampledFormulaBuilder
2020

2121
if TYPE_CHECKING:
22-
# Break circular import by enclosing these type hints in a `TYPE_CHECKING` block.
22+
# Break circular import
2323
from ..formula_engine import FormulaEngine, FormulaEngine3Phase
2424

2525

src/frequenz/sdk/timeseries/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from ..microgrid.component import Component
1515
from ..microgrid.component._component import ComponentCategory
16-
from ..microgrid.fuse import Fuse
16+
from . import Fuse
1717

1818
_logger = logging.getLogger(__name__)
1919

tests/microgrid/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
InverterType,
2727
MeterData,
2828
)
29-
from frequenz.sdk.microgrid.fuse import Fuse
30-
from frequenz.sdk.timeseries import Current
29+
from frequenz.sdk.timeseries import Current, Fuse
3130

3231
from . import mock_api
3332

tests/microgrid/test_graph.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
GridMetadata,
2222
InverterType,
2323
)
24-
from frequenz.sdk.microgrid.fuse import Fuse
25-
from frequenz.sdk.timeseries import Current
24+
from frequenz.sdk.timeseries import Current, Fuse
2625

2726
from .mock_api import MockGrpcServer, MockMicrogridServicer
2827

0 commit comments

Comments
 (0)