Skip to content

Commit

Permalink
Remove unnecessary websocket functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shbatm committed May 24, 2020
1 parent 9ceaf32 commit ff447f7
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions pyisy/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"Origin": "com.universal-devices.websockets.isy",
}
WS_HEARTBEAT = 60
WS_TIMEOUT = aiohttp.ClientTimeout(total=60, connect=60, sock_connect=60, sock_read=60)
WS_TIMEOUT = 60
WS_MAX_RETRIES = 4
WS_RETRY_BACKOFF = [0.01, 1, 10, 30, 60] # Seconds

Expand Down Expand Up @@ -474,52 +474,38 @@ async def websocket(self, retries=0):
) as ws:
self.status = ES_CONNECTED
retries = 0
_LOGGER.debug("Successfully connected to websocket... %s", self.status)
_LOGGER.debug("Successfully connected to websocket.")

async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
await self._route_message(msg.data)

elif msg.type == aiohttp.WSMsgType.CLOSED:
_LOGGER.warning("Websocket connection closed: %s", msg.data)
await ws.close()
break

elif msg.type == aiohttp.WSMsgType.ERROR:
_LOGGER.error("Websocket error: %s", ws.exception())
break

elif msg.type == aiohttp.WSMsgType.PING:
_LOGGER.debug("Websocket ping received.")
ws.pong()

elif msg.type == aiohttp.WSMsgType.PONG:
_LOGGER.debug("Websocket pong received.")

elif msg.type == aiohttp.WSMsgType.BINARY:
_LOGGER.warning("Unexpected binary message received.")

self.status = ES_DISCONNECTED

except (
aiohttp.ClientConnectorError,
aiohttp.ClientOSError,
aiohttp.client_exceptions.ServerDisconnectedError,
):
_LOGGER.debug("ISY not ready or closed connection. Retrying.")
await self.reconnect(WS_RETRY_BACKOFF[retries], retries=retries)
except aiohttp.ClientConnectorError:
if self.status != ES_STOP_UPDATES:
_LOGGER.error("Websocket Client Connector Error.")
self.status = ES_LOST_STREAM_CONNECTION
await self.reconnect(RECONNECT_DELAY)
await self.reconnect(WS_RETRY_BACKOFF[retries], retries=retries)
except asyncio.CancelledError:
self.status = ES_DISCONNECTED
except Exception as err:
if self.status != ES_STOP_UPDATES:
_LOGGER.exception("Unexpected error %s", err)
_LOGGER.exception("Unexpected websocket error %s", err)
self.status = ES_LOST_STREAM_CONNECTION
await self.reconnect(RECONNECT_DELAY)
await self.reconnect(WS_RETRY_BACKOFF[retries], retries=retries)
else:
if self.status != ES_STOP_UPDATES:
self.status = ES_DISCONNECTED
await self.reconnect(RECONNECT_DELAY)
await self.reconnect(WS_RETRY_BACKOFF[retries], retries=retries)

0 comments on commit ff447f7

Please sign in to comment.