Upgrade sendgrid to 3.0.7 (#2604)
parent
487f3b2951
commit
d808d90d26
|
@ -10,7 +10,7 @@ from homeassistant.components.notify import (
|
|||
ATTR_TITLE, DOMAIN, BaseNotificationService)
|
||||
from homeassistant.helpers import validate_config
|
||||
|
||||
REQUIREMENTS = ['sendgrid>=1.6.0,<1.7.0']
|
||||
REQUIREMENTS = ['sendgrid==3.0.7']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -24,27 +24,50 @@ def get_service(hass, config):
|
|||
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):
|
||||
"""Implement the notification service for email via Sendgrid."""
|
||||
"""Implementation the notification service for email via Sendgrid."""
|
||||
|
||||
def __init__(self, api_key, sender, recipient):
|
||||
"""Initialize the service."""
|
||||
from sendgrid import SendGridAPIClient
|
||||
|
||||
self.api_key = api_key
|
||||
self.sender = sender
|
||||
self.recipient = recipient
|
||||
|
||||
from sendgrid import SendGridClient
|
||||
self._sg = SendGridClient(self.api_key)
|
||||
self._sg = SendGridAPIClient(apikey=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)
|
||||
data = {
|
||||
"personalizations": [
|
||||
{
|
||||
"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
|
||||
|
||||
# homeassistant.components.notify.sendgrid
|
||||
sendgrid>=1.6.0,<1.7.0
|
||||
sendgrid==3.0.7
|
||||
|
||||
# homeassistant.components.notify.slack
|
||||
slacker==0.9.24
|
||||
|
|
Loading…
Reference in New Issue