mirror of
https://github.com/caronc/apprise.git
synced 2025-01-22 13:59:03 +01:00
Added delay= switch to aprs:// plugin (#1107)
This commit is contained in:
parent
0d1f3d88af
commit
7a985ea787
@ -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"]):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user