psychos.triggers.BaseTrigger#

class psychos.triggers.BaseTrigger(port: BasePort, mapping: Dict[str, int | bytes] | None = None)[source]#

Bases: object

Abstract base class for trigger implementations.

This class provides a common interface for sending triggers through a communication port. It includes functionality to resolve trigger values using an optional mapping and to manage the port connection.

port#

The communication port used to send trigger values.

Type:

BasePort

mapping#

An optional dictionary mapping trigger names to their corresponding values.

Type:

Dict[str, Union[int, bytes]]

__init__(port: BasePort, mapping: Dict[str, int | bytes] | None = None)[source]#

Initialize a BaseTrigger instance.

Parameters:
  • port (BasePort) – The communication port instance used for sending triggers.

  • mapping (Dict[str, Union[int, bytes]], optional) – A dictionary mapping trigger names (as strings) to their corresponding values (as integers or bytes). Defaults to None.

Methods

__init__(port[, mapping])

Initialize a BaseTrigger instance.

close()

Close the trigger by closing the associated communication port.

resolve_value(value)

Resolve the trigger value using the provided mapping.

send(value)

Send a trigger value through the communication port.

close()[source]#

Close the trigger by closing the associated communication port.

After closing, the port reference is set to None.

resolve_value(value: str | int | bytes) int | bytes[source]#

Resolve the trigger value using the provided mapping.

If the value is a string, it is used as a key to retrieve the corresponding trigger value from the mapping. If no mapping exists for the string, a ValueError is raised.

Parameters:

value (Union[str, int, bytes]) – The trigger value to resolve. If a string is provided, it is treated as a key for the mapping.

Returns:

The resolved trigger value.

Return type:

Union[int, bytes]

Raises:

ValueError – If the value is a string and not found in the mapping.

send(value: str | int | bytes)[source]#

Send a trigger value through the communication port.

This method should be implemented by subclasses.

Parameters:

value – The trigger value to send. Its type (string, integer, or bytes) will be resolved appropriately by the subclass.

Raises:

NotImplementedError – Always, as this is an abstract method.