diff --git a/scos_actions/__init__.py b/scos_actions/__init__.py index 54ccb5d2..73d4c8be 100644 --- a/scos_actions/__init__.py +++ b/scos_actions/__init__.py @@ -1 +1 @@ -__version__ = "7.1.0" +__version__ = "8.0.0" diff --git a/scos_actions/core/__init__.py b/scos_actions/core/__init__.py new file mode 100644 index 00000000..f717c05b --- /dev/null +++ b/scos_actions/core/__init__.py @@ -0,0 +1,5 @@ +from .signal_analyzer_monitor import SignalAnalyzerMonitor +from .status_monitor import StatusMonitor + +signal_analyzer_monitor = SignalAnalyzerMonitor() +status_registrar = StatusMonitor() diff --git a/scos_actions/core/signal_analyzer_monitor.py b/scos_actions/core/signal_analyzer_monitor.py new file mode 100644 index 00000000..eb68de07 --- /dev/null +++ b/scos_actions/core/signal_analyzer_monitor.py @@ -0,0 +1,17 @@ +import logging + +logger = logging.getLogger(__name__) + + +class SignalAnalyzerMonitor: + def __init__(self): + logger.debug("Initializing Signal Analyzer Monitor") + self._signal_analyzer = None + + def register_signal_analyzer(self, sigan): + logger.debug(f"Setting Signal Analyzer to {sigan}") + self._signal_analyzer = sigan + + @property + def signal_analyzer(self): + return self._signal_analyzer diff --git a/scos_actions/status/status_monitor.py b/scos_actions/core/status_monitor.py similarity index 100% rename from scos_actions/status/status_monitor.py rename to scos_actions/core/status_monitor.py diff --git a/scos_actions/discover/__init__.py b/scos_actions/discover/__init__.py index f77df84d..661da6e2 100644 --- a/scos_actions/discover/__init__.py +++ b/scos_actions/discover/__init__.py @@ -1,3 +1,4 @@ +import scos_actions.core from scos_actions.actions import action_classes from scos_actions.actions.logger import Logger from scos_actions.actions.monitor_sigan import MonitorSignalAnalyzer @@ -6,12 +7,16 @@ from scos_actions.hardware.mocks.mock_gps import MockGPS from scos_actions.hardware.mocks.mock_sigan import MockSignalAnalyzer from scos_actions.settings import ACTION_DEFINITIONS_DIR, MOCK_SIGAN -from scos_actions.signals import register_component_with_status +from scos_actions.signals import ( + register_component_with_status, + register_signal_analyzer, +) mock_sigan = MockSignalAnalyzer(randomize_values=True) mock_gps = MockGPS() if MOCK_SIGAN: register_component_with_status.send(mock_sigan.__class__, component=mock_sigan) + register_signal_analyzer.send(__name__, signal_analzyer=mock_sigan) actions = {"logger": Logger()} test_actions = { "test_sync_gps": SyncGps( diff --git a/scos_actions/discover/tests/test_sigan_registration.py b/scos_actions/discover/tests/test_sigan_registration.py new file mode 100644 index 00000000..56ffb181 --- /dev/null +++ b/scos_actions/discover/tests/test_sigan_registration.py @@ -0,0 +1,10 @@ +import pytest +from scos_actions.core import signal_analyzer_monitor +from scos_actions.signals import register_signal_analyzer +from scos_actions.hardware.mocks.mock_sigan import MockSignalAnalyzer + + +def test_sigan_registration(): + sigan = MockSignalAnalyzer() + register_signal_analyzer.send(__name__, signal_analyzer=sigan) + assert signal_analyzer_monitor.signal_analyzer == sigan diff --git a/scos_actions/hardware/__init__.py b/scos_actions/hardware/__init__.py index 34af394d..b8eef049 100644 --- a/scos_actions/hardware/__init__.py +++ b/scos_actions/hardware/__init__.py @@ -7,13 +7,20 @@ from scos_actions import utils from scos_actions.capabilities import capabilities +from scos_actions.core import signal_analyzer_monitor +from scos_actions.hardware.signal_analyzer_registration_handler import ( + signal_analyzer_registration_handler, +) from scos_actions.settings import ( PRESELECTOR_CLASS, PRESELECTOR_CONFIG_FILE, PRESELECTOR_MODULE, SWITCH_CONFIGS_DIR, ) -from scos_actions.signals import register_component_with_status +from scos_actions.signals import ( + register_component_with_status, + register_signal_analyzer, +) from scos_actions.status.status_registration_handler import status_registration_handler logger = logging.getLogger(__name__) @@ -68,6 +75,8 @@ def load_preselector(preselector_config, module, preselector_class_name): return ps +signal_analyzer_monitor = signal_analyzer_monitor +register_signal_analyzer.connect(signal_analyzer_registration_handler) register_component_with_status.connect(status_registration_handler) logger.debug("Connected status registration handler") preselector = load_preselector_from_file(PRESELECTOR_CONFIG_FILE) diff --git a/scos_actions/hardware/signal_analyzer_registration_handler.py b/scos_actions/hardware/signal_analyzer_registration_handler.py new file mode 100644 index 00000000..2555d6ba --- /dev/null +++ b/scos_actions/hardware/signal_analyzer_registration_handler.py @@ -0,0 +1,13 @@ +import logging + +from scos_actions.core import signal_analyzer_monitor + +logger = logging.getLogger(__name__) + + +def signal_analyzer_registration_handler(sender, **kwargs): + try: + logger.debug(f"Registering {sender} as status provider") + signal_analyzer_monitor.register_signal_analyzer(kwargs["signal_analyzer"]) + except: + logger.exception("Error registering signal analyzer") diff --git a/scos_actions/signals.py b/scos_actions/signals.py index 36baaf3b..1818e013 100644 --- a/scos_actions/signals.py +++ b/scos_actions/signals.py @@ -13,3 +13,6 @@ # Provides argument 'action' register_action = Signal() + +# Provides argument 'signal_analyzer' +register_signal_analyzer = Signal() diff --git a/scos_actions/status/__init__.py b/scos_actions/status/__init__.py index f21e1efc..2d749073 100644 --- a/scos_actions/status/__init__.py +++ b/scos_actions/status/__init__.py @@ -1,7 +1,5 @@ import datetime -from .status_monitor import StatusMonitor - -status_registrar = StatusMonitor() +from scos_actions.core.status_monitor import StatusMonitor start_time = datetime.datetime.utcnow() diff --git a/scos_actions/status/status_registration_handler.py b/scos_actions/status/status_registration_handler.py index aed88be3..2cceec5e 100644 --- a/scos_actions/status/status_registration_handler.py +++ b/scos_actions/status/status_registration_handler.py @@ -1,6 +1,6 @@ import logging -from . import status_registrar +from scos_actions.core import status_registrar logger = logging.getLogger(__name__)