Skip to content

Commit

Permalink
Bark - add critical level alert plus ?volume= argument (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
pb8DvwQkfRR authored Nov 30, 2024
1 parent c49e212 commit e9020e6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
35 changes: 34 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': 0,
'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,19 @@ def __init__(self, targets=None, include_image=True, sound=None,
self.logger.warning(
'The specified Bark sound ({}) was not found ', sound)

# Volume
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)

# 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 +352,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 +454,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 +530,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
24 changes: 24 additions & 0 deletions test/test_plugin_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=-1', {
# volume < 0
'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,
Expand Down

0 comments on commit e9020e6

Please sign in to comment.