From 4316832b9576eeb150e700edeac60eaa044db3b4 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 19 Feb 2021 14:53:30 +0100 Subject: [PATCH] input merging mechanism --- owrx/controllers/settings/device.py | 11 +++++++---- owrx/source/rtl_sdr.py | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/owrx/controllers/settings/device.py b/owrx/controllers/settings/device.py index 803644a..edf6348 100644 --- a/owrx/controllers/settings/device.py +++ b/owrx/controllers/settings/device.py @@ -1,6 +1,5 @@ from owrx.form import Input from owrx.controllers.settings import Section -from abc import ABC, abstractmethod from typing import List @@ -8,7 +7,7 @@ class SdrDeviceDescriptionMissing(Exception): pass -class SdrDeviceDescription(ABC): +class SdrDeviceDescription(object): @staticmethod def getByType(sdr_type: str) -> "SdrDeviceDescription": try: @@ -19,9 +18,13 @@ class SdrDeviceDescription(ABC): except (ModuleNotFoundError, AttributeError): raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type)) - @abstractmethod def getInputs(self) -> List[Input]: - pass + return [] + + def mergeInputs(self, *args): + # build a dictionary indexed by the input id to make sure every id only exists once + inputs = {input.id: input for input_list in args for input in input_list} + return inputs.values() def getSection(self): return Section("Device settings", *self.getInputs()) diff --git a/owrx/source/rtl_sdr.py b/owrx/source/rtl_sdr.py index ff1a0df..7fe899b 100644 --- a/owrx/source/rtl_sdr.py +++ b/owrx/source/rtl_sdr.py @@ -17,9 +17,9 @@ class RtlSdrSource(ConnectorSource): class RtlSdrDeviceDescription(SdrDeviceDescription): def getInputs(self) -> List[Input]: - return [ - TextInput( - "test", - "This is a drill" - ), - ] + return self.mergeInputs( + super().getInputs(), + [ + TextInput("test", "This is a drill"), + ], + )