Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 38 additions & 1 deletion apprise/plugins/NotifyAprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
"""
Expand Down Expand Up @@ -272,6 +279,28 @@ def __init__(self, targets=None, locale=None, **kwargs):
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"] \
Expand Down Expand Up @@ -674,6 +703,10 @@ def url(self, privacy=False, *args, **kwargs):
# 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))

Expand Down Expand Up @@ -727,6 +760,10 @@ def parse_url(url):
# 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"]):
Expand Down
16 changes: 16 additions & 0 deletions test/test_plugin_aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down