Skip to content

Commit b76d108

Browse files
committed
Add methods for sending individual mock component data messages
Previously it was only possible to start an automatic task, that sends out its own values continuously. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 0f4fe4c commit b76d108

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

tests/timeseries/mock_microgrid.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,95 @@ def add_ev_chargers(self, count: int) -> None:
363363
self._start_ev_charger_streaming(evc_id)
364364
self._connections.add(Connection(self._connect_to, evc_id))
365365

366+
async def send_meter_data(self, values: list[float]) -> None:
367+
"""Send raw meter data from the mock microgrid.
368+
369+
Args:
370+
values: list of active power values for each meter.
371+
"""
372+
assert len(values) == len(self.meter_ids)
373+
timestamp = datetime.now(tz=timezone.utc)
374+
for comp_id, value in zip(self.meter_ids, values):
375+
await self._microgrid.send(
376+
MeterDataWrapper(
377+
component_id=comp_id,
378+
timestamp=timestamp,
379+
active_power=value,
380+
current_per_phase=(
381+
value + 100.0,
382+
value + 101.0,
383+
value + 102.0,
384+
),
385+
)
386+
)
387+
388+
async def send_battery_data(self, socs: list[float]) -> None:
389+
"""Send raw battery data from the mock microgrid.
390+
391+
Args:
392+
values: list of soc values for each battery.
393+
"""
394+
assert len(socs) == len(self.battery_ids)
395+
timestamp = datetime.now(tz=timezone.utc)
396+
for comp_id, value in zip(self.battery_ids, socs):
397+
await self._microgrid.send(
398+
BatteryDataWrapper(component_id=comp_id, timestamp=timestamp, soc=value)
399+
)
400+
401+
async def send_battery_inverter_data(self, values: list[float]) -> None:
402+
"""Send raw battery inverter data from the mock microgrid.
403+
404+
Args:
405+
values: list of active power values for each battery inverter.
406+
"""
407+
assert len(values) == len(self.battery_inverter_ids)
408+
timestamp = datetime.now(tz=timezone.utc)
409+
for comp_id, value in zip(self.battery_inverter_ids, values):
410+
await self._microgrid.send(
411+
InverterDataWrapper(
412+
component_id=comp_id, timestamp=timestamp, active_power=value
413+
)
414+
)
415+
416+
async def send_pv_inverter_data(self, values: list[float]) -> None:
417+
"""Send raw pv inverter data from the mock microgrid.
418+
419+
Args:
420+
values: list of active power values for each pv inverter.
421+
"""
422+
assert len(values) == len(self.pv_inverter_ids)
423+
timestamp = datetime.now(tz=timezone.utc)
424+
for comp_id, value in zip(self.pv_inverter_ids, values):
425+
await self._microgrid.send(
426+
InverterDataWrapper(
427+
component_id=comp_id, timestamp=timestamp, active_power=value
428+
)
429+
)
430+
431+
async def send_ev_charger_data(self, values: list[float]) -> None:
432+
"""Send raw ev charger data from the mock microgrid.
433+
434+
Args:
435+
values: list of active power values for each ev charger.
436+
"""
437+
assert len(values) == len(self.evc_ids)
438+
timestamp = datetime.now(tz=timezone.utc)
439+
for comp_id, value in zip(self.evc_ids, values):
440+
await self._microgrid.send(
441+
EvChargerDataWrapper(
442+
component_id=comp_id,
443+
timestamp=timestamp,
444+
active_power=value,
445+
current_per_phase=(
446+
value + 100.0,
447+
value + 101.0,
448+
value + 102.0,
449+
),
450+
component_state=self.evc_component_states[comp_id],
451+
cable_state=self.evc_cable_states[comp_id],
452+
)
453+
)
454+
366455
async def cleanup(self) -> None:
367456
"""Clean up after a test."""
368457
# pylint: disable=protected-access

0 commit comments

Comments
 (0)