8000 Catch exceptions by fabaff · Pull Request #9085 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Catch exceptions #9085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions homeassistant/components/notify/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.discord/
"""
import logging
import asyncio
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import (
PLATFORM_SCHEMA, BaseNotificationService, ATTR_TARGET)
Expand Down Expand Up @@ -42,13 +44,22 @@ def async_send_message(self, message, **kwargs):
import discord
discord_bot = discord.Client(loop=self.hass.loop)

if ATTR_TARGET not in kwargs:
_LOGGER.error("No target specified")
return None

# pylint: disable=unused-variable
@discord_bot.event
@asyncio.coroutine
def on_ready(): # pylint: disable=unused-variable
def on_ready():
"""Send the messages when the bot is ready."""
for channelid in kwargs[ATTR_TARGET]:
channel = discord.Object(id=channelid)
yield from discord_bot.send_message(channel, message)
try:
for channelid in kwargs[ATTR_TARGET]:
channel = discord.Object(id=channelid)
yield from discord_bot.send_message(channel, message)
except (discord.errors.HTTPException,
discord.errors.NotFound) as error:
_LOGGER.warning("Communication error: %s", error)
yield from discord_bot.logout()
yield from discord_bot.close()

Expand Down
0