Skip to content

Commit ccb9e29

Browse files
committed
Expose internal mock_client to users of MockMicrogrid
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 7990567 commit ccb9e29

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/timeseries/mock_microgrid.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MockMicrogrid: # pylint: disable=too-many-instance-attributes
4848
inverter_id_suffix = 8
4949
battery_id_suffix = 9
5050

51-
_microgrid: MockMicrogridClient
51+
mock_client: MockMicrogridClient
5252
mock_resampler: MockResampler
5353

5454
def __init__( # pylint: disable=too-many-arguments
@@ -123,8 +123,8 @@ def init_mock_client(
123123
self, initialize_cb: Callable[[MockMicrogridClient], None]
124124
) -> None:
125125
"""Set up the mock client. Does not start the streaming tasks."""
126-
self._microgrid = MockMicrogridClient(self._components, self._connections)
127-
initialize_cb(self._microgrid)
126+
self.mock_client = MockMicrogridClient(self._components, self._connections)
127+
initialize_cb(self.mock_client)
128128

129129
def start_mock_client(
130130
self, initialize_cb: Callable[[MockMicrogridClient], None]
@@ -146,7 +146,7 @@ def start_mock_client(
146146
self._streaming_tasks = [
147147
asyncio.create_task(coro) for coro in self._streaming_coros
148148
]
149-
return self._microgrid
149+
return self.mock_client
150150

151151
async def _comp_data_send_task(
152152
self, comp_id: int, make_comp_data: Callable[[int, datetime], ComponentData]
@@ -157,12 +157,12 @@ async def _comp_data_send_task(
157157
# for inverters with component_id > 100, send only half the messages.
158158
if comp_id % 10 == self.inverter_id_suffix:
159159
if comp_id < 100 or value <= 5:
160-
await self._microgrid.send(make_comp_data(val_to_send, timestamp))
160+
await self.mock_client.send(make_comp_data(val_to_send, timestamp))
161161
else:
162-
await self._microgrid.send(make_comp_data(val_to_send, timestamp))
162+
await self.mock_client.send(make_comp_data(val_to_send, timestamp))
163163
await asyncio.sleep(self._sample_rate_s)
164164

165-
await self._microgrid.close_channel(comp_id)
165+
await self.mock_client.close_channel(comp_id)
166166

167167
def _start_meter_streaming(self, meter_id: int) -> None:
168168
if not self._api_client_streaming:
@@ -359,7 +359,7 @@ async def send_meter_data(self, values: list[float]) -> None:
359359
assert len(values) == len(self.meter_ids)
360360
timestamp = datetime.now(tz=timezone.utc)
361361
for comp_id, value in zip(self.meter_ids, values):
362-
await self._microgrid.send(
362+
await self.mock_client.send(
363363
MeterDataWrapper(
364364
component_id=comp_id,
365365
timestamp=timestamp,
@@ -381,7 +381,7 @@ async def send_battery_data(self, socs: list[float]) -> None:
381381
assert len(socs) == len(self.battery_ids)
382382
timestamp = datetime.now(tz=timezone.utc)
383383
for comp_id, value in zip(self.battery_ids, socs):
384-
await self._microgrid.send(
384+
await self.mock_client.send(
385385
BatteryDataWrapper(component_id=comp_id, timestamp=timestamp, soc=value)
386386
)
387387

@@ -394,7 +394,7 @@ async def send_battery_inverter_data(self, values: list[float]) -> None:
394394
assert len(values) == len(self.battery_inverter_ids)
395395
timestamp = datetime.now(tz=timezone.utc)
396396
for comp_id, value in zip(self.battery_inverter_ids, values):
397-
await self._microgrid.send(
397+
await self.mock_client.send(
398398
InverterDataWrapper(
399399
component_id=comp_id, timestamp=timestamp, active_power=value
400400
)
@@ -409,7 +409,7 @@ async def send_pv_inverter_data(self, values: list[float]) -> None:
409409
assert len(values) == len(self.pv_inverter_ids)
410410
timestamp = datetime.now(tz=timezone.utc)
411411
for comp_id, value in zip(self.pv_inverter_ids, values):
412-
await self._microgrid.send(
412+
await self.mock_client.send(
413413
InverterDataWrapper(
414414
component_id=comp_id, timestamp=timestamp, active_power=value
415415
)
@@ -424,7 +424,7 @@ async def send_ev_charger_data(self, values: list[float]) -> None:
424424
assert len(values) == len(self.evc_ids)
425425
timestamp = datetime.now(tz=timezone.utc)
426426
for comp_id, value in zip(self.evc_ids, values):
427-
await self._microgrid.send(
427+
await self.mock_client.send(
428428
EvChargerDataWrapper(
429429
component_id=comp_id,
430430
timestamp=timestamp,

0 commit comments

Comments
 (0)