Browse Source

Added sound support to Pushover Notifications; refs #113

pull/112/head
Chris Caron 6 years ago committed by GitHub
parent
commit
4c375c8a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 72
      apprise/plugins/NotifyPushover.py
  2. 4
      test/test_rest_plugins.py

72
apprise/plugins/NotifyPushover.py

@ -24,6 +24,7 @@
# THE SOFTWARE. # THE SOFTWARE.
import re import re
import six
import requests import requests
from .NotifyBase import NotifyBase from .NotifyBase import NotifyBase
@ -52,6 +53,57 @@ class PushoverPriority(object):
EMERGENCY = 2 EMERGENCY = 2
# Sounds
class PushoverSound(object):
PUSHOVER = 'pushover'
BIKE = 'bike'
BUGLE = 'bugle'
CASHREGISTER = 'cashregister'
CLASSICAL = 'classical'
COSMIC = 'cosmic'
FALLING = 'falling'
GAMELAN = 'gamelan'
INCOMING = 'incoming'
INTERMISSION = 'intermission'
MAGIC = 'magic'
MECHANICAL = 'mechanical'
PIANOBAR = 'pianobar'
SIREN = 'siren'
SPACEALARM = 'spacealarm'
TUGBOAT = 'tugboat'
ALIEN = 'alien'
CLIMB = 'climb'
PERSISTENT = 'persistent'
ECHO = 'echo'
UPDOWN = 'updown'
NONE = 'none'
PUSHOVER_SOUNDS = (
PushoverSound.PUSHOVER,
PushoverSound.BIKE,
PushoverSound.BUGLE,
PushoverSound.CASHREGISTER,
PushoverSound.CLASSICAL,
PushoverSound.COSMIC,
PushoverSound.FALLING,
PushoverSound.GAMELAN,
PushoverSound.INCOMING,
PushoverSound.INTERMISSION,
PushoverSound.MAGIC,
PushoverSound.MECHANICAL,
PushoverSound.PIANOBAR,
PushoverSound.SIREN,
PushoverSound.SPACEALARM,
PushoverSound.TUGBOAT,
PushoverSound.ALIEN,
PushoverSound.CLIMB,
PushoverSound.PERSISTENT,
PushoverSound.ECHO,
PushoverSound.UPDOWN,
PushoverSound.NONE,
)
PUSHOVER_PRIORITIES = ( PUSHOVER_PRIORITIES = (
PushoverPriority.LOW, PushoverPriority.LOW,
PushoverPriority.MODERATE, PushoverPriority.MODERATE,
@ -89,7 +141,11 @@ class NotifyPushover(NotifyBase):
# The maximum allowable characters allowed in the body per message # The maximum allowable characters allowed in the body per message
body_maxlen = 512 body_maxlen = 512
def __init__(self, token, targets=None, priority=None, **kwargs): # Default Pushover sound
default_pushover_sound = PushoverSound.PUSHOVER
def __init__(self, token, targets=None, priority=None, sound=None,
**kwargs):
""" """
Initialize Pushover Object Initialize Pushover Object
""" """
@ -114,6 +170,14 @@ class NotifyPushover(NotifyBase):
if len(self.targets) == 0: if len(self.targets) == 0:
self.targets = (PUSHOVER_SEND_TO_ALL, ) self.targets = (PUSHOVER_SEND_TO_ALL, )
# Setup our sound
self.sound = NotifyPushover.default_pushover_sound \
if not isinstance(sound, six.string_types) else sound.lower()
if self.sound and self.sound not in PUSHOVER_SOUNDS:
msg = 'The sound specified ({}) is invalid.'.format(sound)
self.logger.warning(msg)
raise TypeError(msg)
# The Priority of the message # The Priority of the message
if priority not in PUSHOVER_PRIORITIES: if priority not in PUSHOVER_PRIORITIES:
self.priority = PushoverPriority.NORMAL self.priority = PushoverPriority.NORMAL
@ -167,6 +231,7 @@ class NotifyPushover(NotifyBase):
'title': title, 'title': title,
'message': body, 'message': body,
'device': device, 'device': device,
'sound': self.sound,
} }
self.logger.debug('Pushover POST URL: %s (cert_verify=%r)' % ( self.logger.debug('Pushover POST URL: %s (cert_verify=%r)' % (
@ -297,6 +362,11 @@ class NotifyPushover(NotifyBase):
# Retrieve all of our targets # Retrieve all of our targets
results['targets'] = NotifyPushover.split_path(results['fullpath']) results['targets'] = NotifyPushover.split_path(results['fullpath'])
# Get the sound
if 'sound' in results['qsd'] and len(results['qsd']['sound']):
results['sound'] = \
NotifyPushover.unquote(results['qsd']['sound'])
# The 'to' makes it easier to use yaml configuration # The 'to' makes it easier to use yaml configuration
if 'to' in results['qsd'] and len(results['qsd']['to']): if 'to' in results['qsd'] and len(results['qsd']['to']):
results['targets'] += \ results['targets'] += \

4
test/test_rest_plugins.py

@ -1349,6 +1349,10 @@ TEST_URLS = (
('pover://%s@%s' % ('u' * 30, 'a' * 24), { ('pover://%s@%s' % ('u' * 30, 'a' * 24), {
'instance': TypeError, 'instance': TypeError,
}), }),
# APIKey + invalid sound setting
('pover://%s@%s?sound=invalid' % ('u' * 30, 'a' * 30), {
'instance': TypeError,
}),
# APIKey + Valid User # APIKey + Valid User
('pover://%s@%s' % ('u' * 30, 'a' * 30), { ('pover://%s@%s' % ('u' * 30, 'a' * 30), {
'instance': plugins.NotifyPushover, 'instance': plugins.NotifyPushover,

Loading…
Cancel
Save