From 8de79ed57c59f6c3dcd8659ef120e8581147fe8d Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Mon, 5 Nov 2018 13:14:22 +0100 Subject: [PATCH] add service to reconnect the bot (#18142) --- homeassistant/components/hangouts/__init__.py | 8 +++++++- homeassistant/components/hangouts/const.py | 1 + homeassistant/components/hangouts/hangouts_bot.py | 5 +++++ homeassistant/components/hangouts/services.yaml | 5 ++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hangouts/__init__.py b/homeassistant/components/hangouts/__init__.py index 5d8a167d2d9..01d81cc466c 100644 --- a/homeassistant/components/hangouts/__init__.py +++ b/homeassistant/components/hangouts/__init__.py @@ -22,7 +22,7 @@ from .const import ( SERVICE_UPDATE, CONF_SENTENCES, CONF_MATCHERS, CONF_ERROR_SUPPRESSED_CONVERSATIONS, INTENT_SCHEMA, TARGETS_SCHEMA, 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. from .config_flow import HangoutsFlowHandler # noqa: F401 @@ -130,6 +130,12 @@ async def async_setup_entry(hass, config): async_handle_update_users_and_conversations, schema=vol.Schema({})) + hass.services.async_register(DOMAIN, + SERVICE_RECONNECT, + bot. + async_handle_reconnect, + schema=vol.Schema({})) + intent.async_register(hass, HelpIntent(hass)) return True diff --git a/homeassistant/components/hangouts/const.py b/homeassistant/components/hangouts/const.py index 5a527fae260..cf5374c317e 100644 --- a/homeassistant/components/hangouts/const.py +++ b/homeassistant/components/hangouts/const.py @@ -39,6 +39,7 @@ CONF_CONVERSATION_NAME = 'name' SERVICE_SEND_MESSAGE = 'send_message' SERVICE_UPDATE = 'update' +SERVICE_RECONNECT = 'reconnect' TARGETS_SCHEMA = vol.All( diff --git a/homeassistant/components/hangouts/hangouts_bot.py b/homeassistant/components/hangouts/hangouts_bot.py index ed041a30ce6..748079452d8 100644 --- a/homeassistant/components/hangouts/hangouts_bot.py +++ b/homeassistant/components/hangouts/hangouts_bot.py @@ -313,6 +313,11 @@ class HangoutsBot: """Handle the update_users_and_conversations service.""" 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): """Return the intents for a specific conversation.""" return self._conversation_intents.get(conv_id) diff --git a/homeassistant/components/hangouts/services.yaml b/homeassistant/components/hangouts/services.yaml index d07f1d65688..26a7193493b 100644 --- a/homeassistant/components/hangouts/services.yaml +++ b/homeassistant/components/hangouts/services.yaml @@ -1,5 +1,5 @@ update: - description: Updates the list of users and conversations. + description: Updates the list of conversations. send_message: description: Send a notification to a specific target. @@ -13,3 +13,6 @@ send_message: data: description: Other options ['image_file' / 'image_url'] example: '{ "image_file": "file" } or { "image_url": "url" }' + +reconnect: + description: Reconnect the bot. \ No newline at end of file