testframework.clients.brain package

Init Brain Client module for Framework and TestCase Automation

class testframework.clients.brain.TestClient(tb: TestBench, default_timeout: int = 30, port: int = 1883, keep_alive: int = 300)

Bases: BaseClient

Test client to be used in automatic tests cases. It has access to TestBench InfluxDB reflected in the name with_recorded.

Interactions with this client that are triggering state changes in the hardware (such as contactors) are recorded in the influxdb alongside the sensor data measured from the equipment under test.

Power Measurements in this client use L1, L2 and L3 as suffix for a single power line of the 3 phase connection

Not for all testbenches all client functionality is available! pvsystem, houseload, and solar are available for pvsystem benches wallbox and car are available for wallbox benches

To check if functionality of subobject is available clients subobject can be asserted in testcase like this:

>>> assert test_client.pvsystem is not None
>>> test_client.pvsystem.turn_on_supply
Usage:

Given a testbench from inventory model you can create a new TestClient with TestClient(testbench, 30)

The client provides an interface to resources on the testbench including
  • houseload

  • car

  • pv_system

  • grid

  • wallbox

  • solar

These can be accessed given an instance of TestClient with .car for example:

Example

>>> def test_houseload_load1(self, testbench: TestBench):
>>>    brain = TestClient(testbench, default_timeout=30)
>>>    brain.car.connect()
>>>    assert brain.car.is_connected()
car = None
check_value(comp: Comparators, variable: PowerVariables, sampling_point: SamplingPoint, expected: list[float | int]) float

Checks last power measurement variable for sampling point with given comparator is true via MQTT.

Parameters:
  • client (MQTTClient) – The MQTT client object.

  • comp (Comparators) – The comparator type, i.e Compartors.BIGGER.

  • variable (MQTTVariables) – The MQTT variable object, i.e MQTTVariables.POWERTOTAL.

  • sampling_point (SamplingPoint) – The sampling point object, i.e SamplingPoint.GRID

  • expected (list) – The expected value(s) to compare against.

Returns:

The value received from MQTT client.

Return type:

Any

grid = None
houseload = None
pvsystem = None
set_contactor_state(contactor_point: ContactorPoints, contactor_state: ContactorState) ContactorStateResponse

This function shouldn’t be used directly unless you know what you’re doing, instead we refer to using the provided objects in this client, i.e [houseload, car, solar, pv_system, grid]

Parameters:
  • contactor_point – (ContactorPoints) the contactor pin to manipulate

  • contactor_state – (ContactorState) the desired state to set on the pin

This sets contactor state for contactor point via testframework API.

solar = None
wait_for_value(comp: Comparators, variable: PowerVariables, sampling_point: SamplingPoint, expected: list[Any], dur: float, start_time: float) float | None

Checks continuously power measurement variable for sampling point with given comparator until it’s true. When value was not met in specified duration via MQTT it returns an error.

Parameters:
  • comp (Comparators) – The comparator object.

  • variable (PowerVariables) – The Power variable object.

  • sampling_point (SamplingPoint) – The sampling point object.

  • expected (list) – The expected value.

  • dur (float) – The duration to wait for the value.

  • start_time – The start time of the waiting period.

Returns:

The elapsed time if the value is received within the duration, None otherwise.

Return type:

Optional[float]

wallbox = None

Subpackages

Submodules