mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix telegram_bot (#7877)
This commit is contained in:
parent
9c9f5068b7
commit
8461cf2717
@ -194,33 +194,34 @@ def load_data(url=None, filepath=None, username=None, password=None,
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Set up the Telegram bot component."""
|
"""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(
|
descriptions = yield from hass.async_add_job(
|
||||||
load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
p_type = p_config.get(CONF_PLATFORM)
|
||||||
def async_setup_platform(p_type, p_config=None, discovery_info=None):
|
|
||||||
"""Set up a Telegram bot platform."""
|
|
||||||
platform = yield from async_prepare_setup_platform(
|
platform = yield from async_prepare_setup_platform(
|
||||||
hass, config, DOMAIN, p_type)
|
hass, config, DOMAIN, p_type)
|
||||||
|
|
||||||
if platform is None:
|
if platform is None:
|
||||||
_LOGGER.error("Unknown notification service specified")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
|
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
|
||||||
try:
|
try:
|
||||||
receiver_service = yield from \
|
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:
|
if receiver_service is None:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Failed to initialize Telegram bot %s", p_type)
|
"Failed to initialize Telegram bot %s", p_type)
|
||||||
return
|
return False
|
||||||
|
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Error setting up platform %s", p_type)
|
_LOGGER.exception("Error setting up platform %s", p_type)
|
||||||
return
|
return False
|
||||||
|
|
||||||
notify_service = TelegramNotificationService(
|
notify_service = TelegramNotificationService(
|
||||||
hass,
|
hass,
|
||||||
@ -282,10 +283,6 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
yield from async_setup_platform(conf.get(CONF_PLATFORM), conf)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class TelegramNotificationService:
|
class TelegramNotificationService:
|
||||||
"""Implement the notification services for the Telegram Bot domain."""
|
"""Implement the notification services for the Telegram Bot domain."""
|
||||||
|
@ -25,7 +25,7 @@ PLATFORM_SCHEMA = TELEGRAM_PLATFORM_SCHEMA
|
|||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@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."""
|
"""Set up the Telegram polling platform."""
|
||||||
import telegram
|
import telegram
|
||||||
bot = telegram.Bot(config[CONF_API_KEY])
|
bot = telegram.Bot(config[CONF_API_KEY])
|
||||||
|
@ -47,7 +47,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@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."""
|
"""Set up the Telegram webhooks platform."""
|
||||||
import telegram
|
import telegram
|
||||||
bot = telegram.Bot(config[CONF_API_KEY])
|
bot = telegram.Bot(config[CONF_API_KEY])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user