mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add SendGrid notify component
This commit is contained in:
parent
f4b5b3f88f
commit
9b371a8c66
@ -116,6 +116,7 @@ omit =
|
|||||||
homeassistant/components/notify/pushetta.py
|
homeassistant/components/notify/pushetta.py
|
||||||
homeassistant/components/notify/pushover.py
|
homeassistant/components/notify/pushover.py
|
||||||
homeassistant/components/notify/rest.py
|
homeassistant/components/notify/rest.py
|
||||||
|
homeassistant/components/notify/sendgrid.py
|
||||||
homeassistant/components/notify/slack.py
|
homeassistant/components/notify/slack.py
|
||||||
homeassistant/components/notify/smtp.py
|
homeassistant/components/notify/smtp.py
|
||||||
homeassistant/components/notify/syslog.py
|
homeassistant/components/notify/syslog.py
|
||||||
|
51
homeassistant/components/notify/sendgrid.py
Normal file
51
homeassistant/components/notify/sendgrid.py
Normal file
@ -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
|
# homeassistant.components.scsgate
|
||||||
scsgate==0.1.0
|
scsgate==0.1.0
|
||||||
|
|
||||||
|
# homeassistant.components.notify.sendgrid
|
||||||
|
sendgrid>=1.6.0,<1.7.0
|
||||||
|
|
||||||
# homeassistant.components.notify.slack
|
# homeassistant.components.notify.slack
|
||||||
slacker==0.6.8
|
slacker==0.6.8
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user