Skip to content

Commit 94ed083

Browse files
Allow setting grid metadata in mocks
This commit allows tests to specify the `rated_fuse_current` member in the metadata objects of grid connection points. The test data supplied using this mechanism can be used in downstream validations. Signed-off-by: Tiyash Basu <[email protected]>
1 parent 2e71987 commit 94ed083

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tests/microgrid/mock_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from frequenz.api.microgrid.battery_pb2 import Battery
3131
from frequenz.api.microgrid.battery_pb2 import Data as BatteryData
3232
from frequenz.api.microgrid.ev_charger_pb2 import EvCharger
33+
from frequenz.api.microgrid.grid_pb2 import Metadata as GridMetadata
3334
from frequenz.api.microgrid.inverter_pb2 import Inverter
3435
from frequenz.api.microgrid.inverter_pb2 import Metadata as InverterMetadata
3536
from frequenz.api.microgrid.meter_pb2 import Data as MeterData
@@ -57,6 +58,8 @@
5758
from google.protobuf.timestamp_pb2 import Timestamp
5859
from google.protobuf.wrappers_pb2 import BoolValue
5960

61+
from frequenz.sdk.timeseries import Current
62+
6063

6164
class MockMicrogridServicer( # pylint: disable=too-many-public-methods
6265
MicrogridServicer
@@ -89,6 +92,7 @@ def add_component(
8992
self,
9093
component_id: int,
9194
component_category: ComponentCategory.V,
95+
max_current: Optional[Current] = None,
9296
inverter_type: InverterType.V = InverterType.INVERTER_TYPE_UNSPECIFIED,
9397
) -> None:
9498
"""Add a component to the mock service."""
@@ -100,6 +104,17 @@ def add_component(
100104
inverter=InverterMetadata(type=inverter_type),
101105
)
102106
)
107+
elif (
108+
component_category == ComponentCategory.COMPONENT_CATEGORY_GRID
109+
and max_current is not None
110+
):
111+
self._components.append(
112+
Component(
113+
id=component_id,
114+
category=component_category,
115+
grid=GridMetadata(rated_fuse_current=int(max_current.as_amperes())),
116+
)
117+
)
103118
else:
104119
self._components.append(
105120
Component(id=component_id, category=component_category)

tests/microgrid/test_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
InverterType,
2727
MeterData,
2828
)
29+
from frequenz.sdk.timeseries import Current
2930

3031
from . import mock_api
3132

@@ -107,7 +108,6 @@ async def test_components(self) -> None:
107108
100,
108109
components_pb.ComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED,
109110
),
110-
(101, components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID),
111111
(104, components_pb.ComponentCategory.COMPONENT_CATEGORY_METER),
112112
(105, components_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER),
113113
(106, components_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY),
@@ -119,13 +119,19 @@ async def test_components(self) -> None:
119119
]
120120
)
121121

122+
servicer.add_component(
123+
101,
124+
components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID,
125+
Current.from_amperes(123.0),
126+
)
127+
122128
assert set(await microgrid.components()) == {
123129
Component(100, ComponentCategory.NONE),
124130
Component(
125131
101,
126132
ComponentCategory.GRID,
127133
None,
128-
GridMetadata(max_current=0.0),
134+
GridMetadata(max_current=123.0),
129135
),
130136
Component(104, ComponentCategory.METER),
131137
Component(105, ComponentCategory.INVERTER, InverterType.NONE),
@@ -143,6 +149,7 @@ async def test_components(self) -> None:
143149
servicer.add_component(
144150
99,
145151
components_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER,
152+
None,
146153
components_pb.InverterType.INVERTER_TYPE_BATTERY,
147154
)
148155

0 commit comments

Comments
 (0)