Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions homeassistant/components/notify/pushbullet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
PushBullet platform for notify component.
Pushbullet platform for notify component.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.pushbullet/
Expand All @@ -26,7 +26,7 @@

# pylint: disable=unused-argument
def get_service(hass, config, discovery_info=None):
"""Get the PushBullet notification service."""
"""Get the Pushbullet notification service."""
from pushbullet import PushBullet
from pushbullet import InvalidKeyError

Expand All @@ -53,9 +53,9 @@ def __init__(self, pb):
def refresh(self):
"""Refresh devices, contacts, etc.

pbtargets stores all targets available from this pushbullet instance
into a dict. These are PB objects!. It sacrifices a bit of memory
for faster processing at send_message.
pbtargets stores all targets available from this Pushbullet instance
into a dict. These are Pushbullet objects!. It sacrifices a bit of
memory for faster processing at send_message.

As of sept 2015, contacts were replaced by chats. This is not
implemented in the module yet.
Expand All @@ -73,7 +73,7 @@ def send_message(self, message=None, **kwargs):
"""Send a message to a specified target.

If no target specified, a 'normal' push will be sent to all devices
linked to the PB account.
linked to the Pushbullet account.
Email is special, these are assumed to always exist. We use a special
call which doesn't require a push object.
"""
Expand All @@ -86,37 +86,37 @@ def send_message(self, message=None, **kwargs):
refreshed = False

if not targets:
# Backward compatebility, notify all devices in own account
# Backward compatibility, notify all devices in own account
if url:
self.pushbullet.push_link(title, url, body=message)
else:
self.pushbullet.push_note(title, message)
_LOGGER.info('Sent notification to self')
_LOGGER.info("Sent notification to self")
return

# Main loop, Process all targets specified
# Main loop, process all targets specified
for target in targets:
try:
ttype, tname = target.split('/', 1)
except ValueError:
_LOGGER.error('Invalid target syntax: %s', target)
_LOGGER.error("Invalid target syntax: %s", target)
continue

# 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)
self.pushbullet.push_link(
title, url, body=message, email=tname)
else:
self.pushbullet.push_note(title, message, email=tname)
_LOGGER.info('Sent notification to email %s', tname)
_LOGGER.info("Sent notification to email %s", tname)
continue

# Refresh if name not found. While awaiting periodic refresh
# solution in component, poor mans refresh ;)
if ttype not in self.pbtargets:
_LOGGER.error('Invalid target syntax: %s', target)
_LOGGER.error("Invalid target syntax: %s", target)
continue

tname = tname.lower()
Expand All @@ -129,14 +129,14 @@ def send_message(self, message=None, **kwargs):
# name. Dict pbtargets has all *actual* targets.
try:
if url:
self.pbtargets[ttype][tname].push_link(title, url,
body=message)
self.pbtargets[ttype][tname].push_link(
title, url, body=message)
else:
self.pbtargets[ttype][tname].push_note(title, message)
_LOGGER.info('Sent notification to %s/%s', ttype, tname)
_LOGGER.info("Sent notification to %s/%s", ttype, tname)
except KeyError:
_LOGGER.error('No such target: %s/%s', ttype, tname)
_LOGGER.error("No such target: %s/%s", ttype, tname)
continue
except self.pushbullet.errors.PushError:
_LOGGER.error('Notify failed to: %s/%s', ttype, tname)
_LOGGER.error("Notify failed to: %s/%s", ttype, tname)
continue
15 changes: 7 additions & 8 deletions homeassistant/components/notify/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def _send_email(self, msg):
msg.as_string())
break
except smtplib.SMTPException:
_LOGGER.warning('SMTPException sending mail: '
'retrying connection')
_LOGGER.warning(
"SMTPException sending mail: retrying connection")
mail.quit()
mail = self.connect()

Expand All @@ -166,13 +166,13 @@ def _send_email(self, msg):

def _build_text_msg(message):
"""Build plaintext email."""
_LOGGER.debug('Building plain text email')
_LOGGER.debug("Building plain text email")
return MIMEText(message)


def _build_multipart_msg(message, images):
"""Build Multipart message with in-line images."""
_LOGGER.debug('Building multipart email with embedded attachment(s)')
_LOGGER.debug("Building multipart email with embedded attachment(s)")
msg = MIMEMultipart('related')
msg_alt = MIMEMultipart('alternative')
msg.attach(msg_alt)
Expand All @@ -191,16 +191,15 @@ def _build_multipart_msg(message, images):
msg.attach(attachment)
attachment.add_header('Content-ID', '<{}>'.format(cid))
except TypeError:
_LOGGER.warning('Attachment %s has an unkown MIME type.'
' Falling back to file', atch_name)
_LOGGER.warning("Attachment %s has an unkown MIME type."
" Falling back to file", atch_name)
attachment = MIMEApplication(file_bytes, Name=atch_name)
attachment['Content-Disposition'] = ('attachment; '
'filename="%s"' %
atch_name)
msg.attach(attachment)
except FileNotFoundError:
_LOGGER.warning('Attachment %s not found. Skipping',
atch_name)
_LOGGER.warning("Attachment %s not found. Skipping", atch_name)

body_html = MIMEText(''.join(body_text), 'html')
msg_alt.attach(body_html)
Expand Down