AbstractCommandHandler

class lsst.ts.ess.common.AbstractCommandHandler(callback: Callable, simulation_mode: int)

Bases: ABC

Handle incoming commands and send replies. Apply configuration and read sensor data.

Parameters:
callbackCallable

The callback coroutine handling the sensor telemetry. This can be a coroutine that sends the data via a socket connection or a coroutine in a test class to verify that the command has been handled correctly.

simulation_modeint

Indicating if a simulation mode (> 0) or not (0) is active.

The commands that can be handled are:

configure: Load the configuration that is passed on with the command and connect to the devices specified in that configuration. This command can be sent multiple times before a start is received and only the last configuration is kept. start: Start reading the sensor data of the connected devices and send it as plain text via the socket. If no configuration was sent then the start command is ignored. Once started no configuration changes can be done anymore. stop: Stop sending sensor data and disconnect from all devices. Once stopped, configuration changes can be done again and/or reading of sensor data can be started again.

Attributes Summary

valid_simulation_modes

Methods Summary

configure(configuration)

Apply the configuration and start sending telemetry.

create_device(device_configuration)

Create the device to connect to by using the specified configuration.

handle_command(command, **kwargs)

Handle incomming commands and parameters.

stop_sending_telemetry()

Stop reading the sensor data.

Attributes Documentation

valid_simulation_modes = (0, 1)

Methods Documentation

async configure(configuration: dict[str, Any]) None

Apply the configuration and start sending telemetry.

Parameters:
configurationdict

The contents of the dict depend on the type of sensor. See the ts_ess configuration schema for more details.

Raises:
CommandError

A CommandError with ResponseCode ALREADY_STARTED is raised if the command handler already was started.

abstract create_device(device_configuration: dict[str, Any]) BaseDevice

Create the device to connect to by using the specified configuration.

Parameters:
device_configurationdict

A dict representing the device to connect to. The format of the dict follows the configuration of the ts_ess_csc project.

Returns:
devicecommon.device.BaseDevice

The device to connect to.

Raises:
RuntimeError

In case an incorrect configuration has been loaded.

Notes

In this case a MockDevice always is returned. Sub-classes should override this method to add support for other devices.

async handle_command(command: str, **kwargs: Any) None

Handle incomming commands and parameters.

Parameters:
commandstr

The command to handle.

kwargs:

The parameters to the command.

async stop_sending_telemetry() None

Stop reading the sensor data.

Raises:
CommandError

A CommandError with ResponseCode NOT_STARTED is raised if the command handler was not started yet.