From da19854520bc6ca16bcccc4ec0c2c3ad53e10cef Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 13 Sep 2020 18:23:50 +0200 Subject: [PATCH] Fix slack notifications requiring an icon (#40027) --- homeassistant/components/slack/notify.py | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/slack/notify.py b/homeassistant/components/slack/notify.py index d43a1fc25ad..8477b2fb501 100644 --- a/homeassistant/components/slack/notify.py +++ b/homeassistant/components/slack/notify.py @@ -202,22 +202,23 @@ class SlackNotificationService(BaseNotificationService): self, targets, message, title, blocks, username, icon ): """Send a text-only message.""" - if self._icon.lower().startswith(("http://", "https://")): - icon_type = "url" - else: - icon_type = "emoji" + message_dict = { + "blocks": blocks, + "link_names": True, + "text": message, + "username": username, + } + + if self._icon: + if self._icon.lower().startswith(("http://", "https://")): + icon_type = "url" + else: + icon_type = "emoji" + + message_dict[f"icon_{icon_type}"] = icon tasks = { - target: self._client.chat_postMessage( - **{ - "blocks": blocks, - "channel": target, - "link_names": True, - "text": message, - "username": username, - f"icon_{icon_type}": icon, - } - ) + target: self._client.chat_postMessage(**message_dict, channel=target) for target in targets }