diff --git a/CODEOWNERS b/CODEOWNERS index c6deb8e9f8f8ffcbbf7f3964657cb5563c533930..27614c3d49dc884a521221049cc494cf5065e0f6 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -404,6 +404,7 @@ homeassistant/components/simplisafe/* @bachya homeassistant/components/sinch/* @bendikrb homeassistant/components/sisyphus/* @jkeljo homeassistant/components/sky_hub/* @rogerselwyn +homeassistant/components/slack/* @bachya homeassistant/components/slide/* @ualex73 homeassistant/components/sma/* @kellerza homeassistant/components/smappee/* @bsmappee diff --git a/homeassistant/components/slack/manifest.json b/homeassistant/components/slack/manifest.json index ad45abbe3c0a896c86c33a426b736c89ef07963b..e183dd455f1a9f578b5588ca41c209629365657b 100644 --- a/homeassistant/components/slack/manifest.json +++ b/homeassistant/components/slack/manifest.json @@ -3,5 +3,5 @@ "name": "Slack", "documentation": "https://www.home-assistant.io/integrations/slack", "requirements": ["slackclient==2.5.0"], - "codeowners": [] + "codeowners": ["@bachya"] } diff --git a/homeassistant/components/slack/notify.py b/homeassistant/components/slack/notify.py index 88317b31585a006184a70b904933544817b8d555..90caad62a5897cd2dce591882d48f68655e2120b 100644 --- a/homeassistant/components/slack/notify.py +++ b/homeassistant/components/slack/notify.py @@ -198,17 +198,21 @@ class SlackNotificationService(BaseNotificationService): _LOGGER.error("Error while uploading file message: %s", err) async def _async_send_text_only_message( - self, targets, message, title, blocks, username, icon + self, + targets, + message, + title, + *, + username=None, + icon=None, + blocks=None, ): """Send a text-only message.""" - message_dict = { - "blocks": blocks, - "link_names": True, - "text": message, - "username": username, - } + message_dict = {"link_names": True, "text": message} + + if username: + message_dict["username"] = username - icon = icon or self._icon if icon: if icon.lower().startswith(("http://", "https://")): icon_type = "url" @@ -217,6 +221,9 @@ class SlackNotificationService(BaseNotificationService): message_dict[f"icon_{icon_type}"] = icon + if blocks: + message_dict["blocks"] = blocks + tasks = { target: self._client.chat_postMessage(**message_dict, channel=target) for target in targets @@ -256,15 +263,15 @@ class SlackNotificationService(BaseNotificationService): elif ATTR_BLOCKS in data: blocks = data[ATTR_BLOCKS] else: - blocks = {} + blocks = None return await self._async_send_text_only_message( targets, message, title, - blocks, username=data.get(ATTR_USERNAME, self._username), icon=data.get(ATTR_ICON, self._icon), + blocks=blocks, ) # Message Type 2: A message that uploads a remote file