Skip to content

Commit 133c735

Browse files
committed
Update mock_microgrid to close channels when done sending.
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 5615061 commit 133c735

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests/timeseries/mock_microgrid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ async def _comp_data_send_task(
148148
await self._microgrid.send(make_comp_data(val_to_send, timestamp))
149149
await asyncio.sleep(self._sample_rate_s)
150150

151+
await self._microgrid.close_channel(comp_id)
152+
151153
def _start_meter_streaming(self, meter_id: int) -> None:
152154
self._streaming_coros.append(
153155
self._comp_data_send_task(

tests/utils/mock_microgrid.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def __init__(self, components: Set[Component], connections: Set[Connection]):
4949
meter_channels = self._create_meter_channels()
5050
ev_charger_channels = self._create_ev_charger_channels()
5151

52+
self._all_channels: Dict[int, Broadcast[Any]] = {
53+
**bat_channels,
54+
**inv_channels,
55+
**meter_channels,
56+
**ev_charger_channels,
57+
}
58+
5259
mock_api = self._create_mock_api(
5360
bat_channels, inv_channels, meter_channels, ev_charger_channels
5461
)
@@ -128,6 +135,15 @@ async def send(self, data: ComponentData) -> bool:
128135

129136
raise RuntimeError(f"{type(data)} is not supported in MockMicrogridClient.")
130137

138+
async def close_channel(self, cid: int) -> None:
139+
"""Close channel for given component id.
140+
141+
Args:
142+
cid: Component id
143+
"""
144+
if cid in self._all_channels:
145+
await self._all_channels[cid].close()
146+
131147
def _create_battery_channels(self) -> Dict[int, Broadcast[BatteryData]]:
132148
"""Create channels for the batteries.
133149

0 commit comments

Comments
 (0)