Fix telegram_bot (#7877)

This commit is contained in:
Paulus Schoutsen 2017-06-03 02:50:37 -07:00 committed by Lewis Juggins
parent 9c9f5068b7
commit 8461cf2717
3 changed files with 80 additions and 83 deletions

View File

@ -194,33 +194,34 @@ def load_data(url=None, filepath=None, username=None, password=None,
@asyncio.coroutine
def async_setup(hass, config):
"""Set up the Telegram bot component."""
conf = config[DOMAIN]
if not config[DOMAIN]:
return False
p_config = config[DOMAIN][0]
descriptions = yield from hass.async_add_job(
load_yaml_config_file,
os.path.join(os.path.dirname(__file__), 'services.yaml'))
@asyncio.coroutine
def async_setup_platform(p_type, p_config=None, discovery_info=None):
"""Set up a Telegram bot platform."""
p_type = p_config.get(CONF_PLATFORM)
platform = yield from async_prepare_setup_platform(
hass, config, DOMAIN, p_type)
if platform is None:
_LOGGER.error("Unknown notification service specified")
return
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
try:
receiver_service = yield from \
platform.async_setup_platform(hass, p_config, discovery_info)
platform.async_setup_platform(hass, p_config)
if receiver_service is None:
_LOGGER.error(
"Failed to initialize Telegram bot %s", p_type)
return
return False
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Error setting up platform %s", p_type)
return
return False
notify_service = TelegramNotificationService(
hass,
@ -282,10 +283,6 @@ def async_setup(hass, config):
return True
yield from async_setup_platform(conf.get(CONF_PLATFORM), conf)
return True
class TelegramNotificationService:
"""Implement the notification services for the Telegram Bot domain."""

View File

@ -25,7 +25,7 @@ PLATFORM_SCHEMA = TELEGRAM_PLATFORM_SCHEMA
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
def async_setup_platform(hass, config):
"""Set up the Telegram polling platform."""
import telegram
bot = telegram.Bot(config[CONF_API_KEY])

View File

@ -47,7 +47,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
def async_setup_platform(hass, config):
"""Set up the Telegram webhooks platform."""
import telegram
bot = telegram.Bot(config[CONF_API_KEY])