mirror of https://github.com/caronc/apprise
Bark - add critical level alert plus ?volume= argument (#1239)
parent
c49e2127c2
commit
e9020e6f74
|
@ -89,11 +89,14 @@ class NotifyBarkLevel:
|
||||||
|
|
||||||
PASSIVE = 'passive'
|
PASSIVE = 'passive'
|
||||||
|
|
||||||
|
CRITICAL = 'critical'
|
||||||
|
|
||||||
|
|
||||||
BARK_LEVELS = (
|
BARK_LEVELS = (
|
||||||
NotifyBarkLevel.ACTIVE,
|
NotifyBarkLevel.ACTIVE,
|
||||||
NotifyBarkLevel.TIME_SENSITIVE,
|
NotifyBarkLevel.TIME_SENSITIVE,
|
||||||
NotifyBarkLevel.PASSIVE,
|
NotifyBarkLevel.PASSIVE,
|
||||||
|
NotifyBarkLevel.CRITICAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,6 +181,12 @@ class NotifyBark(NotifyBase):
|
||||||
'type': 'choice:string',
|
'type': 'choice:string',
|
||||||
'values': BARK_LEVELS,
|
'values': BARK_LEVELS,
|
||||||
},
|
},
|
||||||
|
'volume': {
|
||||||
|
'name': _('Volume'),
|
||||||
|
'type': 'int',
|
||||||
|
'min': 0,
|
||||||
|
'max': 10,
|
||||||
|
},
|
||||||
'click': {
|
'click': {
|
||||||
'name': _('Click'),
|
'name': _('Click'),
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
|
@ -205,7 +214,7 @@ class NotifyBark(NotifyBase):
|
||||||
|
|
||||||
def __init__(self, targets=None, include_image=True, sound=None,
|
def __init__(self, targets=None, include_image=True, sound=None,
|
||||||
category=None, group=None, level=None, click=None,
|
category=None, group=None, level=None, click=None,
|
||||||
badge=None, **kwargs):
|
badge=None, volume=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize Notify Bark Object
|
Initialize Notify Bark Object
|
||||||
"""
|
"""
|
||||||
|
@ -260,6 +269,19 @@ class NotifyBark(NotifyBase):
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'The specified Bark sound ({}) was not found ', sound)
|
'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
|
# Level
|
||||||
self.level = None if not level else next(
|
self.level = None if not level else next(
|
||||||
(f for f in BARK_LEVELS if f[0] == level[0]), None)
|
(f for f in BARK_LEVELS if f[0] == level[0]), None)
|
||||||
|
@ -330,6 +352,9 @@ class NotifyBark(NotifyBase):
|
||||||
if self.group:
|
if self.group:
|
||||||
payload['group'] = self.group
|
payload['group'] = self.group
|
||||||
|
|
||||||
|
if self.volume:
|
||||||
|
payload['volume'] = self.volume
|
||||||
|
|
||||||
auth = None
|
auth = None
|
||||||
if self.user:
|
if self.user:
|
||||||
auth = (self.user, self.password)
|
auth = (self.user, self.password)
|
||||||
|
@ -429,6 +454,9 @@ class NotifyBark(NotifyBase):
|
||||||
if self.level:
|
if self.level:
|
||||||
params['level'] = self.level
|
params['level'] = self.level
|
||||||
|
|
||||||
|
if self.volume:
|
||||||
|
params['volume'] = str(self.volume)
|
||||||
|
|
||||||
if self.category:
|
if self.category:
|
||||||
params['category'] = self.category
|
params['category'] = self.category
|
||||||
|
|
||||||
|
@ -502,6 +530,11 @@ class NotifyBark(NotifyBase):
|
||||||
results['badge'] = NotifyBark.unquote(
|
results['badge'] = NotifyBark.unquote(
|
||||||
results['qsd']['badge'].strip())
|
results['qsd']['badge'].strip())
|
||||||
|
|
||||||
|
# Volume
|
||||||
|
if 'volume' in results['qsd'] and results['qsd']['volume']:
|
||||||
|
results['volume'] = NotifyBark.unquote(
|
||||||
|
results['qsd']['volume'].strip())
|
||||||
|
|
||||||
# Level
|
# Level
|
||||||
if 'level' in results['qsd'] and results['qsd']['level']:
|
if 'level' in results['qsd'] and results['qsd']['level']:
|
||||||
results['level'] = NotifyBark.unquote(
|
results['level'] = NotifyBark.unquote(
|
||||||
|
|
|
@ -117,6 +117,30 @@ apprise_url_tests = (
|
||||||
# active level
|
# active level
|
||||||
'instance': NotifyBark,
|
'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/', {
|
('bark://user:pass@192.168.0.5:8086/device_key/device_key2/', {
|
||||||
# Everything is okay
|
# Everything is okay
|
||||||
'instance': NotifyBark,
|
'instance': NotifyBark,
|
||||||
|
|
Loading…
Reference in New Issue