Skip to content

Commit

Permalink
bark:// add critical level alart
Browse files Browse the repository at this point in the history
  • Loading branch information
pb8DvwQkfRR authored Nov 16, 2024
1 parent f37dfbf commit c33984c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
34 changes: 33 additions & 1 deletion apprise/plugins/bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ class NotifyBarkLevel:

PASSIVE = 'passive'

CRITICAL = 'critical'


BARK_LEVELS = (
NotifyBarkLevel.ACTIVE,
NotifyBarkLevel.TIME_SENSITIVE,
NotifyBarkLevel.PASSIVE,
NotifyBarkLevel.CRITICAL,
)


Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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()

Check warning on line 276 in apprise/plugins/bark.py

View check run for this annotation

Codecov / codecov/patch

apprise/plugins/bark.py#L276

Added line #L276 was not covered by tests
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions test/test_plugin_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
# 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://user:[email protected]:8086/device_key/device_key2/', {
# Everything is okay
'instance': NotifyBark,
Expand Down

0 comments on commit c33984c

Please sign in to comment.