           throw error
 
   logIn: ->
+    # Makes sure there is not session id left.
+    delete @sessionId
+
     @sessionId = @call 'session.login_with_password', @username, @password
 
 #=====================================================================

  call: (method, args...) ->
    @connect() unless @xmlrpc

    args.unshift @sessionId if @sessionId

    tries = @tries
    do helper = =>
      try
        result = $wait (callback) =>
          @xmlrpc.methodCall method, args, callback

        # Returns the plain result if it does not have a valid XAPI format.
        return result unless result.Status?

    if !force and (hostname is @xmlrpc?.options.host)
      return

    @xmlrpc = $xmlrpc.createSecureClient {
      host: hostname
      port: port ? 443
