Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)

This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-10-01 08:56:50 +02:00
1 parent 9e4c8f45d6
commit 3b5e5cbcd6
28 files changed
+112 -195

No files matched your search

@@ -4,7 +4,6 @@ Allows utilizing telegram webhooks.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/telegram_bot.webhooks/
"""
import asyncio
import datetime as dt
from ipaddress import ip_network
import logging
@@ -47,13 +46,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config):
async def async_setup_platform(hass, config):
"""Set up the Telegram webhooks platform."""
import telegram
bot = initialize_bot(config)
current_status = yield from hass.async_add_job(bot.getWebhookInfo)
current_status = await hass.async_add_job(bot.getWebhookInfo)
base_url = config.get(CONF_URL, hass.config.api.base_url)
# Some logging of Bot current status:
@@ -81,7 +79,7 @@ def async_setup_platform(hass, config):
retry_num)
if current_status and current_status['url'] != handler_url:
result = yield from hass.async_add_job(_try_to_set_webhook)
result = await hass.async_add_job(_try_to_set_webhook)
if result:
_LOGGER.info("Set new telegram webhook %s", handler_url)
else:
@@ -108,8 +106,7 @@ class BotPushReceiver(HomeAssistantView, BaseTelegramBotEntity):
BaseTelegramBotEntity.__init__(self, hass, allowed_chat_ids)
self.trusted_networks = trusted_networks
@asyncio.coroutine
def post(self, request):
async def post(self, request):
"""Accept the POST from telegram."""
real_ip = request[KEY_REAL_IP]
if not any(real_ip in net for net in self.trusted_networks):
@@ -117,7 +114,7 @@ class BotPushReceiver(HomeAssistantView, BaseTelegramBotEntity):
return self.json_message('Access denied', HTTP_UNAUTHORIZED)
try:
data = yield from request.json()
data = await request.json()
except ValueError:
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)