示例#1
0
        /// <summary>
        /// Loads the historical data according to the defined filter.
        /// </summary>
        /// <param name="measuresFilters">List of filters to be applied.</param>
        /// <returns></returns>
        public override async Task LoadMeasuresAsync(MeasuresFilters measuresFilters)
        {
            _valueIndex = 0;
            MeasureScale measureScale = GetScaleFromDateRange(_dateBegin, _dateEnd);

            _measuresData = await _aPICommands.GetMeasure(BaseId, measureScale, measuresFilters, _dateBegin, _dateEnd, Id).ConfigureAwait(false);

            if (_measuresData == null)
            {
                return;
            }
            // Wind
            if (measuresFilters.HasFlag(MeasuresFilters.WindStrength))
            {
                LoadData(_measuresData, HistoryWindStrength);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.WindAngle))
            {
                LoadData(_measuresData, HistoryWindAngle);
            }
            // Gust
            if (measuresFilters.HasFlag(MeasuresFilters.GustStrength))
            {
                LoadData(_measuresData, HistoryGustStrength);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.GustAngle))
            {
                LoadData(_measuresData, HistoryGustAngle);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.DateMaxGust))
            {
                LoadData(_measuresData, HistoryDateMaxGust);
            }
        }
示例#2
0
        /// <summary>
        /// Loads the historical data according to the defined filter.
        /// </summary>
        /// <param name="measuresFilters">List of filters to be applied.</param>
        /// <returns></returns>
        public override async Task LoadMeasuresAsync(MeasuresFilters measuresFilters)
        {
            _valueIndex = 0;
            MeasureScale measureScale = GetScaleFromDateRange(_dateBegin, _dateEnd);

            _measuresData = await _aPICommands.GetMeasure(BaseId, measureScale, measuresFilters, _dateBegin, _dateEnd, Id).ConfigureAwait(false);

            if (_measuresData == null)
            {
                return;
            }
            // Temperatures
            if (measuresFilters.HasFlag(MeasuresFilters.Temperature))
            {
                LoadData(_measuresData, HistoryTemperatures);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.MinTemperature))
            {
                LoadData(_measuresData, HistoryMinTemperatures);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.MaxTemperature))
            {
                LoadData(_measuresData, HistoryMaxTemperatures);
            }
            // Co2
            if (measuresFilters.HasFlag(MeasuresFilters.Co2))
            {
                LoadData(_measuresData, HistoryCo2);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.DateMinCo2))
            {
                LoadData(_measuresData, HistoryDateMinCo2);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.DateMaxCo2))
            {
                LoadData(_measuresData, HistoryDateMaxCo2);
            }
            // Humidity
            if (measuresFilters.HasFlag(MeasuresFilters.Humidity))
            {
                LoadData(_measuresData, HistoryHumidity);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.MinHumidity))
            {
                LoadData(_measuresData, HistoryMinHumidity);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.MaxHumidity))
            {
                LoadData(_measuresData, HistoryMaxHumidity);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.DateMaxHumidity))
            {
                LoadData(_measuresData, HistoryDateMaxHumidity);
            }
        }
示例#3
0
        /// <summary>
        /// Loads the historical data according to the defined filter.
        /// </summary>
        /// <param name="measuresFilters">List of filters to be applied.</param>
        /// <returns></returns>
        public override async Task LoadMeasuresAsync(MeasuresFilters measuresFilters)
        {
            _valueIndex = 0;
            MeasureScale measureScale = GetScaleFromDateRange(_dateBegin, _dateEnd);

            _measuresData = await _aPICommands.GetMeasure(BaseId, measureScale, measuresFilters, _dateBegin, _dateEnd, Id).ConfigureAwait(false);

            if (_measuresData == null)
            {
                return;
            }
            if (measuresFilters.HasFlag(MeasuresFilters.Rain))
            {
                LoadData(_measuresData, HistoryRain);
            }
            if (measuresFilters.HasFlag(MeasuresFilters.SumRain))
            {
                LoadData(_measuresData, HistorySumRain);
            }
        }
示例#4
0
        internal static string ToJsonString(this MeasuresFilters value)
        {
            List <string> filters = new List <string>();

            if (value.HasFlag(MeasuresFilters.Temperature))
            {
                filters.Add("Temperature");
            }
            if (value.HasFlag(MeasuresFilters.Co2))
            {
                filters.Add("CO2");
            }
            if (value.HasFlag(MeasuresFilters.Humidity))
            {
                filters.Add("Humidity");
            }
            if (value.HasFlag(MeasuresFilters.Pressure))
            {
                filters.Add("Pressure");
            }
            if (value.HasFlag(MeasuresFilters.Noise))
            {
                filters.Add("Noise");
            }
            if (value.HasFlag(MeasuresFilters.Rain))
            {
                filters.Add("Rain");
            }
            if (value.HasFlag(MeasuresFilters.WindStrength))
            {
                filters.Add("WindStrength");
            }
            if (value.HasFlag(MeasuresFilters.WindAngle))
            {
                filters.Add("WindAngle");
            }
            if (value.HasFlag(MeasuresFilters.GustStrength))
            {
                filters.Add("GustStrength");
            }
            if (value.HasFlag(MeasuresFilters.GustAngle))
            {
                filters.Add("GustAngle");
            }
            if (value.HasFlag(MeasuresFilters.MinTemperature))
            {
                filters.Add("min_temp");
            }
            if (value.HasFlag(MeasuresFilters.MaxTemperature))
            {
                filters.Add("max_temp");
            }
            if (value.HasFlag(MeasuresFilters.MinHumidity))
            {
                filters.Add("min_hum");
            }
            if (value.HasFlag(MeasuresFilters.MaxHumidity))
            {
                filters.Add("max_hum");
            }
            if (value.HasFlag(MeasuresFilters.MinPressure))
            {
                filters.Add("min_pressure");
            }
            if (value.HasFlag(MeasuresFilters.MaxPressure))
            {
                filters.Add("max_pressure");
            }
            if (value.HasFlag(MeasuresFilters.MinNoise))
            {
                filters.Add("min_noise");
            }
            if (value.HasFlag(MeasuresFilters.MaxNoise))
            {
                filters.Add("max_noise");
            }
            if (value.HasFlag(MeasuresFilters.SumRain))
            {
                filters.Add("sum_rain");
            }
            if (value.HasFlag(MeasuresFilters.DateMaxHumidity))
            {
                filters.Add("date_max_hum");
            }
            if (value.HasFlag(MeasuresFilters.DateMinPressure))
            {
                filters.Add("date_min_pressure");
            }
            if (value.HasFlag(MeasuresFilters.DateMaxPressure))
            {
                filters.Add("date_max_pressure");
            }
            if (value.HasFlag(MeasuresFilters.DateMaxGust))
            {
                filters.Add("date_max_gust");
            }
            if (value.HasFlag(MeasuresFilters.DateMinNoise))
            {
                filters.Add("date_min_noise");
            }
            if (value.HasFlag(MeasuresFilters.DateMaxNoise))
            {
                filters.Add("date_max_noise");
            }
            if (value.HasFlag(MeasuresFilters.DateMinCo2))
            {
                filters.Add("date_min_co2");
            }
            if (value.HasFlag(MeasuresFilters.DateMaxCo2))
            {
                filters.Add("date_max_co2");
            }
            return(String.Join(",", filters.ToArray()));
        }
 /// <summary>
 /// Loads the historical data according to the defined filter.
 /// </summary>
 /// <param name="measuresFilters">List of filters to be applied.</param>
 /// <returns></returns>
 public abstract Task LoadMeasuresAsync(MeasuresFilters measuresFilters);
        internal async Task <RoomMeasures> GetRoomMeasures(string homeId, string roomId, MeasureScale scale, MeasuresFilters measureType, DateTime?dateBegin, DateTime?dateEnd, int limit = 1024)
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["home_id"] = homeId;
            parameters["room_id"] = roomId;
            parameters["scale"]   = scale.ToJsonString();
            parameters["type"]    = measureType.ToJsonString();
            if (dateBegin != null)
            {
                parameters["date_begin"] = dateBegin.FromLocalDateTime().ToString(CultureInfo.InvariantCulture);
            }
            if (dateEnd != null)
            {
                parameters["date_end"] = dateEnd.FromLocalDateTime().ToString(CultureInfo.InvariantCulture);
            }
            parameters["optimize"] = true.ToString(CultureInfo.InvariantCulture).ToUpperInvariant();
            parameters["limit"]    = limit.ToString(CultureInfo.InvariantCulture);

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

                    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);

                    RoomMeasures roomMeasures = new RoomMeasures().FromJson(responseBody);
                    if (roomMeasures.Body == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(roomMeasures);
                }
        }
        internal async Task <MeasuresData> GetMeasure(string deviceId, MeasureScale scale, MeasuresFilters measureType, DateTime?dateBegin, DateTime?dateEnd, string moduleId = "", int limit = 1024)
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["access_token"] = _accessToken;
            parameters["device_id"]    = deviceId;
            parameters["scale"]        = scale.ToJsonString();
            parameters["type"]         = measureType.ToJsonString();
            if (dateBegin != null)
            {
                parameters["date_begin"] = dateBegin.FromLocalDateTime().ToString(CultureInfo.InvariantCulture);
            }
            if (dateEnd != null)
            {
                parameters["date_end"] = dateEnd.FromLocalDateTime().ToString(CultureInfo.InvariantCulture);
            }
            parameters["optimize"] = true.ToString(CultureInfo.InvariantCulture).ToUpperInvariant();
            parameters["limit"]    = limit.ToString(CultureInfo.InvariantCulture);
            if (moduleId.Length > 0)
            {
                parameters["module_id"] = moduleId;
            }

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/getmeasure");
                    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);

                    MeasuresData measuresData = new MeasuresData().FromJson(responseBody);
                    if (measuresData.Content == null)
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(measuresData);
                }
        }