Skip to content

dp3.common.base_module

BaseModule

BaseModule(platform_config: PlatformConfig, module_config: dict, registrar: CallbackRegistrar)

Base class for platform modules. Every module must inherit this abstract class for automatic loading of module!

Attributes:

Name Type Description
refresh SharedFlag

SharedFlag that is set to True when module should refresh its attributes values

log Logger

Logger for the module

Initialize the module and register callbacks.

self.load_config() is called in the base class.

Parameters:

Name Type Description Default
platform_config PlatformConfig

Platform configuration class

required
module_config dict

Configuration of the module, equivalent of platform_config.config.get("modules.<module_name>")

required
registrar CallbackRegistrar

A callback / hook registration interface

required
Source code in dp3/common/base_module.py
def __init__(
    self, platform_config: PlatformConfig, module_config: dict, registrar: CallbackRegistrar
):
    """Initialize the module and register callbacks.

    `self.load_config()` is called in the base class.

    Args:
        platform_config: Platform configuration class
        module_config: Configuration of the module,
            equivalent of `platform_config.config.get("modules.<module_name>")`
        registrar: A callback / hook registration interface
    """
    self.refresh: SharedFlag = SharedFlag(False, banner=f"Refresh {self.__class__.__name__}")
    self.log: logging.Logger = logging.getLogger(self.__class__.__name__)

    self.load_config(platform_config, module_config)

load_config

load_config(config: PlatformConfig, module_config: dict) -> None

Load module configuration.

Is called on module initialization and on refresh request via /control API.

Source code in dp3/common/base_module.py
def load_config(self, config: PlatformConfig, module_config: dict) -> None:
    """Load module configuration.

    Is called on module initialization and on refresh request via `/control` API.
    """

start

start() -> None

Run the module - used to run own thread if needed.

Called after initialization, may be used to create and run a separate thread if needed by the module. Do nothing unless overridden.

Source code in dp3/common/base_module.py
def start(self) -> None:
    """
    Run the module - used to run own thread if needed.

    Called after initialization, may be used to create and run a separate
    thread if needed by the module. Do nothing unless overridden.
    """
    return None

stop

stop() -> None

Stop the module - used to stop own thread.

Called before program exit, may be used to finalize and stop the separate thread if it is used. Do nothing unless overridden.

Source code in dp3/common/base_module.py
def stop(self) -> None:
    """
    Stop the module - used to stop own thread.

    Called before program exit, may be used to finalize and stop the
    separate thread if it is used. Do nothing unless overridden.
    """
    return None