Fix for issue #29822 (#30849)

This commit is contained in:
Per-Øyvind Bruun 2020-01-16 20:37:53 +01:00 committed by Paulus Schoutsen
parent 9bfcd04a4f
commit a93088dafb

View file

@ -39,16 +39,18 @@ class MSTeamsNotificationService(BaseNotificationService):
def __init__(self, webhook_url): def __init__(self, webhook_url):
"""Initialize the service.""" """Initialize the service."""
self._webhook_url = webhook_url self._webhook_url = webhook_url
self.teams_message = pymsteams.connectorcard(self._webhook_url)
def send_message(self, message=None, **kwargs): def send_message(self, message=None, **kwargs):
"""Send a message to the webhook.""" """Send a message to the webhook."""
teams_message = pymsteams.connectorcard(self._webhook_url)
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = kwargs.get(ATTR_DATA) data = kwargs.get(ATTR_DATA)
self.teams_message.title(title) teams_message.title(title)
self.teams_message.text(message) teams_message.text(message)
if data is not None: if data is not None:
file_url = data.get(ATTR_FILE_URL) file_url = data.get(ATTR_FILE_URL)
@ -60,8 +62,8 @@ class MSTeamsNotificationService(BaseNotificationService):
message_section = pymsteams.cardsection() message_section = pymsteams.cardsection()
message_section.addImage(file_url) message_section.addImage(file_url)
self.teams_message.addSection(message_section) teams_message.addSection(message_section)
try: try:
self.teams_message.send() teams_message.send()
except RuntimeError as err: except RuntimeError as err:
_LOGGER.error("Could not send notification. Error: %s", err) _LOGGER.error("Could not send notification. Error: %s", err)