Skip to content

Commit 30bd915

Browse files
committed
Add pass-through tests for Relay and Hvac
Build a Grid -> ... -> SolarInverter graph with each pass-through category placed inline and assert that cg's pass-through behavior is observable from the Python API: * predecessors/successors walk past the pass-through node * pv_ac_coalesce_formula doesn't reference the pass-through Hvac is used rather than VoltageTransformer because the latter maps to cg::PowerTransformer, which may stop being pass-through once the Frequenz client gains transformer-specific handling. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent bdfe7e0 commit 30bd915

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

tests/test_microgrid_component_graph.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
Component,
1010
ComponentConnection,
1111
GridConnectionPoint,
12+
Hvac,
1213
Meter,
14+
Relay,
1315
SolarInverter,
1416
WindTurbine,
1517
)
@@ -124,3 +126,94 @@ def test_wind_turbine_graph() -> None:
124126
assert graph.predecessors(ComponentId(3)) == {
125127
Meter(id=ComponentId(2), microgrid_id=MicrogridId(1))
126128
}
129+
130+
131+
def test_relay_is_passthrough() -> None:
132+
"""`Relay` maps to cg's `Breaker`, a pass-through category.
133+
134+
A Relay placed between a Meter and a SolarInverter should be
135+
transparent: cg walks past it when answering `predecessors`/
136+
`successors`, and the PV formula references only the Meter and
137+
the inverter.
138+
"""
139+
graph: microgrid_component_graph.ComponentGraph[
140+
Component, ComponentConnection, ComponentId
141+
] = microgrid_component_graph.ComponentGraph(
142+
components={
143+
GridConnectionPoint(
144+
id=ComponentId(1),
145+
microgrid_id=MicrogridId(1),
146+
rated_fuse_current=100,
147+
),
148+
Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)),
149+
Relay(id=ComponentId(3), microgrid_id=MicrogridId(1)),
150+
SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)),
151+
},
152+
connections={
153+
# Grid -> Meter -> Relay -> SolarInverter
154+
ComponentConnection(source=ComponentId(1), destination=ComponentId(2)),
155+
ComponentConnection(source=ComponentId(2), destination=ComponentId(3)),
156+
ComponentConnection(source=ComponentId(3), destination=ComponentId(4)),
157+
},
158+
)
159+
160+
# Neighbor queries walk past the Relay.
161+
assert graph.predecessors(ComponentId(4)) == {
162+
Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)),
163+
}
164+
assert graph.successors(ComponentId(2)) == {
165+
SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)),
166+
}
167+
# And the formula references the Meter and the inverter only --
168+
# the Relay (#3) does not appear.
169+
assert (
170+
graph.pv_ac_coalesce_formula(pv_inverter_ids={ComponentId(4)})
171+
== "COALESCE(#2, #4)"
172+
)
173+
174+
175+
def test_hvac_is_passthrough() -> None:
176+
"""`Hvac` maps to cg's `Hvac`, a pass-through category.
177+
178+
An Hvac placed between the Grid and a Meter should be
179+
transparent: `successors(Grid)` walks past it to the Meter,
180+
and the PV formula references only the Meter and the inverter.
181+
"""
182+
graph: microgrid_component_graph.ComponentGraph[
183+
Component, ComponentConnection, ComponentId
184+
] = microgrid_component_graph.ComponentGraph(
185+
components={
186+
GridConnectionPoint(
187+
id=ComponentId(1),
188+
microgrid_id=MicrogridId(1),
189+
rated_fuse_current=100,
190+
),
191+
Hvac(id=ComponentId(2), microgrid_id=MicrogridId(1)),
192+
Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)),
193+
SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)),
194+
},
195+
connections={
196+
# Grid -> Hvac -> Meter -> SolarInverter
197+
ComponentConnection(source=ComponentId(1), destination=ComponentId(2)),
198+
ComponentConnection(source=ComponentId(2), destination=ComponentId(3)),
199+
ComponentConnection(source=ComponentId(3), destination=ComponentId(4)),
200+
},
201+
)
202+
203+
# Neighbor queries walk past the Hvac.
204+
assert graph.successors(ComponentId(1)) == {
205+
Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)),
206+
}
207+
assert graph.predecessors(ComponentId(3)) == {
208+
GridConnectionPoint(
209+
id=ComponentId(1),
210+
microgrid_id=MicrogridId(1),
211+
rated_fuse_current=100,
212+
),
213+
}
214+
# And the formula references the Meter and the inverter only --
215+
# the Hvac (#2) does not appear.
216+
assert (
217+
graph.pv_ac_coalesce_formula(pv_inverter_ids={ComponentId(4)})
218+
== "COALESCE(#3, #4)"
219+
)

0 commit comments

Comments
 (0)