Пример #1
0
        internal async Task <SimpleAnswer> UnregisterWebHook()
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["app_types"] = "app_security";

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/dropwebhook");

                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
                    request.Content = new StringContent(parameters.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    SimpleAnswer simpleAnswer = new SimpleAnswer().FromJson(responseBody);
                    if (simpleAnswer.Status == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(simpleAnswer);
                }
        }
Пример #2
0
        internal async Task <SimpleAnswer> SetThermMod(string homeId, ThermostatMode thermalMode, DateTime endTime)
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["home_id"] = homeId;
            parameters["mode"]    = thermalMode.FromThermostatMode();
            parameters["endtime"] = endTime.FromLocalDateTime().ToString(CultureInfo.InvariantCulture);

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/setthermmode");

                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
                    request.Content = new StringContent(parameters.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    SimpleAnswer simpleAnswer = new SimpleAnswer().FromJson(responseBody);
                    if (simpleAnswer.Status == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(simpleAnswer);
                }
        }
Пример #3
0
        internal async Task <SimpleAnswer> SetPersonAway(string homeId, string personId = "")
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["home_id"] = homeId;
            if (!string.IsNullOrEmpty(personId))
            {
                parameters["person_id"] = personId;
            }

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/setpersonsaway");

                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
                    request.Content = new StringContent(parameters.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    SimpleAnswer simpleAnswer = new SimpleAnswer().FromJson(responseBody);
                    if (simpleAnswer.Status == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(simpleAnswer);
                }
        }
Пример #4
0
        internal async Task <SimpleAnswer> SetPersonsHome(string homeId, List <string> personIds)
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            PersonsAtHome personsAtHome = new PersonsAtHome()
            {
                HomeId = homeId
            };

            personsAtHome.PersonIds = new List <string>();
            personsAtHome.PersonIds.AddRange(personIds);

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/setpersonshome");

                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
                    request.Content = new StringContent(personsAtHome.ToJson(), Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    SimpleAnswer simpleAnswer = new SimpleAnswer().FromJson(responseBody);
                    if (simpleAnswer.Status == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(simpleAnswer);
                }
        }
Пример #5
0
        internal async Task <bool> UnregisterWebHook()
        {
            SimpleAnswer simpleAnswer = await _aPICommands.UnregisterWebHook().ConfigureAwait(false);

            return(simpleAnswer.Status == "ok");
        }
Пример #6
0
        internal async Task <bool> SetHomeEmpty(string homeId)
        {
            SimpleAnswer simpleAnswer = await _aPICommands.SetPersonAway(homeId).ConfigureAwait(false);

            return(simpleAnswer.Status == "ok");
        }
Пример #7
0
        internal async Task <bool> SetPersonsHome(string homeId, List <string> personIds)
        {
            SimpleAnswer simpleAnswer = await _aPICommands.SetPersonsHome(homeId, personIds).ConfigureAwait(false);

            return(simpleAnswer.Status == "ok");
        }