Don't filter inputs, add a validator for RF Gain
This commit is contained in:
parent
e37bc0573d
commit
87b9a52fcb
@ -107,8 +107,8 @@ class TextInput(Input):
|
|||||||
|
|
||||||
|
|
||||||
class NumberInput(Input):
|
class NumberInput(Input):
|
||||||
def __init__(self, id, label, infotext=None, append="", converter: Converter = None):
|
def __init__(self, id, label, infotext=None, append="", converter: Converter = None, validator: Validator = None):
|
||||||
super().__init__(id, label, infotext, converter=converter)
|
super().__init__(id, label, infotext, converter=converter, validator=validator)
|
||||||
self.step = None
|
self.step = None
|
||||||
self.append = append
|
self.append = append
|
||||||
|
|
||||||
|
@ -12,3 +12,15 @@ class RequiredValidator(Validator):
|
|||||||
def validate(self, key, value):
|
def validate(self, key, value):
|
||||||
if value is None or value == "":
|
if value is None or value == "":
|
||||||
raise ValidationError(key, "Field is required")
|
raise ValidationError(key, "Field is required")
|
||||||
|
|
||||||
|
class RangeValidator(Validator):
|
||||||
|
def __init__(self, minValue, maxValue):
|
||||||
|
self.minValue = minValue
|
||||||
|
self.maxValue = maxValue
|
||||||
|
|
||||||
|
def validate(self, key, value):
|
||||||
|
if value is None or value == "":
|
||||||
|
return # Ignore empty values
|
||||||
|
n = float(value)
|
||||||
|
if n < self.minValue or n > self.maxValue:
|
||||||
|
raise ValidationError(key, 'Value must be between %s and %s'%(self.minValue, self.maxValue))
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
|
from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
|
||||||
from owrx.command import Option
|
from owrx.command import Option
|
||||||
|
from owrx.form.error import ValidationError
|
||||||
from owrx.form.input import Input, NumberInput, TextInput
|
from owrx.form.input import Input, NumberInput, TextInput
|
||||||
|
from owrx.form.input.validator import RangeValidator
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# In order to use an HPSDR radio, you must install hpsdrconnector from https://github.com/jancona/hpsdrconnector
|
# In order to use an HPSDR radio, you must install hpsdrconnector from https://github.com/jancona/hpsdrconnector
|
||||||
@ -47,9 +49,9 @@ class HpsdrDeviceDescription(ConnectorDeviceDescription):
|
|||||||
return "HPSDR devices (Hermes / Hermes Lite 2 / Red Pitaya)"
|
return "HPSDR devices (Hermes / Hermes Lite 2 / Red Pitaya)"
|
||||||
|
|
||||||
def getInputs(self) -> List[Input]:
|
def getInputs(self) -> List[Input]:
|
||||||
return list(filter(lambda x : x.id != "rf_gain", super().getInputs())) + [
|
return super().getInputs() + [
|
||||||
RemoteInput(), NumberInput("rf_gain", "LNA Gain",
|
RemoteInput(),
|
||||||
"LNA gain between 0 (-12dB) and 60 (48dB)"),
|
NumberInput("rf_gain", "LNA Gain", "LNA gain between 0 (-12dB) and 60 (48dB)", validator=RangeValidator(0, 60)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def getDeviceOptionalKeys(self):
|
def getDeviceOptionalKeys(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user