Merge pull request #1419 from justincmoy/sendgrid_initial
Add SendGrid notify componentpull/1417/head
commit
efeb5c5290
|
@ -116,6 +116,7 @@ omit =
|
|||
homeassistant/components/notify/pushetta.py
|
||||
homeassistant/components/notify/pushover.py
|
||||
homeassistant/components/notify/rest.py
|
||||
homeassistant/components/notify/sendgrid.py
|
||||
homeassistant/components/notify/slack.py
|
||||
homeassistant/components/notify/smtp.py
|
||||
homeassistant/components/notify/syslog.py
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
homeassistant.components.notify.sendgrid
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
SendGrid notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.sendgrid/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TITLE, DOMAIN, BaseNotificationService)
|
||||
from homeassistant.helpers import validate_config
|
||||
|
||||
REQUIREMENTS = ['sendgrid>=1.6.0,<1.7.0']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the SendGrid notification service """
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['api_key', 'sender', 'recipient']},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
api_key = config['api_key']
|
||||
sender = config['sender']
|
||||
recipient = config['recipient']
|
||||
return SendgridNotificationService(api_key, sender, recipient)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class SendgridNotificationService(BaseNotificationService):
|
||||
""" Implements the notification service for email via Sendgrid. """
|
||||
|
||||
def __init__(self, api_key, sender, recipient):
|
||||
self.api_key = api_key
|
||||
self.sender = sender
|
||||
self.recipient = recipient
|
||||
|
||||
from sendgrid import SendGridClient
|
||||
self._sg = SendGridClient(self.api_key)
|
||||
|
||||
def send_message(self, message='', **kwargs):
|
||||
""" Send an email to a user via SendGrid. """
|
||||
subject = kwargs.get(ATTR_TITLE)
|
||||
|
||||
from sendgrid import Mail
|
||||
mail = Mail(from_email=self.sender, to=self.recipient,
|
||||
html=message, text=message, subject=subject)
|
||||
self._sg.send(mail)
|
|
@ -232,6 +232,9 @@ schiene==0.14
|
|||
# homeassistant.components.scsgate
|
||||
scsgate==0.1.0
|
||||
|
||||
# homeassistant.components.notify.sendgrid
|
||||
sendgrid>=1.6.0,<1.7.0
|
||||
|
||||
# homeassistant.components.notify.slack
|
||||
slacker==0.6.8
|
||||
|
||||
|
|
Loading…
Reference in New Issue