Fix typo and update name (#6809)
parent
84287872bb
commit
f4f72e420a
|
@ -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/
|
||||
|
@ -26,7 +26,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
# 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
|
||||
|
||||
|
@ -53,9 +53,9 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
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.
|
||||
|
@ -73,7 +73,7 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
"""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.
|
||||
"""
|
||||
|
@ -86,37 +86,37 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
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()
|
||||
|
@ -129,14 +129,14 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
# 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
|
||||
|
|
|
@ -156,8 +156,8 @@ class MailNotificationService(BaseNotificationService):
|
|||
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()
|
||||
|
||||
|
@ -166,13 +166,13 @@ class MailNotificationService(BaseNotificationService):
|
|||
|
||||
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)
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue