From 0ad5dd81c89584e29de391c8eb37b848995c2d61 Mon Sep 17 00:00:00 2001 From: Q01 <8140841+pb8DvwQkfRR@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:40:53 +0800 Subject: [PATCH 1/3] bark:// add critical level alart Signed-off-by: Q01 <8140841+pb8DvwQkfRR@users.noreply.github.com> --- apprise/plugins/bark.py | 34 +++++++++++++++++++++++++++++++++- test/test_plugin_bark.py | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/apprise/plugins/bark.py b/apprise/plugins/bark.py index e676e0c31..839018e65 100644 --- a/apprise/plugins/bark.py +++ b/apprise/plugins/bark.py @@ -89,11 +89,14 @@ class NotifyBarkLevel: PASSIVE = 'passive' + CRITICAL = 'critical' + BARK_LEVELS = ( NotifyBarkLevel.ACTIVE, NotifyBarkLevel.TIME_SENSITIVE, NotifyBarkLevel.PASSIVE, + NotifyBarkLevel.CRITICAL, ) @@ -178,6 +181,12 @@ class NotifyBark(NotifyBase): 'type': 'choice:string', 'values': BARK_LEVELS, }, + 'volume': { + 'name': _('Volume'), + 'type': 'int', + 'min': 1, + 'max': 10, + }, 'click': { 'name': _('Click'), 'type': 'string', @@ -205,7 +214,7 @@ class NotifyBark(NotifyBase): def __init__(self, targets=None, include_image=True, sound=None, category=None, group=None, level=None, click=None, - badge=None, **kwargs): + badge=None, volume=None, **kwargs): """ Initialize Notify Bark Object """ @@ -260,6 +269,18 @@ def __init__(self, targets=None, include_image=True, sound=None, self.logger.warning( 'The specified Bark sound ({}) was not found ', sound) + # Volume + try: + self.volume = int(volume) if volume is not None else None + if self.volume is not None and not (1 <= self.volume <= 10): + raise ValueError() + except (TypeError, ValueError): + self.volume = None + if volume is not None: + self.logger.warning( + 'The specified Bark volume ({}) is not valid. ' + 'Must be between 1 and 10', volume) + # Level self.level = None if not level else next( (f for f in BARK_LEVELS if f[0] == level[0]), None) @@ -330,6 +351,9 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs): if self.group: payload['group'] = self.group + if self.volume: + payload['volume'] = self.volume + auth = None if self.user: auth = (self.user, self.password) @@ -429,6 +453,9 @@ def url(self, privacy=False, *args, **kwargs): if self.level: params['level'] = self.level + if self.volume: + params['volume'] = str(self.volume) + if self.category: params['category'] = self.category @@ -502,6 +529,11 @@ def parse_url(url): results['badge'] = NotifyBark.unquote( results['qsd']['badge'].strip()) + # Volume + if 'volume' in results['qsd'] and results['qsd']['volume']: + results['volume'] = NotifyBark.unquote( + results['qsd']['volume'].strip()) + # Level if 'level' in results['qsd'] and results['qsd']['level']: results['level'] = NotifyBark.unquote( diff --git a/test/test_plugin_bark.py b/test/test_plugin_bark.py index e8d126361..fc81189bd 100644 --- a/test/test_plugin_bark.py +++ b/test/test_plugin_bark.py @@ -117,6 +117,30 @@ # active level 'instance': NotifyBark, }), + ('bark://192.168.0.6:8081/device_key/?level=critical', { + # critical level + 'instance': NotifyBark, + }), + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=10', { + # critical level with volume 10 + 'instance': NotifyBark, + }), + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=invalid', { + # critical level with invalid volume + 'instance': NotifyBark, + }), + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=11', { + # volume > 10 + 'instance': NotifyBark, + }), + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=0', { + # volume < 1 + 'instance': NotifyBark, + }), + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=', { + # volume None + 'instance': NotifyBark, + }), ('bark://user:pass@192.168.0.5:8086/device_key/device_key2/', { # Everything is okay 'instance': NotifyBark, @@ -150,3 +174,4 @@ def test_plugin_bark_urls(): # Run our general tests AppriseURLTester(tests=apprise_url_tests).run_all() + From e3db9e6008b97efb0e5ffecc2ba988991c54c880 Mon Sep 17 00:00:00 2001 From: Q01 <8140841+pb8DvwQkfRR@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:05:49 +0800 Subject: [PATCH 2/3] bark min volume set to 0 Signed-off-by: Q01 <8140841+pb8DvwQkfRR@users.noreply.github.com> --- apprise/plugins/bark.py | 6 +++--- test/test_plugin_bark.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apprise/plugins/bark.py b/apprise/plugins/bark.py index 839018e65..1653a91a0 100644 --- a/apprise/plugins/bark.py +++ b/apprise/plugins/bark.py @@ -184,7 +184,7 @@ class NotifyBark(NotifyBase): 'volume': { 'name': _('Volume'), 'type': 'int', - 'min': 1, + 'min': 0, 'max': 10, }, 'click': { @@ -272,14 +272,14 @@ def __init__(self, targets=None, include_image=True, sound=None, # Volume try: self.volume = int(volume) if volume is not None else None - if self.volume is not None and not (1 <= self.volume <= 10): + if self.volume is not None and not (0 <= self.volume <= 10): raise ValueError() except (TypeError, ValueError): self.volume = None if volume is not None: self.logger.warning( 'The specified Bark volume ({}) is not valid. ' - 'Must be between 1 and 10', volume) + 'Must be between 0 and 10', volume) # Level self.level = None if not level else next( diff --git a/test/test_plugin_bark.py b/test/test_plugin_bark.py index fc81189bd..9f818c30b 100644 --- a/test/test_plugin_bark.py +++ b/test/test_plugin_bark.py @@ -133,8 +133,8 @@ # volume > 10 'instance': NotifyBark, }), - ('bark://192.168.0.6:8081/device_key/?level=critical&volume=0', { - # volume < 1 + ('bark://192.168.0.6:8081/device_key/?level=critical&volume=-1', { + # volume < 0 'instance': NotifyBark, }), ('bark://192.168.0.6:8081/device_key/?level=critical&volume=', { @@ -174,4 +174,3 @@ def test_plugin_bark_urls(): # Run our general tests AppriseURLTester(tests=apprise_url_tests).run_all() - From 1ce198135506edaff7f54c0e32c8ebfcb4264a55 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 30 Nov 2024 18:40:46 -0500 Subject: [PATCH 3/3] test coverage resolved; volume init reworked --- apprise/plugins/bark.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apprise/plugins/bark.py b/apprise/plugins/bark.py index 1653a91a0..c9f1fedef 100644 --- a/apprise/plugins/bark.py +++ b/apprise/plugins/bark.py @@ -270,13 +270,14 @@ def __init__(self, targets=None, include_image=True, sound=None, 'The specified Bark sound ({}) was not found ', sound) # Volume - try: - self.volume = int(volume) if volume is not None else None - if self.volume is not None and not (0 <= self.volume <= 10): - raise ValueError() - except (TypeError, ValueError): - self.volume = None - if volume is not None: + self.volume = None + if volume is not None: + try: + self.volume = int(volume) if volume is not None else None + if self.volume is not None and not (0 <= self.volume <= 10): + raise ValueError() + + except (TypeError, ValueError): self.logger.warning( 'The specified Bark volume ({}) is not valid. ' 'Must be between 0 and 10', volume)