Update telegram_bot to use async_add_executor_job (#41924)
parent
91042e3e46
commit
9c719beded
|
@ -354,26 +354,32 @@ async def async_setup(hass, config):
|
||||||
_LOGGER.debug("New telegram message %s: %s", msgtype, kwargs)
|
_LOGGER.debug("New telegram message %s: %s", msgtype, kwargs)
|
||||||
|
|
||||||
if msgtype == SERVICE_SEND_MESSAGE:
|
if msgtype == SERVICE_SEND_MESSAGE:
|
||||||
await hass.async_add_job(partial(notify_service.send_message, **kwargs))
|
await hass.async_add_executor_job(
|
||||||
|
partial(notify_service.send_message, **kwargs)
|
||||||
|
)
|
||||||
elif msgtype in [
|
elif msgtype in [
|
||||||
SERVICE_SEND_PHOTO,
|
SERVICE_SEND_PHOTO,
|
||||||
SERVICE_SEND_STICKER,
|
SERVICE_SEND_STICKER,
|
||||||
SERVICE_SEND_VIDEO,
|
SERVICE_SEND_VIDEO,
|
||||||
SERVICE_SEND_DOCUMENT,
|
SERVICE_SEND_DOCUMENT,
|
||||||
]:
|
]:
|
||||||
await hass.async_add_job(
|
await hass.async_add_executor_job(
|
||||||
partial(notify_service.send_file, msgtype, **kwargs)
|
partial(notify_service.send_file, msgtype, **kwargs)
|
||||||
)
|
)
|
||||||
elif msgtype == SERVICE_SEND_LOCATION:
|
elif msgtype == SERVICE_SEND_LOCATION:
|
||||||
await hass.async_add_job(partial(notify_service.send_location, **kwargs))
|
await hass.async_add_executor_job(
|
||||||
|
partial(notify_service.send_location, **kwargs)
|
||||||
|
)
|
||||||
elif msgtype == SERVICE_ANSWER_CALLBACK_QUERY:
|
elif msgtype == SERVICE_ANSWER_CALLBACK_QUERY:
|
||||||
await hass.async_add_job(
|
await hass.async_add_executor_job(
|
||||||
partial(notify_service.answer_callback_query, **kwargs)
|
partial(notify_service.answer_callback_query, **kwargs)
|
||||||
)
|
)
|
||||||
elif msgtype == SERVICE_DELETE_MESSAGE:
|
elif msgtype == SERVICE_DELETE_MESSAGE:
|
||||||
await hass.async_add_job(partial(notify_service.delete_message, **kwargs))
|
await hass.async_add_executor_job(
|
||||||
|
partial(notify_service.delete_message, **kwargs)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await hass.async_add_job(
|
await hass.async_add_executor_job(
|
||||||
partial(notify_service.edit_message, msgtype, **kwargs)
|
partial(notify_service.edit_message, msgtype, **kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ async def async_setup_platform(hass, config):
|
||||||
"""Set up the Telegram broadcast platform."""
|
"""Set up the Telegram broadcast platform."""
|
||||||
bot = initialize_bot(config)
|
bot = initialize_bot(config)
|
||||||
|
|
||||||
bot_config = await hass.async_add_job(bot.getMe)
|
bot_config = await hass.async_add_executor_job(bot.getMe)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Telegram broadcast platform setup with bot %s", bot_config["username"]
|
"Telegram broadcast platform setup with bot %s", bot_config["username"]
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,7 +32,7 @@ async def async_setup_platform(hass, config):
|
||||||
|
|
||||||
bot = initialize_bot(config)
|
bot = initialize_bot(config)
|
||||||
|
|
||||||
current_status = await hass.async_add_job(bot.getWebhookInfo)
|
current_status = await hass.async_add_executor_job(bot.getWebhookInfo)
|
||||||
base_url = config.get(
|
base_url = config.get(
|
||||||
CONF_URL, get_url(hass, require_ssl=True, allow_internal=False)
|
CONF_URL, get_url(hass, require_ssl=True, allow_internal=False)
|
||||||
)
|
)
|
||||||
|
@ -64,7 +64,7 @@ async def async_setup_platform(hass, config):
|
||||||
_LOGGER.warning("Timeout trying to set webhook (retry #%d)", retry_num)
|
_LOGGER.warning("Timeout trying to set webhook (retry #%d)", retry_num)
|
||||||
|
|
||||||
if current_status and current_status["url"] != handler_url:
|
if current_status and current_status["url"] != handler_url:
|
||||||
result = await hass.async_add_job(_try_to_set_webhook)
|
result = await hass.async_add_executor_job(_try_to_set_webhook)
|
||||||
if result:
|
if result:
|
||||||
_LOGGER.info("Set new telegram webhook %s", handler_url)
|
_LOGGER.info("Set new telegram webhook %s", handler_url)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue