Skip to content

Commit 0efb86a

Browse files
committed
Allow MockMicrogrid battery chains without meters
In most component graph configs, batteries would be attached to inverters and the inverters would be meters. But there might be some cases where there are no meters, and we'll have to read data from the inverters. This commit enables such test configs, that can be used in tests that use the MockMicrogrid. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 6d4f2ad commit 0efb86a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/timeseries/mock_microgrid.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,23 @@ def add_chps(self, count: int) -> None:
251251
self._connections.add(Connection(self._connect_to, meter_id))
252252
self._connections.add(Connection(meter_id, chp_id))
253253

254-
def add_batteries(self, count: int) -> None:
254+
def add_batteries(self, count: int, no_meter: bool = False) -> None:
255255
"""Add batteries with connected inverters and meters to the microgrid.
256256
257257
Args:
258258
count: number of battery sets to add.
259+
no_meter: if True, do not add a meter for each battery set.
259260
"""
260261
for _ in range(count):
261262
meter_id = self._id_increment * 10 + self.meter_id_suffix
262263
inv_id = self._id_increment * 10 + self.inverter_id_suffix
263264
bat_id = self._id_increment * 10 + self.battery_id_suffix
264265
self._id_increment += 1
265266

266-
self.meter_ids.append(meter_id)
267267
self.battery_inverter_ids.append(inv_id)
268268
self.battery_ids.append(bat_id)
269269
self.bat_inv_map[bat_id] = inv_id
270270

271-
self._components.add(
272-
Component(
273-
meter_id,
274-
ComponentCategory.METER,
275-
)
276-
)
277271
self._components.add(
278272
Component(inv_id, ComponentCategory.INVERTER, InverterType.BATTERY)
279273
)
@@ -285,9 +279,20 @@ def add_batteries(self, count: int) -> None:
285279
)
286280
self._start_battery_streaming(bat_id)
287281
self._start_inverter_streaming(inv_id)
288-
self._start_meter_streaming(meter_id)
289-
self._connections.add(Connection(self._connect_to, meter_id))
290-
self._connections.add(Connection(meter_id, inv_id))
282+
283+
if no_meter:
284+
self._connections.add(Connection(self._connect_to, inv_id))
285+
else:
286+
self.meter_ids.append(meter_id)
287+
self._components.add(
288+
Component(
289+
meter_id,
290+
ComponentCategory.METER,
291+
)
292+
)
293+
self._start_meter_streaming(meter_id)
294+
self._connections.add(Connection(self._connect_to, meter_id))
295+
self._connections.add(Connection(meter_id, inv_id))
291296
self._connections.add(Connection(inv_id, bat_id))
292297

293298
def add_solar_inverters(self, count: int) -> None:

0 commit comments

Comments
 (0)