Added delay= switch to aprs:// plugin (#1107)

This commit is contained in:
Chris Caron 2024-04-13 19:23:50 -04:00 committed by GitHub
parent 0d1f3d88af
commit 7a985ea787
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 1 deletions

View File

@ -203,6 +203,13 @@ class NotifyAprs(NotifyBase):
"type": "string",
"map_to": "targets",
},
"delay": {
"name": _("Resend Delay"),
"type": "float",
"min": 0.0,
"max": 5.0,
"default": 0.0,
},
"locale": {
"name": _("Locale"),
"type": "choice:string",
@ -212,7 +219,7 @@ class NotifyAprs(NotifyBase):
}
)
def __init__(self, targets=None, locale=None, **kwargs):
def __init__(self, targets=None, locale=None, delay=None, **kwargs):
"""
Initialize APRS Object
"""
@ -272,6 +279,28 @@ class NotifyAprs(NotifyBase):
self.logger.warning(msg)
raise TypeError(msg)
# Update our delay
if delay is None:
self.delay = NotifyAprs.template_args["delay"]["default"]
else:
try:
self.delay = float(delay)
if self.delay < NotifyAprs.template_args["delay"]["min"]:
raise ValueError()
elif self.delay >= NotifyAprs.template_args["delay"]["max"]:
raise ValueError()
except (TypeError, ValueError):
msg = "Unsupported APRS-IS delay ({}) specified. ".format(
delay)
self.logger.warning(msg)
raise TypeError(msg)
# Bump up our request_rate
self.request_rate_per_sec += self.delay
# Set the transmitter group
self.locale = \
NotifyAprs.template_args["locale"]["default"] \
@ -674,6 +703,10 @@ class NotifyAprs(NotifyBase):
# Store our locale if not default
params['locale'] = self.locale
if self.delay != NotifyAprs.template_args["delay"]["default"]:
# Store our locale if not default
params['delay'] = "{:.2f}".format(self.delay)
# Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
@ -727,6 +760,10 @@ class NotifyAprs(NotifyBase):
# All entries after the hostname are additional targets
results["targets"].extend(NotifyAprs.split_path(results["fullpath"]))
# Get Delay (if set)
if 'delay' in results['qsd'] and len(results['qsd']['delay']):
results['delay'] = NotifyAprs.unquote(results['qsd']['delay'])
# Support the 'to' variable so that we can support rooms this way too
# The 'to' makes it easier to use yaml configuration
if "to" in results["qsd"] and len(results["qsd"]["to"]):

View File

@ -87,6 +87,22 @@ def test_plugin_aprs_urls(mock_create_connection):
'aprs://DF1JSL-15:****@D...C?')
assert instance.notify('test') is True
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC?delay=3.0")
assert isinstance(instance, NotifyAprs)
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC?delay=2")
assert isinstance(instance, NotifyAprs)
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC?delay=-3.0")
assert instance is None
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC?delay=40.0")
assert instance is None
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC?delay=invalid")
assert instance is None
instance = apprise.Apprise.instantiate(
"aprs://DF1JSL-15:12345@DF1ABC/DF1DEF")
assert isinstance(instance, NotifyAprs)