Style updates (#5878)

* Use consts, update quoting, and update comments

* Update log message

* Update docstrings

* Update log messages

* Update log messages

* Update style

* Fix typo

* Add newline

* Fix indent

* Fix line too long
This commit is contained in:
Fabian Affolter authored and Paulus Schoutsen committed 2017-02-11 11:29:37 -08:00
1 parent b981bfba7e
commit 88653e66c8
9 files changed
+142 -185

No files matched your search

+16 -21
View File
@@ -9,13 +9,14 @@ import logging
import voluptuous as vol
from homeassistant.components.notify import (
PLATFORM_SCHEMA, BaseNotificationService,
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA)
from homeassistant.const import (CONF_TOKEN, CONF_DOMAIN,
CONF_RECIPIENT, CONF_SENDER)
PLATFORM_SCHEMA, BaseNotificationService, ATTR_TITLE, ATTR_TITLE_DEFAULT,
ATTR_DATA)
from homeassistant.const import (
CONF_TOKEN, CONF_DOMAIN, CONF_RECIPIENT, CONF_SENDER)
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['https://github.com/pschmitt/pymailgun/'
'archive/1.3.zip#'
'pymailgun==1.3']
@@ -23,12 +24,9 @@ REQUIREMENTS = ['https://github.com/pschmitt/pymailgun/'
# Images to attach to notification
ATTR_IMAGES = 'images'
# Configuration item for the domain to use.
CONF_SANDBOX = 'sandbox'
# Default sender name
DEFAULT_SENDER = 'hass@{domain}'
# Default sandbox value
DEFAULT_SANDBOX = False
# pylint: disable=no-value-for-parameter
@@ -43,11 +41,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def get_service(hass, config, discovery_info=None):
"""Get the Mailgun notification service."""
mailgun_service = MailgunNotificationService(config.get(CONF_DOMAIN),
config.get(CONF_SANDBOX),
config.get(CONF_TOKEN),
config.get(CONF_SENDER),
config.get(CONF_RECIPIENT))
mailgun_service = MailgunNotificationService(
config.get(CONF_DOMAIN), config.get(CONF_SANDBOX),
config.get(CONF_TOKEN), config.get(CONF_SENDER),
config.get(CONF_RECIPIENT))
if mailgun_service.connection_is_valid():
return mailgun_service
else:
@@ -70,7 +67,7 @@ class MailgunNotificationService(BaseNotificationService):
"""Initialize the connection to Mailgun."""
from pymailgun import Client
self._client = Client(self._token, self._domain, self._sandbox)
_LOGGER.debug('Mailgun domain: %s', self._client.domain)
_LOGGER.debug("Mailgun domain: %s", self._client.domain)
self._domain = self._client.domain
if not self._sender:
self._sender = DEFAULT_SENDER.format(domain=self._domain)
@@ -81,7 +78,7 @@ class MailgunNotificationService(BaseNotificationService):
try:
self.initialize_client()
except MailgunCredentialsError:
_LOGGER.exception('Invalid credentials')
_LOGGER.exception("Invalid credentials")
return False
except MailgunDomainError as mailgun_error:
_LOGGER.exception(mailgun_error)
@@ -99,11 +96,9 @@ class MailgunNotificationService(BaseNotificationService):
# Initialize the client in case it was not.
if self._client is None:
self.initialize_client()
resp = self._client.send_mail(sender=self._sender,
to=self._recipient,
subject=subject,
text=message,
files=files)
_LOGGER.debug('Message sent: %s', resp)
resp = self._client.send_mail(
sender=self._sender, to=self._recipient, subject=subject,
text=message, files=files)
_LOGGER.debug("Message sent: %s", resp)
except MailgunError as mailgun_error:
_LOGGER.exception('Failed to send message: %s', mailgun_error)
_LOGGER.exception("Failed to send message: %s", mailgun_error)