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

refactor pushbullet #9125

Merged
merged 2 commits into from Aug 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 14 additions & 19 deletions homeassistant/components/notify/pushbullet.py
Expand Up @@ -89,15 +89,7 @@ def send_message(self, message=None, **kwargs):

if not targets:
# Backward compatibility, notify all devices in own account
if url:
self.pushbullet.push_link(title, url, body=message)
elif filepath and self.hass.config.is_allowed_path(filepath):
with open(filepath, "rb") as fileh:
filedata = self.pushbullet.upload_file(fileh, filepath)
self.pushbullet.push_file(title=title, body=message,
**filedata)
else:
self.pushbullet.push_note(title, message)
self._push_data(filepath, message, title, url)
_LOGGER.info("Sent notification to self")
return

Expand All @@ -112,16 +104,7 @@ def send_message(self, message=None, **kwargs):
# Target is email, send directly, don't use a target object
# This also seems works to send to all devices in own account
if ttype == 'email':
if url:
self.pushbullet.push_link(
title, url, body=message, email=tname)
if filepath and self.hass.config.is_allowed_path(filepath):
with open(filepath, "rb") as fileh:
filedata = self.pushbullet.upload_file(fileh, filepath)
self.pushbullet.push_file(title=title, body=message,
**filedata)
else:
self.pushbullet.push_note(title, message, email=tname)
self._push_data(filepath, message, title, url, tname)
_LOGGER.info("Sent notification to email %s", tname)
continue

Expand Down Expand Up @@ -152,3 +135,15 @@ def send_message(self, message=None, **kwargs):
except self.pushbullet.errors.PushError:
_LOGGER.error("Notify failed to: %s/%s", ttype, tname)
continue

def _push_data(self, filepath, message, title, url, tname=None):
if url:
self.pushbullet.push_link(
title, url, body=message, email=tname)
elif filepath and self.hass.config.is_allowed_path(filepath):
with open(filepath, "rb") as fileh:
filedata = self.pushbullet.upload_file(fileh, filepath)
self.pushbullet.push_file(title=title, body=message,
**filedata)
else:
self.pushbullet.push_note(title, message, email=tname)