Skip to content

Echo Plugin

Bases: BasePlugin

EchoPlugin is a simple diagnostic plugin that echoes incoming events.

It is useful for testing the event system and verifying that events are being dispatched correctly with their data payload and timestamp.

Source code in plugins/echo/main.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class EchoPlugin(BasePlugin):
    """
    EchoPlugin is a simple diagnostic plugin that echoes incoming events.

    It is useful for testing the event system and verifying that events are
    being dispatched correctly with their data payload and timestamp.
    """

    def __init__(self):
        """
        Initializes the EchoPlugin.

        Sets the plugin name and creates a logger instance.
        """
        self.name = "EchoPlugin"
        self.logger = Logger(self.name)

    def on_init(self, config):
        """
        Called once when the plugin is initialized.

        Args:
            config (dict): Optional configuration parameters (unused in this plugin).
        """
        self.logger.info("Initialized.")

    def on_event(self, topic, data, timestamp):
        """
        Handles incoming events and logs the message.

        If a `message` key exists in the event data, it is echoed.
        Otherwise, the entire data dictionary is converted to a string and echoed.

        Args:
            topic (str): The topic name of the event (e.g., "echo").
            data (dict): Event data payload.
            timestamp (float): Simulation time in seconds when the event occurred.
        """
        message = data.get("message", None)
        if message is None:
            message = str(data)  # Fallback to full data dict
        self.logger.info(f"[{timestamp:.3f}s] Echoed: {message}")

    def on_shutdown(self):
        """
        Called when the plugin is being shut down.

        Used to perform any cleanup before unloading the plugin.
        """
        self.logger.info("Shutting down.")

__init__()

Initializes the EchoPlugin.

Sets the plugin name and creates a logger instance.

Source code in plugins/echo/main.py
34
35
36
37
38
39
40
41
def __init__(self):
    """
    Initializes the EchoPlugin.

    Sets the plugin name and creates a logger instance.
    """
    self.name = "EchoPlugin"
    self.logger = Logger(self.name)

on_event(topic, data, timestamp)

Handles incoming events and logs the message.

If a message key exists in the event data, it is echoed. Otherwise, the entire data dictionary is converted to a string and echoed.

Parameters:

Name Type Description Default
topic str

The topic name of the event (e.g., "echo").

required
data dict

Event data payload.

required
timestamp float

Simulation time in seconds when the event occurred.

required
Source code in plugins/echo/main.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def on_event(self, topic, data, timestamp):
    """
    Handles incoming events and logs the message.

    If a `message` key exists in the event data, it is echoed.
    Otherwise, the entire data dictionary is converted to a string and echoed.

    Args:
        topic (str): The topic name of the event (e.g., "echo").
        data (dict): Event data payload.
        timestamp (float): Simulation time in seconds when the event occurred.
    """
    message = data.get("message", None)
    if message is None:
        message = str(data)  # Fallback to full data dict
    self.logger.info(f"[{timestamp:.3f}s] Echoed: {message}")

on_init(config)

Called once when the plugin is initialized.

Parameters:

Name Type Description Default
config dict

Optional configuration parameters (unused in this plugin).

required
Source code in plugins/echo/main.py
43
44
45
46
47
48
49
50
def on_init(self, config):
    """
    Called once when the plugin is initialized.

    Args:
        config (dict): Optional configuration parameters (unused in this plugin).
    """
    self.logger.info("Initialized.")

on_shutdown()

Called when the plugin is being shut down.

Used to perform any cleanup before unloading the plugin.

Source code in plugins/echo/main.py
69
70
71
72
73
74
75
def on_shutdown(self):
    """
    Called when the plugin is being shut down.

    Used to perform any cleanup before unloading the plugin.
    """
    self.logger.info("Shutting down.")