A bugfix for pushbullet (#9237)

* Bug fix for pushbullet
This commit is contained in:
Daniel Høyer Iversen 2017-08-31 14:19:33 +02:00 committed by GitHub
parent e22ec28bce
commit d816ff26ad

View File

@ -129,17 +129,21 @@ class PushBulletNotificationService(BaseNotificationService):
def _push_data(self, title, message, data, pusher, tname=None): def _push_data(self, title, message, data, pusher, tname=None):
from pushbullet import PushError from pushbullet import PushError
from pushbullet import Device if data is None:
data = {}
url = data.get(ATTR_URL) url = data.get(ATTR_URL)
filepath = data.get(ATTR_FILE) filepath = data.get(ATTR_FILE)
file_url = data.get(ATTR_FILE_URL) file_url = data.get(ATTR_FILE_URL)
try: try:
if url: if url:
if isinstance(pusher, Device): if tname:
pusher.push_link(title, url, body=message)
else:
pusher.push_link(title, url, body=message, email=tname) pusher.push_link(title, url, body=message, email=tname)
elif filepath and self.hass.config.is_allowed_path(filepath): else:
pusher.push_link(title, url, body=message)
elif filepath:
if not self.hass.config.is_allowed_path(filepath):
_LOGGER.error("Filepath is not valid or allowed.")
return
with open(filepath, "rb") as fileh: with open(filepath, "rb") as fileh:
filedata = self.pushbullet.upload_file(fileh, filepath) filedata = self.pushbullet.upload_file(fileh, filepath)
if filedata.get('file_type') == 'application/x-empty': if filedata.get('file_type') == 'application/x-empty':
@ -154,9 +158,9 @@ class PushBulletNotificationService(BaseNotificationService):
file_url=file_url, file_url=file_url,
file_type=mimetypes.guess_type(file_url)[0]) file_type=mimetypes.guess_type(file_url)[0])
else: else:
if isinstance(pusher, Device): if tname:
pusher.push_note(title, message)
else:
pusher.push_note(title, message, email=tname) pusher.push_note(title, message, email=tname)
else:
pusher.push_note(title, message)
except PushError as err: except PushError as err:
_LOGGER.error("Notify failed: %s", err) _LOGGER.error("Notify failed: %s", err)