add service to reconnect the bot (#18142)

This commit is contained in:
Marcel Hoppe 2018-11-05 13:14:22 +01:00 committed by Paulus Schoutsen
parent 8ee0e0c6c6
commit 8de79ed57c
4 changed files with 17 additions and 2 deletions

View File

@ -22,7 +22,7 @@ from .const import (
SERVICE_UPDATE, CONF_SENTENCES, CONF_MATCHERS, SERVICE_UPDATE, CONF_SENTENCES, CONF_MATCHERS,
CONF_ERROR_SUPPRESSED_CONVERSATIONS, INTENT_SCHEMA, TARGETS_SCHEMA, CONF_ERROR_SUPPRESSED_CONVERSATIONS, INTENT_SCHEMA, TARGETS_SCHEMA,
CONF_DEFAULT_CONVERSATIONS, EVENT_HANGOUTS_CONVERSATIONS_RESOLVED, CONF_DEFAULT_CONVERSATIONS, EVENT_HANGOUTS_CONVERSATIONS_RESOLVED,
INTENT_HELP) INTENT_HELP, SERVICE_RECONNECT)
# We need an import from .config_flow, without it .config_flow is never loaded. # We need an import from .config_flow, without it .config_flow is never loaded.
from .config_flow import HangoutsFlowHandler # noqa: F401 from .config_flow import HangoutsFlowHandler # noqa: F401
@ -130,6 +130,12 @@ async def async_setup_entry(hass, config):
async_handle_update_users_and_conversations, async_handle_update_users_and_conversations,
schema=vol.Schema({})) schema=vol.Schema({}))
hass.services.async_register(DOMAIN,
SERVICE_RECONNECT,
bot.
async_handle_reconnect,
schema=vol.Schema({}))
intent.async_register(hass, HelpIntent(hass)) intent.async_register(hass, HelpIntent(hass))
return True return True

View File

@ -39,6 +39,7 @@ CONF_CONVERSATION_NAME = 'name'
SERVICE_SEND_MESSAGE = 'send_message' SERVICE_SEND_MESSAGE = 'send_message'
SERVICE_UPDATE = 'update' SERVICE_UPDATE = 'update'
SERVICE_RECONNECT = 'reconnect'
TARGETS_SCHEMA = vol.All( TARGETS_SCHEMA = vol.All(

View File

@ -313,6 +313,11 @@ class HangoutsBot:
"""Handle the update_users_and_conversations service.""" """Handle the update_users_and_conversations service."""
await self._async_list_conversations() await self._async_list_conversations()
async def async_handle_reconnect(self, _=None):
"""Handle the reconnect service."""
await self.async_disconnect()
await self.async_connect()
def get_intents(self, conv_id): def get_intents(self, conv_id):
"""Return the intents for a specific conversation.""" """Return the intents for a specific conversation."""
return self._conversation_intents.get(conv_id) return self._conversation_intents.get(conv_id)

View File

@ -1,5 +1,5 @@
update: update:
description: Updates the list of users and conversations. description: Updates the list of conversations.
send_message: send_message:
description: Send a notification to a specific target. description: Send a notification to a specific target.
@ -13,3 +13,6 @@ send_message:
data: data:
description: Other options ['image_file' / 'image_url'] description: Other options ['image_file' / 'image_url']
example: '{ "image_file": "file" } or { "image_url": "url" }' example: '{ "image_file": "file" } or { "image_url": "url" }'
reconnect:
description: Reconnect the bot.