Skip to content

Commit

Permalink
Ensure websocket connection is cleaned up on connection failure (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Aug 18, 2024
1 parent 66cb4a1 commit b8a1e61
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aioshelly/rpc_device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,17 @@ async def _connect_websocket(self) -> None:
except InvalidAuthError as err:
self._last_error = InvalidAuthError(err)
_LOGGER.debug("host %s:%s: error: %r", ip, port, self._last_error)
await self._wsrpc.disconnect()
raise
except MacAddressMismatchError as err:
self._last_error = err
_LOGGER.debug("host %s:%s: error: %r", ip, port, err)
await self._wsrpc.disconnect()
raise
except (*CONNECT_ERRORS, RpcCallError) as err:
self._last_error = DeviceConnectionError(err)
_LOGGER.debug("host %s:%s: error: %r", ip, port, self._last_error)
await self._wsrpc.disconnect()
raise self._last_error from err
else:
_LOGGER.debug("host %s:%s: RPC device init finished", ip, port)
Expand Down

0 comments on commit b8a1e61

Please sign in to comment.