mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Fix telegram_bot (#7877)
This commit is contained in:
parent
a33bcdf270
commit
a79f1d4d40
@ -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."""
|
||||
|
@ -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])
|
||||
|
@ -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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user