From a4b8c3cab0b3e3a7613924492535c13cd39d3114 Mon Sep 17 00:00:00 2001 From: icovada Date: Sat, 27 Aug 2016 02:52:44 +0200 Subject: [PATCH] Update telegram.py add send_document (#2937) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐬 --- homeassistant/components/notify/telegram.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/homeassistant/components/notify/telegram.py b/homeassistant/components/notify/telegram.py index 5e0cee9a441..8da916eb1f3 100644 --- a/homeassistant/components/notify/telegram.py +++ b/homeassistant/components/notify/telegram.py @@ -21,6 +21,7 @@ _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['python-telegram-bot==5.0.0'] ATTR_PHOTO = "photo" +ATTR_DOCUMENT = "document" ATTR_CAPTION = "caption" CONF_CHAT_ID = 'chat_id' @@ -102,6 +103,8 @@ class TelegramNotificationService(BaseNotificationService): return elif data is not None and ATTR_LOCATION in data: return self.send_location(data.get(ATTR_LOCATION)) + elif data is not None and ATTR_DOCUMENT in data: + return self.send_document(data.get(ATTR_DOCUMENT)) # send message try: @@ -125,6 +128,20 @@ class TelegramNotificationService(BaseNotificationService): _LOGGER.exception("Error sending photo.") return + def send_document(self, data): + """Send a document.""" + import telegram + caption = data.pop(ATTR_CAPTION, None) + + # send photo + try: + document = load_data(**data) + self.bot.sendDocument(chat_id=self._chat_id, + document=document, caption=caption) + except telegram.error.TelegramError: + _LOGGER.exception("Error sending document.") + return + def send_location(self, gps): """Send a location.""" import telegram