Fix typo and update name (#6809)

This commit is contained in:
Fabian Affolter 2017-03-27 10:35:27 +02:00 committed by GitHub
parent 84287872bb
commit f4f72e420a
2 changed files with 26 additions and 27 deletions

View file

@ -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 For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.pushbullet/ https://home-assistant.io/components/notify.pushbullet/
@ -26,7 +26,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument # pylint: disable=unused-argument
def get_service(hass, config, discovery_info=None): 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 PushBullet
from pushbullet import InvalidKeyError from pushbullet import InvalidKeyError
@ -53,9 +53,9 @@ class PushBulletNotificationService(BaseNotificationService):
def refresh(self): def refresh(self):
"""Refresh devices, contacts, etc. """Refresh devices, contacts, etc.
pbtargets stores all targets available from this pushbullet instance pbtargets stores all targets available from this Pushbullet instance
into a dict. These are PB objects!. It sacrifices a bit of memory into a dict. These are Pushbullet objects!. It sacrifices a bit of
for faster processing at send_message. memory for faster processing at send_message.
As of sept 2015, contacts were replaced by chats. This is not As of sept 2015, contacts were replaced by chats. This is not
implemented in the module yet. implemented in the module yet.
@ -73,7 +73,7 @@ class PushBulletNotificationService(BaseNotificationService):
"""Send a message to a specified target. """Send a message to a specified target.
If no target specified, a 'normal' push will be sent to all devices 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 Email is special, these are assumed to always exist. We use a special
call which doesn't require a push object. call which doesn't require a push object.
""" """
@ -86,37 +86,37 @@ class PushBulletNotificationService(BaseNotificationService):
refreshed = False refreshed = False
if not targets: if not targets:
# Backward compatebility, notify all devices in own account # Backward compatibility, notify all devices in own account
if url: if url:
self.pushbullet.push_link(title, url, body=message) self.pushbullet.push_link(title, url, body=message)
else: else:
self.pushbullet.push_note(title, message) self.pushbullet.push_note(title, message)
_LOGGER.info('Sent notification to self') _LOGGER.info("Sent notification to self")
return return
# Main loop, Process all targets specified # Main loop, process all targets specified
for target in targets: for target in targets:
try: try:
ttype, tname = target.split('/', 1) ttype, tname = target.split('/', 1)
except ValueError: except ValueError:
_LOGGER.error('Invalid target syntax: %s', target) _LOGGER.error("Invalid target syntax: %s", target)
continue continue
# Target is email, send directly, don't use a target object # Target is email, send directly, don't use a target object
# This also seems works to send to all devices in own account # This also seems works to send to all devices in own account
if ttype == 'email': if ttype == 'email':
if url: if url:
self.pushbullet.push_link(title, url, self.pushbullet.push_link(
body=message, email=tname) title, url, body=message, email=tname)
else: else:
self.pushbullet.push_note(title, message, email=tname) 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 continue
# Refresh if name not found. While awaiting periodic refresh # Refresh if name not found. While awaiting periodic refresh
# solution in component, poor mans refresh ;) # solution in component, poor mans refresh ;)
if ttype not in self.pbtargets: if ttype not in self.pbtargets:
_LOGGER.error('Invalid target syntax: %s', target) _LOGGER.error("Invalid target syntax: %s", target)
continue continue
tname = tname.lower() tname = tname.lower()
@ -129,14 +129,14 @@ class PushBulletNotificationService(BaseNotificationService):
# name. Dict pbtargets has all *actual* targets. # name. Dict pbtargets has all *actual* targets.
try: try:
if url: if url:
self.pbtargets[ttype][tname].push_link(title, url, self.pbtargets[ttype][tname].push_link(
body=message) title, url, body=message)
else: else:
self.pbtargets[ttype][tname].push_note(title, message) 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: except KeyError:
_LOGGER.error('No such target: %s/%s', ttype, tname) _LOGGER.error("No such target: %s/%s", ttype, tname)
continue continue
except self.pushbullet.errors.PushError: except self.pushbullet.errors.PushError:
_LOGGER.error('Notify failed to: %s/%s', ttype, tname) _LOGGER.error("Notify failed to: %s/%s", ttype, tname)
continue continue

View file

@ -156,8 +156,8 @@ class MailNotificationService(BaseNotificationService):
msg.as_string()) msg.as_string())
break break
except smtplib.SMTPException: except smtplib.SMTPException:
_LOGGER.warning('SMTPException sending mail: ' _LOGGER.warning(
'retrying connection') "SMTPException sending mail: retrying connection")
mail.quit() mail.quit()
mail = self.connect() mail = self.connect()
@ -166,13 +166,13 @@ class MailNotificationService(BaseNotificationService):
def _build_text_msg(message): def _build_text_msg(message):
"""Build plaintext email.""" """Build plaintext email."""
_LOGGER.debug('Building plain text email') _LOGGER.debug("Building plain text email")
return MIMEText(message) return MIMEText(message)
def _build_multipart_msg(message, images): def _build_multipart_msg(message, images):
"""Build Multipart message with in-line 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 = MIMEMultipart('related')
msg_alt = MIMEMultipart('alternative') msg_alt = MIMEMultipart('alternative')
msg.attach(msg_alt) msg.attach(msg_alt)
@ -191,16 +191,15 @@ def _build_multipart_msg(message, images):
msg.attach(attachment) msg.attach(attachment)
attachment.add_header('Content-ID', '<{}>'.format(cid)) attachment.add_header('Content-ID', '<{}>'.format(cid))
except TypeError: except TypeError:
_LOGGER.warning('Attachment %s has an unkown MIME type.' _LOGGER.warning("Attachment %s has an unkown MIME type."
' Falling back to file', atch_name) " Falling back to file", atch_name)
attachment = MIMEApplication(file_bytes, Name=atch_name) attachment = MIMEApplication(file_bytes, Name=atch_name)
attachment['Content-Disposition'] = ('attachment; ' attachment['Content-Disposition'] = ('attachment; '
'filename="%s"' % 'filename="%s"' %
atch_name) atch_name)
msg.attach(attachment) msg.attach(attachment)
except FileNotFoundError: except FileNotFoundError:
_LOGGER.warning('Attachment %s not found. Skipping', _LOGGER.warning("Attachment %s not found. Skipping", atch_name)
atch_name)
body_html = MIMEText(''.join(body_text), 'html') body_html = MIMEText(''.join(body_text), 'html')
msg_alt.attach(body_html) msg_alt.attach(body_html)