Example #1
0
        public static Tuple <bool, ClimateInfo> GetPrediction(RealtimeClimateInfo realtimeClimateInfo, string longitude, string latitude)
        {
            var url     = $"http://api.caiyunapp.com/v2/{key}/{longitude},{latitude}/forecast.json";
            var getData = "unit=metric:v2";
            var result  = HttpHelper.HttpGet($"{url}?{getData}");

            if (JsonHelper.GetString(result, "status") != "ok")
            {
                LogHelper.Error("获取天气预报信息错误:" + result);
                return(null);
            }

            realtimeClimateInfo.ClimateDescription = JsonHelper.GetString(result, "result", "hourly", "description");
            realtimeClimateInfo.RainDescription    = JsonHelper.GetString(result, "result", "minutely", "description");
            var climateInfo = new ClimateInfo();

            climateInfo.Temperatures   = JsonHelper.Get <List <Dictionary <string, string> > >(result, "result", "daily", "temperature");
            climateInfo.AQIs           = JsonHelper.Get <List <Dictionary <string, string> > >(result, "result", "daily", "aqi");
            climateInfo.PMs            = JsonHelper.Get <List <Dictionary <string, string> > >(result, "result", "daily", "pm25");
            climateInfo.Skycons        = JsonHelper.Get <List <Dictionary <string, string> > >(result, "result", "daily", "skycon");
            climateInfo.Precipitations = JsonHelper.Get <List <Dictionary <string, string> > >(result, "result", "daily", "precipitation");

            return(new Tuple <bool, ClimateInfo>(true, climateInfo));
        }
Example #2
0
 private void ShowClimateInfo(ClimateInfo climateInfo)
 {
     Console.WriteLine($"Current temperature is: {climateInfo.Temperature}°C and humidity: {climateInfo.Humidity}%");
 }
 /// <summary>
 /// Установить обновленное значение датчиков
 /// </summary>
 /// <param name="climateInfo">Информация о климате</param>
 public void SetSensorsData(ClimateInfo climateInfo)
 {
     _climateInfo = climateInfo;
     DataChanged();
 }