Skip to content

Commit 214d0e4

Browse files
committed
Use deprecate-aware enum from frequenz-core
With this we can enable `@unique` again, as we can explicitly mark members as deprecated and deprecated members are not checked for duplicates. We also replace the internal uses of the deprecated names with the new names. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 087c7fe commit 214d0e4

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies = [
4141
"frequenz-channels >= 1.6.1, < 2.0.0",
4242
"frequenz-client-base >= 0.10.0, < 0.12.0",
4343
"frequenz-client-common >= 0.3.6, < 0.4.0",
44+
"frequenz-core >= 1.3.0, < 2.0.0",
4445
"grpcio >= 1.72.1, < 2",
4546
"protobuf >= 6.31.1, < 7",
4647
"typing-extensions >= 4.13.0, < 5",

src/frequenz/client/microgrid/component/_category.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
"""The component categories that can be used in a microgrid."""
55

6-
import enum
7-
86
from frequenz.api.common.v1alpha8.microgrid.electrical_components import (
97
electrical_components_pb2,
108
)
9+
from frequenz.core import enum
1110

1211

13-
# @enum.unique
12+
@enum.unique
1413
class ComponentCategory(enum.Enum):
1514
"""The known categories of components that can be present in a microgrid."""
1615

@@ -22,7 +21,10 @@ class ComponentCategory(enum.Enum):
2221
)
2322
"""The point where the local microgrid is connected to the grid."""
2423

25-
GRID = electrical_components_pb2.ELECTRICAL_COMPONENT_CATEGORY_GRID_CONNECTION_POINT
24+
GRID = enum.deprecated_member(
25+
electrical_components_pb2.ELECTRICAL_COMPONENT_CATEGORY_GRID_CONNECTION_POINT,
26+
"GRID is deprecated, use GRID_CONNECTION_POINT instead",
27+
)
2628
"""The point where the local microgrid is connected to the grid (deprecated).
2729
2830
Deprecated: Deprecated in v0.18.0
@@ -88,8 +90,9 @@ class ComponentCategory(enum.Enum):
8890
proportionally reduced, and vice versa.
8991
"""
9092

91-
VOLTAGE_TRANSFORMER = (
92-
electrical_components_pb2.ELECTRICAL_COMPONENT_CATEGORY_POWER_TRANSFORMER
93+
VOLTAGE_TRANSFORMER = enum.deprecated_member(
94+
electrical_components_pb2.ELECTRICAL_COMPONENT_CATEGORY_POWER_TRANSFORMER,
95+
"VOLTAGE_TRANSFORMER is deprecated, use POWER_TRANSFORMER instead",
9396
)
9497
"""A voltage transformer (deprecated).
9598

src/frequenz/client/microgrid/component/_grid_connection_point.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class GridConnectionPoint(Component):
3434
Note that this may also be the PCC in some cases.
3535
"""
3636

37-
category: Literal[ComponentCategory.GRID] = ComponentCategory.GRID
37+
category: Literal[ComponentCategory.GRID_CONNECTION_POINT] = (
38+
ComponentCategory.GRID_CONNECTION_POINT
39+
)
3840
"""The category of this component."""
3941

4042
rated_fuse_current: int

src/frequenz/client/microgrid/component/_state_sample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
"""Definition of component states."""
55

6-
import enum
76
from dataclasses import dataclass
87
from datetime import datetime
98

109
from frequenz.api.common.v1alpha8.microgrid.electrical_components import (
1110
electrical_components_pb2,
1211
)
12+
from frequenz.core import enum
1313

1414

1515
@enum.unique
@@ -106,7 +106,7 @@ class ComponentStateCode(enum.Enum):
106106
"""The precharger circuit is closed, allowing full current to flow to the main circuit."""
107107

108108

109-
# @enum.unique
109+
@enum.unique
110110
class ComponentErrorCode(enum.Enum):
111111
"""The various errors that a component can report."""
112112

@@ -182,8 +182,9 @@ class ComponentErrorCode(enum.Enum):
182182
)
183183
"""Plausibility issues within the system involving this component."""
184184

185-
UNDERVOLTAGE_SHUTDOWN = (
186-
electrical_components_pb2.ELECTRICAL_COMPONENT_DIAGNOSTIC_CODE_UNDERVOLTAGE
185+
UNDERVOLTAGE_SHUTDOWN = enum.deprecated_member(
186+
electrical_components_pb2.ELECTRICAL_COMPONENT_DIAGNOSTIC_CODE_UNDERVOLTAGE,
187+
"UNDERVOLTAGE_SHUTDOWN is deprecated, use UNDERVOLTAGE instead",
187188
)
188189
"""System shutdown due to undervoltage involving this component.
189190

src/frequenz/client/microgrid/component/_voltage_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class VoltageTransformer(Component):
2424
than the input power.
2525
"""
2626

27-
category: Literal[ComponentCategory.VOLTAGE_TRANSFORMER] = (
28-
ComponentCategory.VOLTAGE_TRANSFORMER
27+
category: Literal[ComponentCategory.POWER_TRANSFORMER] = (
28+
ComponentCategory.POWER_TRANSFORMER
2929
)
3030
"""The category of this component."""
3131

tests/component/test_grid_connection_point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_creation_ok(
4141
assert grid_point.name == "test_grid_point"
4242
assert grid_point.manufacturer == "test_manufacturer"
4343
assert grid_point.model_name == "test_model"
44-
assert grid_point.category == ComponentCategory.GRID
44+
assert grid_point.category == ComponentCategory.GRID_CONNECTION_POINT
4545
assert grid_point.rated_fuse_current == rated_fuse_current
4646

4747

tests/component/test_voltage_transformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ def test_creation_ok(
4747
assert voltage_transformer.name == "test_voltage_transformer"
4848
assert voltage_transformer.manufacturer == "test_manufacturer"
4949
assert voltage_transformer.model_name == "test_model"
50-
assert voltage_transformer.category == ComponentCategory.VOLTAGE_TRANSFORMER
50+
assert voltage_transformer.category == ComponentCategory.POWER_TRANSFORMER
5151
assert voltage_transformer.primary_voltage == pytest.approx(primary)
5252
assert voltage_transformer.secondary_voltage == pytest.approx(secondary)

0 commit comments

Comments
 (0)