diff --git a/owrx/controllers/settings/devices/__init__.py b/owrx/controllers/settings/devices/__init__.py new file mode 100644 index 0000000..30f1882 --- /dev/null +++ b/owrx/controllers/settings/devices/__init__.py @@ -0,0 +1,23 @@ +from owrx.form import Input +from owrx.controllers.settings import Section +from abc import ABC, abstractmethod +from typing import List + + +class SdrDeviceType(ABC): + @staticmethod + def getByType(sdr_type: str) -> "SdrDeviceType": + 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]) + cls = getattr(module, className) + return cls() + except ModuleNotFoundError: + return None + + @abstractmethod + def getInputs(self) -> List[Input]: + pass + + def getSection(self): + return Section("Device settings", *self.getInputs()) diff --git a/owrx/controllers/settings/devices/rtl_sdr.py b/owrx/controllers/settings/devices/rtl_sdr.py new file mode 100644 index 0000000..af6673e --- /dev/null +++ b/owrx/controllers/settings/devices/rtl_sdr.py @@ -0,0 +1,13 @@ +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" + ), + ] diff --git a/owrx/controllers/settings/sdr.py b/owrx/controllers/settings/sdr.py index 88cf10f..6c2661e 100644 --- a/owrx/controllers/settings/sdr.py +++ b/owrx/controllers/settings/sdr.py @@ -1,5 +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.config import Config from urllib.parse import quote, unquote @@ -45,8 +47,22 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController): self.serve_template("settings/general.html", **self.template_variables()) -class SdrDeviceController(AuthorizationMixin, WebpageController): - def get_device(self): +class SdrDeviceController(SettingsFormController): + def __init__(self, handler, request, options): + super().__init__(handler, request, options) + self.device = self._get_device() + + def getSections(self): + device_type = SdrDeviceType.getByType(self.device["type"]) + if device_type is None: + # TODO provide a generic interface that allows to switch the type + return [] + return [device_type.getSection()] + + def getTitle(self): + return self.device["name"] + + def _get_device(self): device_id = unquote(self.request.matches.group(1)) if device_id not in Config.get()["sdrs"]: return None @@ -57,16 +73,13 @@ class SdrDeviceController(AuthorizationMixin, WebpageController): variables["assets_prefix"] = "../../" return variables - def template_variables(self, device): + def template_variables(self): variables = super().template_variables() - variables["title"] = device["name"] - variables["content"] = "TODO" variables["assets_prefix"] = "../../" return variables def indexAction(self): - device = self.get_device() - if device is None: + if self.device is None: self.send_response("device not found", code=404) return - self.serve_template("settings/general.html", **self.template_variables(device)) + self.serve_template("settings/general.html", **self.template_variables()) diff --git a/owrx/sdr.py b/owrx/sdr.py index 039e914..87cc9bd 100644 --- a/owrx/sdr.py +++ b/owrx/sdr.py @@ -71,7 +71,7 @@ class SdrService(object): def getSources(): SdrService._loadProps() for id in SdrService.sdrProps.keys(): - if not id in SdrService.sources: + if id not in SdrService.sources: props = SdrService.sdrProps[id] sdrType = props["type"] className = "".join(x for x in sdrType.title() if x.isalnum()) + "Source"