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

Bark - add critical level alert plus ?volume= argument #1239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': 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,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 (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 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 +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
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