-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherData.cs
209 lines (186 loc) · 10.5 KB
/
WeatherData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
namespace Davis2Mqtt
{
public class WeatherData
{
public List<WeatherDataItem> WeatherDataItems = new List<WeatherDataItem>();
public WeatherData()
{
WeatherDataItems.Add(new WeatherDataItem("BarometricTrend", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("Barometer", DataType.BAROMETER));
WeatherDataItems.Add(new WeatherDataItem("InsideTemperature", DataType.TEMP));
WeatherDataItems.Add(new WeatherDataItem("InsideHumidity", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("OutsideTemperature", DataType.TEMP));
WeatherDataItems.Add(new WeatherDataItem("WindSpeed", DataType.WIND));
WeatherDataItems.Add(new WeatherDataItem("WindSpeed10MinAvg", DataType.WIND));
WeatherDataItems.Add(new WeatherDataItem("WindDirectionNamed", DataType.DIRECTION));
WeatherDataItems.Add(new WeatherDataItem("WindDirection", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("ExtraTemperatures", DataType.TEMP));
//WeatherDataItems.Add(new WeatherDataItem("SoilTemperatures", DataType.TEMP));
//WeatherDataItems.Add(new WeatherDataItem("LeafTemperatures", DataType.TEMP));
WeatherDataItems.Add(new WeatherDataItem("OutsideHumidity", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("ExtraHumidities", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("RainRate", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("UV", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("SolarRadiation", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("StormRain", DataType.RAIN));
//WeatherDataItems.Add(new WeatherDataItem("StartDateofcurrentStorm", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("RainDay", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("RainMonth", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("RainYear", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("DayET", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("MonthET", DataType.RAIN));
WeatherDataItems.Add(new WeatherDataItem("YearET", DataType.RAIN));
//WeatherDataItems.Add(new WeatherDataItem("SoilMoistures", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("LeafWetnesses", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("InsideAlarms", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("RainAlarms", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("OutsideAlarms", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("ExtraTempHumAlarms", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("SoilLeafAlarms", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("TransmitterBatteryStatus", DataType.OTHER));
WeatherDataItems.Add(new WeatherDataItem("ConsoleBatteryVoltage", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("ForecastIcons", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("ForecastRulenumber", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("TimeOfSunrise", DataType.OTHER));
//WeatherDataItems.Add(new WeatherDataItem("TimeOfSunset", DataType.OTHER));
}
internal void Update(WeatherLinkHandler weather)
{
WeatherLoopData weatherLoopData = weather.Data;
if (weatherLoopData == null)
return;
WeatherDataItems.Find(x => x.Name == "BarometricTrend").RawValueUpdate(weatherLoopData.BarometerTrend);
WeatherDataItems.Find(x => x.Name == "Barometer").RawValueUpdate(weatherLoopData.Barometer);
WeatherDataItems.Find(x => x.Name == "InsideTemperature").RawValueUpdate(weatherLoopData.InsideTemperature);
WeatherDataItems.Find(x => x.Name == "InsideHumidity").RawValueUpdate(weatherLoopData.InsideHumidity);
WeatherDataItems.Find(x => x.Name == "OutsideTemperature").RawValueUpdate(weatherLoopData.OutsideTemperature);
WeatherDataItems.Find(x => x.Name == "WindSpeed").RawValueUpdate(weatherLoopData.WindSpeed);
WeatherDataItems.Find(x => x.Name == "WindSpeed10MinAvg").RawValueUpdate(weatherLoopData.WindSpeed10MinAvg);
WeatherDataItems.Find(x => x.Name == "WindDirectionNamed").RawValueUpdate(weatherLoopData.WindDirection);
WeatherDataItems.Find(x => x.Name == "WindDirection").RawValueUpdate(weatherLoopData.WindDirection);
WeatherDataItems.Find(x => x.Name == "OutsideHumidity").RawValueUpdate(weatherLoopData.OutsideHumidity);
WeatherDataItems.Find(x => x.Name == "RainRate").RawValueUpdate(weatherLoopData.RainRate);
WeatherDataItems.Find(x => x.Name == "UV").RawValueUpdate(weatherLoopData.UV);
WeatherDataItems.Find(x => x.Name == "SolarRadiation").RawValueUpdate(weatherLoopData.SolarRadiation);
WeatherDataItems.Find(x => x.Name == "StormRain").RawValueUpdate(weatherLoopData.StormRain);
WeatherDataItems.Find(x => x.Name == "RainDay").RawValueUpdate(weatherLoopData.RainDay);
WeatherDataItems.Find(x => x.Name == "RainMonth").RawValueUpdate(weatherLoopData.RainMonth);
WeatherDataItems.Find(x => x.Name == "RainYear").RawValueUpdate(weatherLoopData.RainYear);
WeatherDataItems.Find(x => x.Name == "DayET").RawValueUpdate(weatherLoopData.DayET);
WeatherDataItems.Find(x => x.Name == "MonthET").RawValueUpdate(weatherLoopData.MonthET);
WeatherDataItems.Find(x => x.Name == "YearET").RawValueUpdate(weatherLoopData.YearET);
WeatherDataItems.Find(x => x.Name == "ConsoleBatteryVoltage").RawValueUpdate(weatherLoopData.ConsoleBatteryVoltage);
}
}
public enum DataType { TEMP, WIND, BAROMETER, DIRECTION, RAIN, OTHER }
public class WeatherDataItem
{
public string Name { get; set; }
public DataType Type { get; set; }
public object RawValue { get; set; }
public bool Published { get; set; }
public DateTime Updated { get; set; }
public WeatherDataItem(string Name, DataType Type)
{
this.Name = Name;
this.Type = Type;
RawValue = string.Empty;
Published = false;
Updated = DateTime.Now;
}
internal void RawValueUpdate(object newRawValue)
{
if (!RawValue.Equals(newRawValue))
{
RawValue = newRawValue;
Updated = DateTime.Now;
Published = false;
}
}
public string Value
{
get
{
string value = "";
if (Type == DataType.BAROMETER)
value = ConvertToHectopascal;
else if (Type == DataType.DIRECTION)
value = ConvertToDirectionName;
else if (Type == DataType.TEMP)
value = ConvertToDegreeCelcius;
else if (Type == DataType.WIND)
value = ConvertToMetersPrSecond;
else if (Type == DataType.RAIN)
value = ConvertToMillimeters;
else
value = RawValue.ToString();
return value.Replace(",", ".");
}
}
private string ConvertToDirectionName
{
get
{
if (RawValue.ToString() == string.Empty)
return "--";
// The wind direction is given in degrees - 0-359 - convert to string representing the direction
if (Convert.ToSingle(RawValue) < 11.25f) return "N";
else if (Convert.ToSingle(RawValue) < 11.25f) return "N";
else if (Convert.ToSingle(RawValue) < 33.75f) return "NNE";
else if (Convert.ToSingle(RawValue) < 56.25f) return "NE";
else if (Convert.ToSingle(RawValue) < 78.75f) return "ENE";
else if (Convert.ToSingle(RawValue) < 101.25f) return "E";
else if (Convert.ToSingle(RawValue) < 123.75f) return "ESE";
else if (Convert.ToSingle(RawValue) < 146.25f) return "SE";
else if (Convert.ToSingle(RawValue) < 168.75f) return "SSE";
else if (Convert.ToSingle(RawValue) < 191.25f) return "S";
else if (Convert.ToSingle(RawValue) < 213.75f) return "SSW";
else if (Convert.ToSingle(RawValue) < 236.25f) return "SW";
else if (Convert.ToSingle(RawValue) < 258.75f) return "WSW";
else if (Convert.ToSingle(RawValue) < 281.25f) return "W";
else if (Convert.ToSingle(RawValue) < 303.75f) return "WNW";
else if (Convert.ToSingle(RawValue) < 326.25f) return "NW";
else if (Convert.ToSingle(RawValue) < 348.75f) return "NNW";
else return "N";
}
}
private string ConvertToDegreeCelcius
{
get
{
if (RawValue.ToString() == string.Empty)
return "";
return Math.Round(((Convert.ToSingle(RawValue) - 32) * 5 / 9), 1).ToString();
}
}
private string ConvertToMetersPrSecond
{
get
{
if (RawValue.ToString() == string.Empty)
return "";
return Math.Round((Convert.ToSingle(RawValue) * 0.44704f), 1).ToString();
}
}
private string ConvertToHectopascal
{
get
{
if (RawValue.ToString() == string.Empty)
return "";
return Math.Round((Convert.ToSingle(RawValue) * 33.8639f), 1).ToString();
}
}
private string ConvertToMillimeters
{
get
{
if (RawValue.ToString() == string.Empty)
return "";
return Math.Round((Convert.ToSingle(RawValue) * .2f), 1).ToString(); // Not inches but "clicks"
}
}
}
}