From f38a52b08d8a8bfa13a36c72564666234e086330 Mon Sep 17 00:00:00 2001 From: azogue Date: Mon, 26 Jun 2017 12:14:50 +0200 Subject: [PATCH 1/2] add new telegram_bot platform to only send messages --- .../components/telegram_bot/__init__.py | 2 +- .../components/telegram_bot/broadcast.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/telegram_bot/broadcast.py diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 0e889d64a4afa..8e9e6373918a6 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -227,7 +227,7 @@ def async_setup(hass, config): try: receiver_service = yield from \ platform.async_setup_platform(hass, p_config) - if receiver_service is None: + if receiver_service is False: _LOGGER.error( "Failed to initialize Telegram bot %s", p_type) return False diff --git a/homeassistant/components/telegram_bot/broadcast.py b/homeassistant/components/telegram_bot/broadcast.py new file mode 100644 index 0000000000000..ebc1533b98617 --- /dev/null +++ b/homeassistant/components/telegram_bot/broadcast.py @@ -0,0 +1,26 @@ +""" +Telegram bot implementation to send messages only. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/telegram_bot.broadcast/ +""" +import asyncio +import logging + +from homeassistant.components.telegram_bot import ( + PLATFORM_SCHEMA as TELEGRAM_PLATFORM_SCHEMA) +from homeassistant.const import CONF_API_KEY + +_LOGGER = logging.getLogger(__name__) + +PLATFORM_SCHEMA = TELEGRAM_PLATFORM_SCHEMA + + +@asyncio.coroutine +def async_setup_platform(hass, config): + """Set up the Telegram broadcast platform.""" + # Check the API key works + import telegram + bot = telegram.Bot(config[CONF_API_KEY]) + _LOGGER.debug("Telegram broadcast platform setup with bot %s", bot.name) + return True From beaf0e9bee744fcb58b799035df081060a790ed9 Mon Sep 17 00:00:00 2001 From: azogue Date: Mon, 26 Jun 2017 22:58:18 +0200 Subject: [PATCH 2/2] Fix async --- homeassistant/components/telegram_bot/broadcast.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/telegram_bot/broadcast.py b/homeassistant/components/telegram_bot/broadcast.py index ebc1533b98617..091aab58be89b 100644 --- a/homeassistant/components/telegram_bot/broadcast.py +++ b/homeassistant/components/telegram_bot/broadcast.py @@ -22,5 +22,7 @@ def async_setup_platform(hass, config): # Check the API key works import telegram bot = telegram.Bot(config[CONF_API_KEY]) - _LOGGER.debug("Telegram broadcast platform setup with bot %s", bot.name) + bot_config = yield from hass.async_add_job(bot.getMe) + _LOGGER.debug("Telegram broadcast platform setup with bot %s", + bot_config['username']) return True