Update discord.py (#16248)

* Update discord.py

* Update discord.py

Fixed ATTR_IMAGES checking, line length, and ATTR_DATA imported. Also fixed missing spaces.

* Update discord.py

Fix E302...
This commit is contained in:
Totoo 2018-09-02 18:58:31 +02:00 committed by Fabian Affolter
parent a5cff9877e
commit 03480dc779

View file

@ -11,7 +11,7 @@ import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import (
PLATFORM_SCHEMA, BaseNotificationService, ATTR_TARGET)
PLATFORM_SCHEMA, BaseNotificationService, ATTR_TARGET, ATTR_DATA)
from homeassistant.const import CONF_TOKEN
_LOGGER = logging.getLogger(__name__)
@ -22,6 +22,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_TOKEN): cv.string
})
ATTR_IMAGES = 'images'
def get_service(hass, config, discovery_info=None):
"""Get the Discord notification service."""
@ -53,9 +55,15 @@ class DiscordNotificationService(BaseNotificationService):
def on_ready():
"""Send the messages when the bot is ready."""
try:
data = kwargs.get(ATTR_DATA)
if data:
images = data.get(ATTR_IMAGES)
for channelid in kwargs[ATTR_TARGET]:
channel = discord.Object(id=channelid)
yield from discord_bot.send_message(channel, message)
if images:
for anum, f_name in enumerate(images):
yield from discord_bot.send_file(channel, f_name)
except (discord.errors.HTTPException,
discord.errors.NotFound) as error:
_LOGGER.warning("Communication error: %s", error)