move device descriptions to owrx.source

This commit is contained in:
Jakob Ketterl 2021-02-19 14:44:16 +01:00
parent 012952f6f3
commit bec61465c9
4 changed files with 28 additions and 23 deletions

View File

@ -4,16 +4,20 @@ from abc import ABC, abstractmethod
from typing import List from typing import List
class SdrDeviceType(ABC): class SdrDeviceDescriptionMissing(Exception):
pass
class SdrDeviceDescription(ABC):
@staticmethod @staticmethod
def getByType(sdr_type: str) -> "SdrDeviceType": def getByType(sdr_type: str) -> "SdrDeviceDescription":
try: try:
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceType" className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription"
module = __import__("owrx.controllers.settings.devices.{0}".format(sdr_type), fromlist=[className]) module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className])
cls = getattr(module, className) cls = getattr(module, className)
return cls() return cls()
except ModuleNotFoundError: except (ModuleNotFoundError, AttributeError):
return None raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
@abstractmethod @abstractmethod
def getInputs(self) -> List[Input]: def getInputs(self) -> List[Input]:

View File

@ -1,13 +0,0 @@
from typing import List
from owrx.controllers.settings.devices import SdrDeviceType
from owrx.form import Input, TextInput
class RtlSdrDeviceType(SdrDeviceType):
def getInputs(self) -> List[Input]:
return [
TextInput(
"test",
"This is a drill"
),
]

View File

@ -1,7 +1,7 @@
from owrx.controllers.admin import AuthorizationMixin from owrx.controllers.admin import AuthorizationMixin
from owrx.controllers.template import WebpageController from owrx.controllers.template import WebpageController
from owrx.controllers.settings import SettingsFormController from owrx.controllers.settings import SettingsFormController
from owrx.controllers.settings.devices import SdrDeviceType from owrx.controllers.settings.device import SdrDeviceDescription, SdrDeviceDescriptionMissing
from owrx.config import Config from owrx.config import Config
from urllib.parse import quote, unquote from urllib.parse import quote, unquote
@ -53,11 +53,12 @@ class SdrDeviceController(SettingsFormController):
self.device = self._get_device() self.device = self._get_device()
def getSections(self): def getSections(self):
device_type = SdrDeviceType.getByType(self.device["type"]) try:
if device_type is None: description = SdrDeviceDescription.getByType(self.device["type"])
return [description.getSection()]
except SdrDeviceDescriptionMissing:
# TODO provide a generic interface that allows to switch the type # TODO provide a generic interface that allows to switch the type
return [] return []
return [device_type.getSection()]
def getTitle(self): def getTitle(self):
return self.device["name"] return self.device["name"]

View File

@ -1,5 +1,8 @@
from .connector import ConnectorSource from .connector import ConnectorSource
from owrx.command import Flag, Option from owrx.command import Flag, Option
from owrx.controllers.settings.device import SdrDeviceDescription
from typing import List
from owrx.form import Input, TextInput
class RtlSdrSource(ConnectorSource): class RtlSdrSource(ConnectorSource):
@ -10,3 +13,13 @@ class RtlSdrSource(ConnectorSource):
.setBase("rtl_connector") .setBase("rtl_connector")
.setMappings({"bias_tee": Flag("-b"), "direct_sampling": Option("-e")}) .setMappings({"bias_tee": Flag("-b"), "direct_sampling": Option("-e")})
) )
class RtlSdrDeviceDescription(SdrDeviceDescription):
def getInputs(self) -> List[Input]:
return [
TextInput(
"test",
"This is a drill"
),
]