2021-02-18 23:46:52 +00:00
|
|
|
from owrx.form import Input
|
|
|
|
from owrx.controllers.settings import Section
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
2021-02-19 13:44:16 +00:00
|
|
|
class SdrDeviceDescriptionMissing(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class SdrDeviceDescription(ABC):
|
2021-02-18 23:46:52 +00:00
|
|
|
@staticmethod
|
2021-02-19 13:44:16 +00:00
|
|
|
def getByType(sdr_type: str) -> "SdrDeviceDescription":
|
2021-02-18 23:46:52 +00:00
|
|
|
try:
|
2021-02-19 13:44:16 +00:00
|
|
|
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription"
|
|
|
|
module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className])
|
2021-02-18 23:46:52 +00:00
|
|
|
cls = getattr(module, className)
|
|
|
|
return cls()
|
2021-02-19 13:44:16 +00:00
|
|
|
except (ModuleNotFoundError, AttributeError):
|
|
|
|
raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
|
2021-02-18 23:46:52 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def getInputs(self) -> List[Input]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def getSection(self):
|
|
|
|
return Section("Device settings", *self.getInputs())
|