remove implicit optional handling for optional fields

This commit is contained in:
Jakob Ketterl 2021-02-23 00:27:29 +01:00
parent 436010ffe3
commit d15d9d8c76
8 changed files with 14 additions and 41 deletions

View File

@ -32,7 +32,7 @@ class GainInput(Input):
label=self.label, label=self.label,
options=self.render_options(value), options=self.render_options(value),
stageoption="" if self.gain_stages is None else self.render_stage_option(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): def render_options(self, value):
@ -105,6 +105,8 @@ class GainInput(Input):
select_id = "{id}-select".format(id=self.id) select_id = "{id}-select".format(id=self.id)
if select_id in data: if select_id in data:
if data[select_id][0] == "auto":
return {self.id: "auto"}
if data[select_id][0] == "manual": if data[select_id][0] == "manual":
input_id = "{id}-manual".format(id=self.id) input_id = "{id}-manual".format(id=self.id)
value = 0.0 value = 0.0
@ -120,14 +122,12 @@ class GainInput(Input):
settings_dict = [s for s in settings_dict if next(iter(s.values()))] settings_dict = [s for s in settings_dict if next(iter(s.values()))]
return {self.id: SoapySettings.encode(settings_dict)} return {self.id: SoapySettings.encode(settings_dict)}
return {self.id: None} return {}
class BiasTeeInput(CheckboxInput): class BiasTeeInput(CheckboxInput):
def __init__(self): def __init__(self):
super().__init__( super().__init__("bias_tee", "Enable Bias-Tee power supply")
"bias_tee", "Enable Bias-Tee power supply", converter=OptionalConverter(defaultFormValue=False)
)
class DirectSamplingOptions(DropdownEnum): class DirectSamplingOptions(DropdownEnum):
@ -152,10 +152,6 @@ class DirectSamplingInput(DropdownInput):
"direct_sampling", "direct_sampling",
"Direct Sampling", "Direct Sampling",
DirectSamplingOptions, DirectSamplingOptions,
converter=OptionalConverter(
EnumConverter(DirectSamplingOptions),
defaultFormValue=DirectSamplingOptions.DIRECT_SAMPLING_OFF.name,
),
) )

View File

@ -11,7 +11,7 @@ from owrx.command import CommandMapper
from owrx.socket import getAvailablePort from owrx.socket import getAvailablePort
from owrx.property import PropertyStack, PropertyLayer from owrx.property import PropertyStack, PropertyLayer
from owrx.form import Input, TextInput, NumberInput, CheckboxInput 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.form.device import GainInput
from owrx.controllers.settings import Section from owrx.controllers.settings import Section
from typing import List from typing import List
@ -471,18 +471,15 @@ class SdrDeviceDescription(object):
"ppm", "ppm",
"Frequency correction", "Frequency correction",
append="ppm", append="ppm",
converter=OptionalConverter(IntConverter(), defaultFormValue="0"),
), ),
CheckboxInput( CheckboxInput(
"always-on", "always-on",
"Keep device running at all times", "Keep device running at all times",
infotext="Prevents shutdown of the device when idle. Useful for devices with unreliable startup.", infotext="Prevents shutdown of the device when idle. Useful for devices with unreliable startup.",
converter=OptionalConverter(defaultFormValue=False),
), ),
CheckboxInput( CheckboxInput(
"services", "services",
"Run background services on this device", "Run background services on this device",
converter=OptionalConverter(defaultFormValue=True),
), ),
GainInput("rf_gain", "Device gain"), GainInput("rf_gain", "Device gain"),
NumberInput( NumberInput(
@ -491,10 +488,9 @@ class SdrDeviceDescription(object):
append="Hz", append="Hz",
infotext="Use this when the actual receiving frequency differs from the frequency to be tuned on the" infotext="Use this when the actual receiving frequency differs from the frequency to be tuned on the"
+ " device. <br/> Formula: Center frequency + oscillator offset = sdr tune frequency", + " device. <br/> Formula: Center frequency + oscillator offset = sdr tune frequency",
converter=OptionalConverter(),
), ),
NumberInput("waterfall_min_level", "Lowest waterfall level", append="dBFS", converter=OptionalConverter()), NumberInput("waterfall_min_level", "Lowest waterfall level", append="dBFS"),
NumberInput("waterfall_max_level", "Highest waterfall level", append="dBFS", converter=OptionalConverter()), NumberInput("waterfall_max_level", "Highest waterfall level", append="dBFS"),
# TODO `schedule` # TODO `schedule`
] ]

View File

@ -1,7 +1,6 @@
from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription
from owrx.form import Input, CheckboxInput from owrx.form import Input, CheckboxInput
from owrx.form.device import BiasTeeInput from owrx.form.device import BiasTeeInput
from owrx.form.converter import OptionalConverter
from typing import List from typing import List
@ -29,7 +28,6 @@ class AirspyDeviceDescription(SoapyConnectorDeviceDescription):
"Enable bit-packing", "Enable bit-packing",
infotext="Packs two 12-bit samples into 3 bytes." infotext="Packs two 12-bit samples into 3 bytes."
+ " Lowers USB bandwidth consumption, increases CPU load", + " Lowers USB bandwidth consumption, increases CPU load",
converter=OptionalConverter(defaultFormValue=False),
), ),
] ]

View File

@ -4,7 +4,6 @@ import socket
from owrx.command import Flag, Option from owrx.command import Flag, Option
from typing import List from typing import List
from owrx.form import Input, NumberInput, CheckboxInput from owrx.form import Input, NumberInput, CheckboxInput
from owrx.form.converter import OptionalConverter, IntConverter
import logging import logging
@ -83,13 +82,11 @@ class ConnectorDeviceDescription(SdrDeviceDescription):
infotext="Activate an rtl_tcp compatible interface on the port number specified.<br />" infotext="Activate an rtl_tcp compatible interface on the port number specified.<br />"
+ "Note: Port is only available on the local machine, not on the network.<br />" + "Note: Port is only available on the local machine, not on the network.<br />"
+ "Note: IQ data may be degraded by the downsampling process to 8 bits.", + "Note: IQ data may be degraded by the downsampling process to 8 bits.",
converter=OptionalConverter(IntConverter()),
), ),
CheckboxInput( CheckboxInput(
"iqswap", "iqswap",
"Swap I and Q channels", "Swap I and Q channels",
infotext="Swapping inverts the spectrum, so this is useful in combination with an inverting mixer", infotext="Swapping inverts the spectrum, so this is useful in combination with an inverting mixer",
converter=OptionalConverter(defaultFormValue=False),
), ),
] ]

View File

@ -2,7 +2,6 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
from owrx.command import Flag, Option from owrx.command import Flag, Option
from typing import List from typing import List
from owrx.form import Input, TextInput from owrx.form import Input, TextInput
from owrx.form.converter import OptionalConverter
from owrx.form.device import BiasTeeInput, DirectSamplingInput from owrx.form.device import BiasTeeInput, DirectSamplingInput
@ -23,10 +22,9 @@ class RtlSdrDeviceDescription(ConnectorDeviceDescription):
"device", "device",
"Device identifier", "Device identifier",
infotext="Device serial number or index", infotext="Device serial number or index",
converter=OptionalConverter(),
), ),
BiasTeeInput(), BiasTeeInput(),
DirectSamplingInput() DirectSamplingInput(),
] ]
def getOptionalKeys(self): def getOptionalKeys(self):

View File

@ -2,7 +2,6 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
from owrx.command import Argument, Flag, Option from owrx.command import Argument, Flag, Option
from owrx.form import Input, DropdownInput, DropdownEnum, CheckboxInput from owrx.form import Input, DropdownInput, DropdownEnum, CheckboxInput
from owrx.form.device import RemoteInput from owrx.form.device import RemoteInput
from owrx.form.converter import OptionalConverter
from typing import List from typing import List
@ -42,10 +41,11 @@ class RundsDeviceDescription(ConnectorDeviceDescription):
return super().getInputs() + [ return super().getInputs() + [
RemoteInput(), RemoteInput(),
DropdownInput("protocol", "Protocol", ProtocolOptions), DropdownInput("protocol", "Protocol", ProtocolOptions),
CheckboxInput( CheckboxInput("long", "Use 32-bit sample size (LONG)"),
"long", "", "Use 32-bit sample size (LONG)", converter=OptionalConverter(defaultFormValue=False)
),
] ]
def getMandatoryKeys(self): def getMandatoryKeys(self):
return super().getMandatoryKeys() + ["device"] return super().getMandatoryKeys() + ["device"]
def getOptionalKeys(self):
return super().getOptionalKeys() + ["protocol", "long"]

View File

@ -1,7 +1,6 @@
from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription
from owrx.form import Input, CheckboxInput, DropdownInput, DropdownEnum from owrx.form import Input, CheckboxInput, DropdownInput, DropdownEnum
from owrx.form.device import BiasTeeInput from owrx.form.device import BiasTeeInput
from owrx.form.converter import OptionalConverter, EnumConverter
from typing import List from typing import List
@ -43,20 +42,15 @@ class SdrplayDeviceDescription(SoapyConnectorDeviceDescription):
CheckboxInput( CheckboxInput(
"rf_notch", "rf_notch",
"Enable RF notch filter", "Enable RF notch filter",
converter=OptionalConverter(defaultFormValue=True),
), ),
CheckboxInput( CheckboxInput(
"dab_notch", "dab_notch",
"Enable DAB notch filter", "Enable DAB notch filter",
converter=OptionalConverter(defaultFormValue=True),
), ),
DropdownInput( DropdownInput(
"if_mode", "if_mode",
"IF Mode", "IF Mode",
IfModeOptions, IfModeOptions,
converter=OptionalConverter(
EnumConverter(IfModeOptions), defaultFormValue=IfModeOptions.IFMODE_ZERO_IF.name
),
), ),
] ]

View File

@ -3,7 +3,6 @@ from owrx.command import Option
from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
from typing import List from typing import List
from owrx.form import Input, TextInput from owrx.form import Input, TextInput
from owrx.form.converter import OptionalConverter
from owrx.form.device import GainInput from owrx.form.device import GainInput
from owrx.soapy import SoapySettings from owrx.soapy import SoapySettings
@ -89,18 +88,13 @@ class SoapyConnectorDeviceDescription(ConnectorDeviceDescription):
"device", "device",
"Device Identifier", "Device Identifier",
infotext='SoapySDR device identifier string (example: "serial=123456789")', infotext='SoapySDR device identifier string (example: "serial=123456789")',
converter=OptionalConverter()
), ),
GainInput( GainInput(
"rf_gain", "rf_gain",
"Device Gain", "Device Gain",
gain_stages=self.getGainStages(), gain_stages=self.getGainStages(),
), ),
TextInput( TextInput("antenna", "Antenna"),
"antenna",
"Antenna",
converter=OptionalConverter(),
),
] ]
def getOptionalKeys(self): def getOptionalKeys(self):