Skip to content

Commit 4160b80

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 5b8fd4c commit 4160b80

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

tests/microgrid/mock_api.py

Lines changed: 13 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
@@ -89,6 +90,7 @@ def add_component(
8990
self,
9091
component_id: int,
9192
component_category: ComponentCategory.V,
93+
max_current: Optional[int] = None,
9294
inverter_type: InverterType.V = InverterType.INVERTER_TYPE_UNSPECIFIED,
9395
) -> None:
9496
"""Add a component to the mock service."""
@@ -100,6 +102,17 @@ def add_component(
100102
inverter=InverterMetadata(type=inverter_type),
101103
)
102104
)
105+
elif (
106+
component_category == ComponentCategory.COMPONENT_CATEGORY_GRID
107+
and max_current is not None
108+
):
109+
self._components.append(
110+
Component(
111+
id=component_id,
112+
category=component_category,
113+
grid=GridMetadata(rated_fuse_current=max_current),
114+
)
115+
)
103116
else:
104117
self._components.append(
105118
Component(id=component_id, category=component_category)

tests/microgrid/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ async def test_components(self) -> None:
107107
100,
108108
components_pb.ComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED,
109109
),
110-
(101, components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID),
111110
(104, components_pb.ComponentCategory.COMPONENT_CATEGORY_METER),
112111
(105, components_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER),
113112
(106, components_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY),
@@ -119,10 +118,14 @@ async def test_components(self) -> None:
119118
]
120119
)
121120

121+
servicer.add_component(
122+
101, components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID, 123
123+
)
124+
122125
assert set(await microgrid.components()) == {
123126
Component(100, ComponentCategory.NONE),
124127
Component(
125-
101, ComponentCategory.GRID, None, GridMetadata(max_current=0.0)
128+
101, ComponentCategory.GRID, None, GridMetadata(max_current=123.0)
126129
),
127130
Component(104, ComponentCategory.METER),
128131
Component(105, ComponentCategory.INVERTER, InverterType.NONE),
@@ -140,6 +143,7 @@ async def test_components(self) -> None:
140143
servicer.add_component(
141144
99,
142145
components_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER,
146+
None,
143147
components_pb.InverterType.INVERTER_TYPE_BATTERY,
144148
)
145149

0 commit comments

Comments
 (0)