move device descriptions to owrx.source
This commit is contained in:
parent
012952f6f3
commit
bec61465c9
@ -4,16 +4,20 @@ from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
|
||||
|
||||
class SdrDeviceType(ABC):
|
||||
class SdrDeviceDescriptionMissing(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SdrDeviceDescription(ABC):
|
||||
@staticmethod
|
||||
def getByType(sdr_type: str) -> "SdrDeviceType":
|
||||
def getByType(sdr_type: str) -> "SdrDeviceDescription":
|
||||
try:
|
||||
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceType"
|
||||
module = __import__("owrx.controllers.settings.devices.{0}".format(sdr_type), fromlist=[className])
|
||||
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription"
|
||||
module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className])
|
||||
cls = getattr(module, className)
|
||||
return cls()
|
||||
except ModuleNotFoundError:
|
||||
return None
|
||||
except (ModuleNotFoundError, AttributeError):
|
||||
raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
|
||||
|
||||
@abstractmethod
|
||||
def getInputs(self) -> List[Input]:
|
@ -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"
|
||||
),
|
||||
]
|
@ -1,7 +1,7 @@
|
||||
from owrx.controllers.admin import AuthorizationMixin
|
||||
from owrx.controllers.template import WebpageController
|
||||
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 urllib.parse import quote, unquote
|
||||
|
||||
@ -53,11 +53,12 @@ class SdrDeviceController(SettingsFormController):
|
||||
self.device = self._get_device()
|
||||
|
||||
def getSections(self):
|
||||
device_type = SdrDeviceType.getByType(self.device["type"])
|
||||
if device_type is None:
|
||||
try:
|
||||
description = SdrDeviceDescription.getByType(self.device["type"])
|
||||
return [description.getSection()]
|
||||
except SdrDeviceDescriptionMissing:
|
||||
# TODO provide a generic interface that allows to switch the type
|
||||
return []
|
||||
return [device_type.getSection()]
|
||||
|
||||
def getTitle(self):
|
||||
return self.device["name"]
|
||||
|
@ -1,5 +1,8 @@
|
||||
from .connector import ConnectorSource
|
||||
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):
|
||||
@ -10,3 +13,13 @@ class RtlSdrSource(ConnectorSource):
|
||||
.setBase("rtl_connector")
|
||||
.setMappings({"bias_tee": Flag("-b"), "direct_sampling": Option("-e")})
|
||||
)
|
||||
|
||||
|
||||
class RtlSdrDeviceDescription(SdrDeviceDescription):
|
||||
def getInputs(self) -> List[Input]:
|
||||
return [
|
||||
TextInput(
|
||||
"test",
|
||||
"This is a drill"
|
||||
),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user