Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch websocket handshake exception #10

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions opsdroid_homeassistant/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def __init__(self, config, opsdroid=None):
self.listening = None
self.discovery_info = None
self.token = self.config.get("token")
self.api_url = urllib.parse.urljoin(self.config.get("url"), "/api/")
self.api_url = urllib.parse.urljoin(self.config.get("url"), "api/")

# The websocket URL can differ depending on how Home Assistant was installed.
# So we will iterate over the various urls when attempting to connect.
self.websocket_urls = [
urllib.parse.urljoin(self.api_url, "websocket"), # Plain Home Assistant
urllib.parse.urljoin(self.config.get("url"), "/websocket"), # Hassio proxy
urllib.parse.urljoin(self.config.get("url"), "websocket"), # Hassio proxy
]
self.id = 1

Expand All @@ -74,7 +74,11 @@ async def listen(self):
elif msg.type == aiohttp.WSMsgType.ERROR:
break
_LOGGER.info("Home Assistant closed the websocket, retrying...")
except aiohttp.client_exceptions.ClientConnectorError:
except (
aiohttp.client_exceptions.ClientConnectorError,
aiohttp.client_exceptions.WSServerHandshakeError,
aiohttp.client_exceptions.ServerDisconnectedError,
):
_LOGGER.info("Unable to connect to Home Assistant, retrying...")
await asyncio.sleep(1)

Expand Down