mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Upgrade sendgrid to 3.0.7 (#2604)
This commit is contained in:
parent
487f3b2951
commit
d808d90d26
@ -10,7 +10,7 @@ from homeassistant.components.notify import (
|
|||||||
ATTR_TITLE, DOMAIN, BaseNotificationService)
|
ATTR_TITLE, DOMAIN, BaseNotificationService)
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
|
|
||||||
REQUIREMENTS = ['sendgrid>=1.6.0,<1.7.0']
|
REQUIREMENTS = ['sendgrid==3.0.7']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -24,27 +24,50 @@ def get_service(hass, config):
|
|||||||
api_key = config['api_key']
|
api_key = config['api_key']
|
||||||
sender = config['sender']
|
sender = config['sender']
|
||||||
recipient = config['recipient']
|
recipient = config['recipient']
|
||||||
|
|
||||||
return SendgridNotificationService(api_key, sender, recipient)
|
return SendgridNotificationService(api_key, sender, recipient)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class SendgridNotificationService(BaseNotificationService):
|
class SendgridNotificationService(BaseNotificationService):
|
||||||
"""Implement the notification service for email via Sendgrid."""
|
"""Implementation the notification service for email via Sendgrid."""
|
||||||
|
|
||||||
def __init__(self, api_key, sender, recipient):
|
def __init__(self, api_key, sender, recipient):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
|
from sendgrid import SendGridAPIClient
|
||||||
|
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.sender = sender
|
self.sender = sender
|
||||||
self.recipient = recipient
|
self.recipient = recipient
|
||||||
|
|
||||||
from sendgrid import SendGridClient
|
self._sg = SendGridAPIClient(apikey=self.api_key)
|
||||||
self._sg = SendGridClient(self.api_key)
|
|
||||||
|
|
||||||
def send_message(self, message='', **kwargs):
|
def send_message(self, message='', **kwargs):
|
||||||
"""Send an email to a user via SendGrid."""
|
"""Send an email to a user via SendGrid."""
|
||||||
subject = kwargs.get(ATTR_TITLE)
|
subject = kwargs.get(ATTR_TITLE)
|
||||||
|
|
||||||
from sendgrid import Mail
|
data = {
|
||||||
mail = Mail(from_email=self.sender, to=self.recipient,
|
"personalizations": [
|
||||||
html=message, text=message, subject=subject)
|
{
|
||||||
self._sg.send(mail)
|
"to": [
|
||||||
|
{
|
||||||
|
"email": self.recipient
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"subject": subject
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"from": {
|
||||||
|
"email": self.sender
|
||||||
|
},
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text/plain",
|
||||||
|
"value": message
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self._sg.client.mail.send.post(request_body=data)
|
||||||
|
if response.status_code is not 202:
|
||||||
|
_LOGGER.error('Unable to send notification with SendGrid')
|
||||||
|
@ -378,7 +378,7 @@ schiene==0.17
|
|||||||
scsgate==0.1.0
|
scsgate==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.notify.sendgrid
|
# homeassistant.components.notify.sendgrid
|
||||||
sendgrid>=1.6.0,<1.7.0
|
sendgrid==3.0.7
|
||||||
|
|
||||||
# homeassistant.components.notify.slack
|
# homeassistant.components.notify.slack
|
||||||
slacker==0.9.24
|
slacker==0.9.24
|
||||||
|
Loading…
x
Reference in New Issue
Block a user