private void DigitalEvent(byte[] baPayload) { ushort idx = (ushort)((baPayload[5] & 0x7F) * 0x100 + baPayload[4] + 1); bool val = !StringHelper.GetBit(baPayload[5], 7); OnDebug(eDebugEventType.Info, "Digital event on join={0} to {1}", idx.ToString(), val.ToString()); OnDigital?.Invoke(idx, val); }
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); } }