testframework.clients.ops.base_client module

This module defines the OpsBaseClient class, which interfaces with the OpsAPI This should contain core methods to communicate with the OpsAPI but additional logic should be created in the inherited classes: - FrameworkOpsClient (framework_client.py) - OpsClient (tester_client.py)

class testframework.clients.ops.base_client.OpsBaseClient(url: str, default_timeout: int)

Bases: object

The base client for interacting with the Operations Container API.

This class provides methods for making HTTP requests to the Operations Container API, such as GET, POST, PUT, and DELETE requests. It also includes methods for retrieving global sensor data, PV sensor data, device properties, and performing various operations on the Operations Container.

url_base

The base URL of the Operations Container API.

Type:

str

logger

The logger object for logging debug and error messages.

Type:

logging.Logger

default_timeout

The default timeout value for HTTP requests.

Type:

int

start_time

Start time of the client

Type:

time

async get_all_global_sensor_name(global_sensor_name: type[GlobalSensorName | GlobalSensorNameInverterBatch1 | GlobalSensorNameInverterBatch2 | GlobalSensorNameInverterBatch3 | GlobalSensorNameInverterBatch4 | GlobalSensorNameWallboxBatch1 | GlobalSensorNameWallboxBatch2 | GlobalSensorNameWallboxBatch3 | GlobalSensorNameWallboxBatch4]) list[NumberDataPoint | None]

Async method to get all global sensor names from the provided enum. This iterates over the enum’s values and makes parallel requests to the OpsApi

Parameters:

global_sensor_name (list) – A list of global sensor names.

Returns:

A list of parsed number data points.

Return type:

list[NumberDataPoint]

get_device_properties() list[DeviceProperties | None]

Returns properties of all devices i.e inverter, battery, edge device etc. :raises ValidationError: If failed to validate response from API.

Returns:

An instance of the DeviceProperties class containing the properties of all devices.

Return type:

DeviceProperties

get_global_sensor_name(sensor_name: GlobalSensorName | GlobalSensorNameInverterBatch1) NumberDataPoint

Sends a GET request for the value of Global Sensor Name of Operation Container.

Parameters:

sensor_name (GlobalSensorName) – The name of the global sensor.

Raises:

ValidationError – if failed to validate response from API

Returns:

The value of the global sensor as a NumberDataPoint object.

Return type:

NumberDataPoint

get_pv_sensor_value(sensor_name: GlobalSensorName) SensorValue

Sends a GET request for PV Sensor value by Name from Operation Container.

Parameters:

sensor_name (GlobalSensorName) – The name of the sensor.

Raises:

Validation Error if failed –

Returns:

The value of the sensor.

Return type:

SensorValue

post_device_defaults() bool

Sends a POST request to apply default parameters of the system.

Raises:
  • ValueError – If the OpsApi fails with a status code other than 200, or if there is an error in the response.

  • Exception – If there is an exception while processing the response.

Returns:

True if the default parameters are successfully applied, False otherwise.

Return type:

bool

post_pv_action(pv_action: PvActionRequest) float | ErrorResponse

Sends a POST request to the Pv Action endpoint.

Parameters:

pv_action (PvActionRequest) – The PvActionRequest object containing the data for the request.

Raises:

ValueError – If the response code is not 200 or 400.

Returns:

The start time of the request if successful, or an ErrorResponse object if there was an error.

Return type:

float | ErrorResponse

put_grid_control_lpc(data: LoadLimitRequest) GridControlResponse

Puts Limit Power Consumption to operation container.

Parameters:

data (LoadLimitRequest) – The data containing the load limit request.

Raises:

ValidationError – if failed to parse response from API.

Returns:

The response from the operation container.

Return type:

GridControlResponse

put_grid_control_lpp(data: LoadLimitRequest) GridControlResponse

Puts Limit Power Production to operation container.

Parameters:

data (LoadLimitRequest) – The data containing the load limit request.

Raises:

ValidationError – If failed to parse response from API

Returns:

The response from the operation container.

Return type:

GridControlResponse

remove_grid_control_lpp(timeout: int | None) GridControlResponse

Removes the lpp setting of the Operations Container.

Raises:

ValidationError –

Returns:

A GridControlResponse object representing the response from the API.

wait_for_sensor_value(sensor_type: Type[float | str], sensor_name: GlobalSensorName, expected_values: list[int | float | str], comparator: Comparators, timeout_seconds: int, success_hold_seconds: int, delay_seconds: int = 1) str | float

Waits for a specified SensorValue (modbus register) to fulfill the provided parameters. The value needs to remain within parameters for a specified amount of time for the method to succeed.

Parameters:
  • sensor_type (Type[str|float]) – Return type of the associated modbus register (string | int | float)

  • sensor_name (GlobalSensorName) – The sensor value to monitor

  • expected_values (list) – Expected value (range) as required by the specified comparator

  • comparator (Comparators) – Comparator to apply between the expected and received value

  • timeout_seconds (int) – Maximum wait time in seconds. This includes the success-hold time.

  • success_hold_seconds (int) – Time in seconds for which the value has to continuously satisfy the comparator condition.

  • delay_seconds (int, optional) – Frequency in which to check for value changes. Defaults to 1.

Raises:

SensorValueTimeoutException – Raised if the value does not meet the expected constraints in the given time.

Returns:

value returned by the register

Return type:

sensor_type(str | float)