From d02d2005bcad646ea420a536d05a2a02abcdf033 Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Sun, 5 Apr 2020 13:34:27 +0200 Subject: [PATCH 1/8] Update notify.py --- homeassistant/components/discord/notify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index 19c25a2fd45148..e0ef7e1c174203 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -70,12 +70,13 @@ async def async_send_message(self, message, **kwargs): # pylint: disable=unused-variable @discord_bot.event + async def on_ready(): """Send the messages when the bot is ready.""" try: for channelid in kwargs[ATTR_TARGET]: channelid = int(channelid) - channel = discord_bot.get_channel(channelid) + channel = discord_bot.get_channel(channelid) or discord_bot.get_user(channelid) if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) From 962c17e3ffde8097a5472560064b13fefd5a64d1 Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Sun, 5 Apr 2020 14:28:01 +0200 Subject: [PATCH 2/8] Update notify.py --- homeassistant/components/discord/notify.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index e0ef7e1c174203..e4558b103bd276 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -39,7 +39,6 @@ def file_exists(self, filename): """Check if a file exists on disk and is in authorized path.""" if not self.hass.config.is_allowed_path(filename): return False - return os.path.isfile(filename) async def async_send_message(self, message, **kwargs): @@ -52,7 +51,6 @@ async def async_send_message(self, message, **kwargs): if ATTR_TARGET not in kwargs: _LOGGER.error("No target specified") return None - data = kwargs.get(ATTR_DATA) or {} if ATTR_IMAGES in data: @@ -67,28 +65,26 @@ async def async_send_message(self, message, **kwargs): images.append(image) else: _LOGGER.warning("Image not found: %s", image) - # pylint: disable=unused-variable @discord_bot.event - async def on_ready(): """Send the messages when the bot is ready.""" try: for channelid in kwargs[ATTR_TARGET]: channelid = int(channelid) - channel = discord_bot.get_channel(channelid) or discord_bot.get_user(channelid) + channel = discord_bot.get_channel( + channelid + ) or discord_bot.get_user(channelid) if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) continue - # Must create new instances of File for each channel. files = None if images: files = [] for image in images: files.append(discord.File(image)) - await channel.send(message, files=files) except (discord.errors.HTTPException, discord.errors.NotFound) as error: _LOGGER.warning("Communication error: %s", error) From fa198fb23fb5dcbd75e84cfd6757a5b120ce7edf Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 12:39:45 +0200 Subject: [PATCH 3/8] Update notify.py Added a comment --- homeassistant/components/discord/notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index e4558b103bd276..97d78cd0c9ea12 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -74,7 +74,7 @@ async def on_ready(): channelid = int(channelid) channel = discord_bot.get_channel( channelid - ) or discord_bot.get_user(channelid) + ) or discord_bot.get_user(channelid) # tests the target as a channel and user if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) From 1b3143e71bf3ffb902743db63c37c37e5087e117 Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 13:57:54 +0200 Subject: [PATCH 4/8] Update notify.py --- homeassistant/components/discord/notify.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index 97d78cd0c9ea12..687d37311a0853 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -74,7 +74,9 @@ async def on_ready(): channelid = int(channelid) channel = discord_bot.get_channel( channelid - ) or discord_bot.get_user(channelid) # tests the target as a channel and user + ) or discord_bot.get_user( + channelid + ) # tests the target as a channel and user if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) From b4e9592a9d4e84b74c543e82261792aa319f7434 Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 15:14:47 +0200 Subject: [PATCH 5/8] Update notify.py --- homeassistant/components/discord/notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index 687d37311a0853..b043ef022b0c64 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -76,7 +76,7 @@ async def on_ready(): channelid ) or discord_bot.get_user( channelid - ) # tests the target as a channel and user + ) if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) From 4a20d07c17af90c2f9dff143447a220b1d8ab992 Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 15:23:28 +0200 Subject: [PATCH 6/8] Update notify.py --- homeassistant/components/discord/notify.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index b043ef022b0c64..e4558b103bd276 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -74,9 +74,7 @@ async def on_ready(): channelid = int(channelid) channel = discord_bot.get_channel( channelid - ) or discord_bot.get_user( - channelid - ) + ) or discord_bot.get_user(channelid) if channel is None: _LOGGER.warning("Channel not found for id: %s", channelid) From c7ddca84de8328799acbb9242b6e292be1055c1f Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:07:06 +0200 Subject: [PATCH 7/8] Update notify.py --- homeassistant/components/discord/notify.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index e4558b103bd276..8da9c3c07ffcaa 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -20,13 +20,11 @@ ATTR_IMAGES = "images" - def get_service(hass, config, discovery_info=None): """Get the Discord notification service.""" token = config.get(CONF_TOKEN) return DiscordNotificationService(hass, token) - class DiscordNotificationService(BaseNotificationService): """Implement the notification service for Discord.""" From 59fb39cd1af21cfbe38b6a1dbb43d80863441d9f Mon Sep 17 00:00:00 2001 From: vermium-sifell <47034338+vermium-sifell@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:13:38 +0200 Subject: [PATCH 8/8] Update notify.py --- homeassistant/components/discord/notify.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index 8da9c3c07ffcaa..e4558b103bd276 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -20,11 +20,13 @@ ATTR_IMAGES = "images" + def get_service(hass, config, discovery_info=None): """Get the Discord notification service.""" token = config.get(CONF_TOKEN) return DiscordNotificationService(hass, token) + class DiscordNotificationService(BaseNotificationService): """Implement the notification service for Discord."""