diff --git a/apprise/plugins/NotifyAprs.py b/apprise/plugins/NotifyAprs.py index c56982a7..5d8c3c10 100644 --- a/apprise/plugins/NotifyAprs.py +++ b/apprise/plugins/NotifyAprs.py @@ -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"]): diff --git a/test/test_plugin_aprs.py b/test/test_plugin_aprs.py index eeac51f0..f61b154c 100644 --- a/test/test_plugin_aprs.py +++ b/test/test_plugin_aprs.py @@ -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)