mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
telegram_bot platform to only send messages (#8186)
* add new telegram_bot platform to only send messages * Fix async
This commit is contained in:
parent
23400c4b0a
commit
596093d564
@ -227,7 +227,7 @@ def async_setup(hass, config):
|
|||||||
try:
|
try:
|
||||||
receiver_service = yield from \
|
receiver_service = yield from \
|
||||||
platform.async_setup_platform(hass, p_config)
|
platform.async_setup_platform(hass, p_config)
|
||||||
if receiver_service is None:
|
if receiver_service is False:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Failed to initialize Telegram bot %s", p_type)
|
"Failed to initialize Telegram bot %s", p_type)
|
||||||
return False
|
return False
|
||||||
|
28
homeassistant/components/telegram_bot/broadcast.py
Normal file
28
homeassistant/components/telegram_bot/broadcast.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""
|
||||||
|
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])
|
||||||
|
bot_config = yield from hass.async_add_job(bot.getMe)
|
||||||
|
_LOGGER.debug("Telegram broadcast platform setup with bot %s",
|
||||||
|
bot_config['username'])
|
||||||
|
return True
|
Loading…
x
Reference in New Issue
Block a user