Browse Source

Notifications for Pushbullet channels

Making it possible to send notifications not only to devices, but also to channels. It is very useful when one wants to send notifications to other pushbullet users, i.e. flatmates. A flatmate can then subscribe to your channel and receive notifications on his/her devices. 

For some reason, a POST request sending notification to a channel returns an empty dictionary, so no counting of successful requests is performed for those notifications.
pull/5051/head
Krzysztof Jagiełło 10 years ago
parent
commit
fc72de5228
  1. 27
      couchpotato/core/notifications/pushbullet.py

27
couchpotato/core/notifications/pushbullet.py

@ -19,14 +19,8 @@ class Pushbullet(Notification):
def notify(self, message = '', data = None, listener = None): def notify(self, message = '', data = None, listener = None):
if not data: data = {} if not data: data = {}
devices = self.getDevices()
if devices is None:
return False
# Get all the device IDs linked to this user # Get all the device IDs linked to this user
if not len(devices): devices = self.getDevices() or [None]
devices = [None]
successful = 0 successful = 0
for device in devices: for device in devices:
response = self.request( response = self.request(
@ -43,11 +37,24 @@ class Pushbullet(Notification):
else: else:
log.error('Unable to push notification to Pushbullet device with ID %s' % device) log.error('Unable to push notification to Pushbullet device with ID %s' % device)
for channel in self.getChannels():
response = self.request(
'pushes',
cache = False,
channel_tag = channel,
type = 'note',
title = self.default_title,
body = toUnicode(message)
)
return successful == len(devices) return successful == len(devices)
def getDevices(self): def getDevices(self):
return splitString(self.conf('devices')) return splitString(self.conf('devices'))
def getChannels(self):
return splitString(self.conf('channels'))
def request(self, method, cache = True, **kwargs): def request(self, method, cache = True, **kwargs):
try: try:
base64string = base64.encodestring('%s:' % self.conf('api_key'))[:-1] base64string = base64.encodestring('%s:' % self.conf('api_key'))[:-1]
@ -94,6 +101,12 @@ config = [{
'description': 'IDs of devices to send notifications to, empty = all devices' 'description': 'IDs of devices to send notifications to, empty = all devices'
}, },
{ {
'name': 'channels',
'default': '',
'advanced': True,
'description': 'IDs of channels to send notifications to, empty = no channels'
},
{
'name': 'on_snatch', 'name': 'on_snatch',
'default': 0, 'default': 0,
'type': 'bool', 'type': 'bool',

Loading…
Cancel
Save