From d15d9d8c76c17fd2fc1b6af00f01ae6cf9d4f29c Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 23 Feb 2021 00:27:29 +0100 Subject: [PATCH] remove implicit optional handling for optional fields --- owrx/form/device.py | 14 +++++--------- owrx/source/__init__.py | 10 +++------- owrx/source/airspy.py | 2 -- owrx/source/connector.py | 3 --- owrx/source/rtl_sdr.py | 4 +--- owrx/source/runds.py | 8 ++++---- owrx/source/sdrplay.py | 6 ------ owrx/source/soapy.py | 8 +------- 8 files changed, 14 insertions(+), 41 deletions(-) diff --git a/owrx/form/device.py b/owrx/form/device.py index d1c0c92..dfc1bc3 100644 --- a/owrx/form/device.py +++ b/owrx/form/device.py @@ -32,7 +32,7 @@ class GainInput(Input): label=self.label, options=self.render_options(value), stageoption="" if self.gain_stages is None else self.render_stage_option(value), - disabled="disabled" if self.disabled else "" + disabled="disabled" if self.disabled else "", ) def render_options(self, value): @@ -105,6 +105,8 @@ class GainInput(Input): select_id = "{id}-select".format(id=self.id) if select_id in data: + if data[select_id][0] == "auto": + return {self.id: "auto"} if data[select_id][0] == "manual": input_id = "{id}-manual".format(id=self.id) value = 0.0 @@ -120,14 +122,12 @@ class GainInput(Input): settings_dict = [s for s in settings_dict if next(iter(s.values()))] return {self.id: SoapySettings.encode(settings_dict)} - return {self.id: None} + return {} class BiasTeeInput(CheckboxInput): def __init__(self): - super().__init__( - "bias_tee", "Enable Bias-Tee power supply", converter=OptionalConverter(defaultFormValue=False) - ) + super().__init__("bias_tee", "Enable Bias-Tee power supply") class DirectSamplingOptions(DropdownEnum): @@ -152,10 +152,6 @@ class DirectSamplingInput(DropdownInput): "direct_sampling", "Direct Sampling", DirectSamplingOptions, - converter=OptionalConverter( - EnumConverter(DirectSamplingOptions), - defaultFormValue=DirectSamplingOptions.DIRECT_SAMPLING_OFF.name, - ), ) diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index b062bb7..c034102 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -11,7 +11,7 @@ from owrx.command import CommandMapper from owrx.socket import getAvailablePort from owrx.property import PropertyStack, PropertyLayer from owrx.form import Input, TextInput, NumberInput, CheckboxInput -from owrx.form.converter import IntConverter, OptionalConverter +from owrx.form.converter import OptionalConverter from owrx.form.device import GainInput from owrx.controllers.settings import Section from typing import List @@ -471,18 +471,15 @@ class SdrDeviceDescription(object): "ppm", "Frequency correction", append="ppm", - converter=OptionalConverter(IntConverter(), defaultFormValue="0"), ), CheckboxInput( "always-on", "Keep device running at all times", infotext="Prevents shutdown of the device when idle. Useful for devices with unreliable startup.", - converter=OptionalConverter(defaultFormValue=False), ), CheckboxInput( "services", "Run background services on this device", - converter=OptionalConverter(defaultFormValue=True), ), GainInput("rf_gain", "Device gain"), NumberInput( @@ -491,10 +488,9 @@ class SdrDeviceDescription(object): append="Hz", infotext="Use this when the actual receiving frequency differs from the frequency to be tuned on the" + " device.
Formula: Center frequency + oscillator offset = sdr tune frequency", - converter=OptionalConverter(), ), - NumberInput("waterfall_min_level", "Lowest waterfall level", append="dBFS", converter=OptionalConverter()), - NumberInput("waterfall_max_level", "Highest waterfall level", append="dBFS", converter=OptionalConverter()), + NumberInput("waterfall_min_level", "Lowest waterfall level", append="dBFS"), + NumberInput("waterfall_max_level", "Highest waterfall level", append="dBFS"), # TODO `schedule` ] diff --git a/owrx/source/airspy.py b/owrx/source/airspy.py index 5a907ff..4345b3c 100644 --- a/owrx/source/airspy.py +++ b/owrx/source/airspy.py @@ -1,7 +1,6 @@ from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription from owrx.form import Input, CheckboxInput from owrx.form.device import BiasTeeInput -from owrx.form.converter import OptionalConverter from typing import List @@ -29,7 +28,6 @@ class AirspyDeviceDescription(SoapyConnectorDeviceDescription): "Enable bit-packing", infotext="Packs two 12-bit samples into 3 bytes." + " Lowers USB bandwidth consumption, increases CPU load", - converter=OptionalConverter(defaultFormValue=False), ), ] diff --git a/owrx/source/connector.py b/owrx/source/connector.py index e4b5a1a..6af4692 100644 --- a/owrx/source/connector.py +++ b/owrx/source/connector.py @@ -4,7 +4,6 @@ import socket from owrx.command import Flag, Option from typing import List from owrx.form import Input, NumberInput, CheckboxInput -from owrx.form.converter import OptionalConverter, IntConverter import logging @@ -83,13 +82,11 @@ class ConnectorDeviceDescription(SdrDeviceDescription): infotext="Activate an rtl_tcp compatible interface on the port number specified.
" + "Note: Port is only available on the local machine, not on the network.
" + "Note: IQ data may be degraded by the downsampling process to 8 bits.", - converter=OptionalConverter(IntConverter()), ), CheckboxInput( "iqswap", "Swap I and Q channels", infotext="Swapping inverts the spectrum, so this is useful in combination with an inverting mixer", - converter=OptionalConverter(defaultFormValue=False), ), ] diff --git a/owrx/source/rtl_sdr.py b/owrx/source/rtl_sdr.py index a01e41d..a4da374 100644 --- a/owrx/source/rtl_sdr.py +++ b/owrx/source/rtl_sdr.py @@ -2,7 +2,6 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.command import Flag, Option from typing import List from owrx.form import Input, TextInput -from owrx.form.converter import OptionalConverter from owrx.form.device import BiasTeeInput, DirectSamplingInput @@ -23,10 +22,9 @@ class RtlSdrDeviceDescription(ConnectorDeviceDescription): "device", "Device identifier", infotext="Device serial number or index", - converter=OptionalConverter(), ), BiasTeeInput(), - DirectSamplingInput() + DirectSamplingInput(), ] def getOptionalKeys(self): diff --git a/owrx/source/runds.py b/owrx/source/runds.py index 9b33da5..224d65d 100644 --- a/owrx/source/runds.py +++ b/owrx/source/runds.py @@ -2,7 +2,6 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.command import Argument, Flag, Option from owrx.form import Input, DropdownInput, DropdownEnum, CheckboxInput from owrx.form.device import RemoteInput -from owrx.form.converter import OptionalConverter from typing import List @@ -42,10 +41,11 @@ class RundsDeviceDescription(ConnectorDeviceDescription): return super().getInputs() + [ RemoteInput(), DropdownInput("protocol", "Protocol", ProtocolOptions), - CheckboxInput( - "long", "", "Use 32-bit sample size (LONG)", converter=OptionalConverter(defaultFormValue=False) - ), + CheckboxInput("long", "Use 32-bit sample size (LONG)"), ] def getMandatoryKeys(self): return super().getMandatoryKeys() + ["device"] + + def getOptionalKeys(self): + return super().getOptionalKeys() + ["protocol", "long"] diff --git a/owrx/source/sdrplay.py b/owrx/source/sdrplay.py index dbf6d7d..19b1509 100644 --- a/owrx/source/sdrplay.py +++ b/owrx/source/sdrplay.py @@ -1,7 +1,6 @@ from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription from owrx.form import Input, CheckboxInput, DropdownInput, DropdownEnum from owrx.form.device import BiasTeeInput -from owrx.form.converter import OptionalConverter, EnumConverter from typing import List @@ -43,20 +42,15 @@ class SdrplayDeviceDescription(SoapyConnectorDeviceDescription): CheckboxInput( "rf_notch", "Enable RF notch filter", - converter=OptionalConverter(defaultFormValue=True), ), CheckboxInput( "dab_notch", "Enable DAB notch filter", - converter=OptionalConverter(defaultFormValue=True), ), DropdownInput( "if_mode", "IF Mode", IfModeOptions, - converter=OptionalConverter( - EnumConverter(IfModeOptions), defaultFormValue=IfModeOptions.IFMODE_ZERO_IF.name - ), ), ] diff --git a/owrx/source/soapy.py b/owrx/source/soapy.py index 0db1c45..02973f6 100644 --- a/owrx/source/soapy.py +++ b/owrx/source/soapy.py @@ -3,7 +3,6 @@ from owrx.command import Option from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from typing import List from owrx.form import Input, TextInput -from owrx.form.converter import OptionalConverter from owrx.form.device import GainInput from owrx.soapy import SoapySettings @@ -89,18 +88,13 @@ class SoapyConnectorDeviceDescription(ConnectorDeviceDescription): "device", "Device Identifier", infotext='SoapySDR device identifier string (example: "serial=123456789")', - converter=OptionalConverter() ), GainInput( "rf_gain", "Device Gain", gain_stages=self.getGainStages(), ), - TextInput( - "antenna", - "Antenna", - converter=OptionalConverter(), - ), + TextInput("antenna", "Antenna"), ] def getOptionalKeys(self):