Add missing docstring (#10812)

* Add missing docstring

* Revert isort change
This commit is contained in:
Fabian Affolter 2017-11-26 21:12:47 +01:00 committed by Daniel Høyer Iversen
parent 3e962808e6
commit a187bd5455

View File

@ -10,8 +10,8 @@ import mimetypes
import voluptuous as vol import voluptuous as vol
from homeassistant.components.notify import ( from homeassistant.components.notify import (
ATTR_DATA, ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA,
PLATFORM_SCHEMA, BaseNotificationService) BaseNotificationService)
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -85,12 +85,12 @@ class PushBulletNotificationService(BaseNotificationService):
refreshed = False refreshed = False
if not targets: if not targets:
# Backward compatibility, notify all devices in own account # Backward compatibility, notify all devices in own account.
self._push_data(message, title, data, self.pushbullet) self._push_data(message, title, data, self.pushbullet)
_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)
@ -98,15 +98,15 @@ class PushBulletNotificationService(BaseNotificationService):
_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':
self._push_data(message, title, data, self.pushbullet, tname) self._push_data(message, title, data, self.pushbullet, 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
@ -128,6 +128,7 @@ class PushBulletNotificationService(BaseNotificationService):
continue continue
def _push_data(self, message, title, data, pusher, tname=None): def _push_data(self, message, title, data, pusher, tname=None):
"""Helper for creating the message content."""
from pushbullet import PushError from pushbullet import PushError
if data is None: if data is None:
data = {} data = {}
@ -142,17 +143,17 @@ class PushBulletNotificationService(BaseNotificationService):
pusher.push_link(title, url, body=message) pusher.push_link(title, url, body=message)
elif filepath: elif filepath:
if not self.hass.config.is_allowed_path(filepath): if not self.hass.config.is_allowed_path(filepath):
_LOGGER.error("Filepath is not valid or allowed.") _LOGGER.error("Filepath is not valid or allowed")
return 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':
_LOGGER.error("Can not send an empty file.") _LOGGER.error("Can not send an empty file")
return return
pusher.push_file(title=title, body=message, **filedata) pusher.push_file(title=title, body=message, **filedata)
elif file_url: elif file_url:
if not file_url.startswith('http'): if not file_url.startswith('http'):
_LOGGER.error("Url should start with http or https.") _LOGGER.error("URL should start with http or https")
return return
pusher.push_file(title=title, body=message, file_name=file_url, pusher.push_file(title=title, body=message, file_name=file_url,
file_url=file_url, file_url=file_url,