From 114d48ed8b5d029abe2fb06cba0eb4aebda7eca4 Mon Sep 17 00:00:00 2001 From: Konsts Date: Mon, 3 Feb 2020 22:23:58 +0200 Subject: [PATCH] Add timeout attribute for send files (#31379) * Add timeout attribute for send files * Remove dublicate Remove attribute dublicate in BASE_SERVICE_SCHEMA * Remove duplicate return attribute to BASE_SERVICE_SCHEMA and remove from SERVICE_SCHEMA_SEND_FILE * Add timeout parameter description Add timeout parameter description for "send message" and "send location" --- .../components/telegram_bot/__init__.py | 10 +++++----- .../components/telegram_bot/services.yaml | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 9b56201f8c74..277f91086639 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -25,7 +25,6 @@ from homeassistant.const import ( ATTR_LONGITUDE, CONF_API_KEY, CONF_PLATFORM, - CONF_TIMEOUT, CONF_URL, HTTP_DIGEST_AUTHENTICATION, ) @@ -67,6 +66,7 @@ ATTR_URL = "url" ATTR_USER_ID = "user_id" ATTR_USERNAME = "username" ATTR_VERIFY_SSL = "verify_ssl" +ATTR_TIMEOUT = "timeout" CONF_ALLOWED_CHAT_IDS = "allowed_chat_ids" CONF_PROXY_URL = "proxy_url" @@ -135,7 +135,7 @@ BASE_SERVICE_SCHEMA = vol.Schema( vol.Optional(ATTR_DISABLE_WEB_PREV): cv.boolean, vol.Optional(ATTR_KEYBOARD): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_KEYBOARD_INLINE): cv.ensure_list, - vol.Optional(CONF_TIMEOUT): vol.Coerce(float), + vol.Optional(ATTR_TIMEOUT): cv.positive_int, }, extra=vol.ALLOW_EXTRA, ) @@ -499,15 +499,15 @@ class TelegramNotificationService: ATTR_DISABLE_WEB_PREV: None, ATTR_REPLY_TO_MSGID: None, ATTR_REPLYMARKUP: None, - CONF_TIMEOUT: None, + ATTR_TIMEOUT: None, } if data is not None: if ATTR_PARSER in data: params[ATTR_PARSER] = self._parsers.get( data[ATTR_PARSER], self._parse_mode ) - if CONF_TIMEOUT in data: - params[CONF_TIMEOUT] = data[CONF_TIMEOUT] + if ATTR_TIMEOUT in data: + params[ATTR_TIMEOUT] = data[ATTR_TIMEOUT] if ATTR_DISABLE_NOTIF in data: params[ATTR_DISABLE_NOTIF] = data[ATTR_DISABLE_NOTIF] if ATTR_DISABLE_WEB_PREV in data: diff --git a/homeassistant/components/telegram_bot/services.yaml b/homeassistant/components/telegram_bot/services.yaml index ed8720c58770..e3d303a2c528 100644 --- a/homeassistant/components/telegram_bot/services.yaml +++ b/homeassistant/components/telegram_bot/services.yaml @@ -21,6 +21,9 @@ send_message: disable_web_page_preview: description: Disables link previews for links in the message. example: true + timeout: + description: Timeout for send message. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. Empty list clears a previously set keyboard. example: '["/command1, /command2", "/command3"]' @@ -55,6 +58,9 @@ send_photo: verify_ssl: description: Enable or disable SSL certificate verification. Set to false if you're downloading the file from a URL and you don't want to validate the SSL certificate of the server. example: false + timeout: + description: Timeout for send photo. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. example: '["/command1, /command2", "/command3"]' @@ -86,6 +92,9 @@ send_sticker: verify_ssl: description: Enable or disable SSL certificate verification. Set to false if you're downloading the file from a URL and you don't want to validate the SSL certificate of the server. example: false + timeout: + description: Timeout for send sticker. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. example: '["/command1, /command2", "/command3"]' @@ -120,6 +129,9 @@ send_video: verify_ssl: description: Enable or disable SSL certificate verification. Set to false if you're downloading the file from a URL and you don't want to validate the SSL certificate of the server. example: false + timeout: + description: Timeout for send video. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. example: '["/command1, /command2", "/command3"]' @@ -154,6 +166,9 @@ send_document: verify_ssl: description: Enable or disable SSL certificate verification. Set to false if you're downloading the file from a URL and you don't want to validate the SSL certificate of the server. example: false + timeout: + description: Timeout for send document. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. example: '["/command1, /command2", "/command3"]' @@ -176,6 +191,9 @@ send_location: disable_notification: description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound. example: true + timeout: + description: Timeout for send photo. Will help with timeout errors (poor internet connection, etc) + example: '1000' keyboard: description: List of rows of commands, comma-separated, to make a custom keyboard. example: '["/command1, /command2", "/command3"]'