campbellcontrol package

Subpackages

Submodules

campbellcontrol.control module

Module for sending commands and receiving responses from loggers.

class campbellcontrol.control.CommandHandler(client: Connection)

Bases: ABC

Interface class for command/response handling. Different MQTT client objects have different signatures for the “on_message” method that must be reduced down to a “topic” and “message” to be processed by the current command instance. There are also different invocations for sending/receiving a command, so multiple CommandHandler classes are needed.

command: Command | None = None

The current control command being sent/received.

response: Any | None = None

The latest response. Used to break out of wait state.

client: Connection

Handle to the broker connection client object.

handle_response(*args, **kwargs) None

Forwards arguments to the command’s handler method.

reset() None

Resets the stateful attributes.

send_command(command: Command, *args, timeout: int = 20, **kwargs) CommandResponse | None

Invokes a given MQTT command and awaits the response until timeout is reached.

Parameters:
  • command – The specified Campbell compatible command.

  • *args – Arguments to pass to the given command.

  • timeout – Time in seconds before the command aborts.

  • **kwargs – Keyword arguments passed to the command.

Returns:

A CommandResponse dictionary if a response is received, otherwise None.

class campbellcontrol.control.PahoCommandHandler(client: Connection)

Bases: CommandHandler

Handler class for the generic PAHO based clients.

handle_response(client: Client, userdata: Any, msg: MQTTMessage) None
Forwards message topic and payload for a message from a logger to

the command response handler.

Parameters:
  • client – The MQTT client.

  • userdata – Data defined by the user.

  • msg – The received message.

class campbellcontrol.control.AWSCommandHandler(client: Connection)

Bases: CommandHandler

handle_response(topic: str, payload: bytes, dup: bool, qos: QoS, retain: bool, **kwargs) None

Forwards arguments to the command’s handler method.

Module contents