Пример #1
0
        private void SendForecast(ForecastTime fr, int num)
        {
            ushort tempJoin    = (ushort)(1 + num - 1);
            ushort weatherJoin = (ushort)(2 + num - 1);
            ushort iconJoin    = (ushort)(5 + num - 1);
            ushort timeJoin    = (ushort)(5 + num - 1);
            ushort tempSJoin   = (ushort)(9 + num);

            OnAnalog?.Invoke(tempJoin, (ushort)(fr.Temperature.Value * 10));
            OnSerial?.Invoke(weatherJoin, fr.Symbol.Name);
            OnAnalog?.Invoke(iconJoin, IconToCrestronVT(fr.Symbol.Var, fr.To));
            string sTime = fr.To.ToString("t") + (fr.To.Day == DateTime.Now.Day ? "" : " (+1)");

            OnSerial?.Invoke(timeJoin, sTime);
            OnSerial?.Invoke(tempSJoin, Math.Round(fr.Temperature.Value, 1).ToString() + "°");
        }
Пример #2
0
        private async void GetForecast()
        {
            OnDigital?.Invoke(1, false);
            try
            {
                var cw = await owmClient.CurrentWeather.GetByName(Settings.City, MetricSystem.Metric, OpenWeatherMapLanguage.RU);

                var fw = await owmClient.Forecast.GetByName(Settings.City, false, MetricSystem.Metric, OpenWeatherMapLanguage.RU);

                SunRise = fw.Sun.Rise.ToLocalTime().TimeOfDay;
                SunSet  = fw.Sun.Set.ToLocalTime().TimeOfDay;

                OnAnalog?.Invoke(4, IconToCrestronVT(cw.Weather.Icon, DateTime.Now));
                OnSerial?.Invoke(1, cw.Weather.Value);
                OnSerial?.Invoke(8, SunRise.ToString(@"h\:mm"));
                OnSerial?.Invoke(9, SunSet.ToString(@"h\:mm"));

                OnAnalog?.Invoke(8, (ushort)cw.Humidity.Value);
                OnAnalog?.Invoke(9, (ushort)cw.Wind.Speed.Value);

                DateTime fr1;
                DateTime fr2;
                DateTime fr3;

                DateTime curr = DateTime.Now;

                int hr = curr.Hour;
                if (hr < 5)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 6, 0, 0);
                    fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0);
                    fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0);
                }
                else if (hr < 8)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0);
                    fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0);
                    fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0);
                }
                else if (hr < 11)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0);
                    fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 15, 0, 0);
                    fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0);
                }
                else if (hr < 14)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 15, 0, 0);
                    fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0);
                    fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0);
                }
                else if (hr < 17)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0);
                    fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0);
                    fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 0, 0, 0)).AddDays(1);
                }
                else if (hr < 20)
                {
                    fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0);
                    fr2 = (new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0)).AddDays(1);
                    fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0)).AddDays(1);
                }
                else
                {
                    fr1 = (new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0)).AddDays(1);
                    fr2 = (new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0)).AddDays(1);
                    fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0)).AddDays(1);
                }
                var fw1 = fw.Forecast.FirstOrDefault(o => o.To == fr1);
                var fw2 = fw.Forecast.FirstOrDefault(o => o.To == fr2);
                var fw3 = fw.Forecast.FirstOrDefault(o => o.To == fr3);
                SendForecast(fw1, 1);
                SendForecast(fw2, 2);
                SendForecast(fw3, 3);
            }
            catch
            {
                OnDigital?.Invoke(1, true);
            }
        }