Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register signal analyzer signal/signal analyzer monitor #107

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scos_actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "7.1.0"
__version__ = "8.0.0"
5 changes: 5 additions & 0 deletions scos_actions/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .signal_analyzer_monitor import SignalAnalyzerMonitor
from .status_monitor import StatusMonitor

signal_analyzer_monitor = SignalAnalyzerMonitor()
status_registrar = StatusMonitor()
17 changes: 17 additions & 0 deletions scos_actions/core/signal_analyzer_monitor.py
Original file line number Diff line number Diff line change
@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest including a type hint here and on the property below to indicate that these expect/return instances of SignalAnalyzerInterface

logger.debug(f"Setting Signal Analyzer to {sigan}")
self._signal_analyzer = sigan

@property
def signal_analyzer(self):
return self._signal_analyzer
7 changes: 6 additions & 1 deletion scos_actions/discover/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions scos_actions/discover/tests/test_sigan_registration.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion scos_actions/hardware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -68,6 +75,8 @@ def load_preselector(preselector_config, module, preselector_class_name):
return ps


signal_analyzer_monitor = signal_analyzer_monitor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be unnecessary

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)
Expand Down
13 changes: 13 additions & 0 deletions scos_actions/hardware/signal_analyzer_registration_handler.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 3 additions & 0 deletions scos_actions/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Provides argument 'action'
register_action = Signal()

# Provides argument 'signal_analyzer'
register_signal_analyzer = Signal()
4 changes: 1 addition & 3 deletions scos_actions/status/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import datetime

from .status_monitor import StatusMonitor

status_registrar = StatusMonitor()
from scos_actions.core.status_monitor import StatusMonitor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this import is no longer needed since the status_registrar instance of StatusMonitor was moved to scos_actions.core


start_time = datetime.datetime.utcnow()
2 changes: 1 addition & 1 deletion scos_actions/status/status_registration_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from . import status_registrar
from scos_actions.core import status_registrar

logger = logging.getLogger(__name__)

Expand Down