Exemple #1
0
        public RestHandlerResult DoDeviceListing()
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(UserListDevices, Method.GET);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                _log.Error($"Could not fetch devices from Melcloud: {e.Message}");
                result.Error = e.Message;
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            else
            {
                if (!string.IsNullOrEmpty(result.Response.ErrorMessage))
                {
                    result.Error = result.Response.ErrorMessage;
                }
            }

            return(result);
        }
Exemple #2
0
        public RestHandlerResult Login(string melcloudEmail, string melcloudPassword)
        {
            var result = new RestHandlerResult(_log);

            _contextKey     = null;         //Reset context key
            _httpStatusCode = 0;
            var request = RequestBasis(ClientLogin);

            request.Parameters.Clear();
            request.AddJsonBody(new
            {
                Email           = melcloudEmail,
                Password        = melcloudPassword,
                Language        = 0,
                AppVersion      = "1.16.1.2",
                Persist         = "false",
                CaptchaResponse = ""
            });
            IRestResponse response = null;

            try
            {
                response = _client.Execute(request);
                _log.Debug(response.Content);
                result.Response = response;
                IsConnected     = response.IsSuccessful;
            }
            catch (Exception ex)
            {
                _log.Info("Could not login to Melcloud" + ex);
                result.Success = false;
                IsConnected    = false;
                result.Error   = ex.Message;
            }

            if (ResponseIsOk(response))
            {
                _log.Debug("Got a successful response from Melcloud");

                CheckForLoginErrorAndGetContext(response);
                result.Success = true;
                result.WrongUsernameOrPassword = WrongUsernamePassword;
            }

            return(result);
        }
Exemple #3
0
        public RestHandlerResult UpdateDevice(object jsonObject)
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(DeviceSetAta);

            request.AddJsonBody(jsonObject);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result.Error = $"Tried to save device to Melcloud but got an error: {e.Message}";
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            return(result);
        }
Exemple #4
0
        public RestHandlerResult DoDeviceGet(JToken deviceId, JToken buildingId)
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(DeviceGet, Method.GET);

            request.AddParameter("id", deviceId);
            request.AddParameter("buildingID", buildingId);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                _log.Error($"Could not fetch data for updating devices from Melcloud: {e.Message}");
                result.Error = e.Message;
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            return(result);
        }