Refactor models

This commit is contained in:
2019-08-07 18:25:56 -04:00
parent e93ec7f09a
commit 03cff3533c
4 changed files with 81 additions and 61 deletions

View File

@@ -0,0 +1,11 @@
using JetBrains.Annotations;
namespace ChrisKaczor.HomeMonitor.Weather.Models
{
[PublicAPI]
public enum MessageType
{
Text,
Data
}
}

View File

@@ -7,71 +7,12 @@ using System.Linq;
namespace ChrisKaczor.HomeMonitor.Weather.Models namespace ChrisKaczor.HomeMonitor.Weather.Models
{ {
public enum MessageType
{
Text,
Data
}
[PublicAPI] [PublicAPI]
public enum WindDirection public class WeatherMessage : WeatherReading
{
None = -1,
North = 0,
East = 90,
South = 180,
West = 270,
NorthEast = 45,
SouthEast = 135,
SouthWest = 225,
NorthWest = 315,
NorthNorthEast = 23,
EastNorthEast = 68,
EastSouthEast = 113,
SouthSouthEast = 158,
SouthSouthWest = 203,
WestSouthWest = 248,
WestNorthWest = 293,
NorthNorthWest = 338
}
[PublicAPI]
public class WeatherMessage
{ {
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public MessageType Type { get; set; } public MessageType Type { get; set; }
public DateTimeOffset Timestamp { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public WindDirection WindDirection { get; set; }
public decimal WindSpeed { get; set; }
public decimal Humidity { get; set; }
public decimal HumidityTemperature { get; set; }
public decimal Rain { get; set; }
public decimal Pressure { get; set; }
public decimal PressureTemperature { get; set; }
public decimal BatteryLevel { get; set; }
public decimal LightLevel { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public decimal Altitude { get; set; }
public int SatelliteCount { get; set; }
public DateTimeOffset GpsTimestamp { get; set; }
public string Message { get; set; } public string Message { get; set; }
public WeatherMessage() public WeatherMessage()
@@ -92,7 +33,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
var messageValues = messageParts.Select(m => m.Split('=')).ToDictionary(a => a[0], a => a[1]); var messageValues = messageParts.Select(m => m.Split('=')).ToDictionary(a => a[0], a => a[1]);
WindDirection = (WindDirection) Enum.Parse(typeof(WindDirection), messageValues[@"winddir"]); WindDirection = (WindDirection)Enum.Parse(typeof(WindDirection), messageValues[@"winddir"]);
WindSpeed = decimal.Parse(messageValues[@"windspeedmph"]); WindSpeed = decimal.Parse(messageValues[@"windspeedmph"]);
Humidity = decimal.Parse(messageValues[@"humidity"]); Humidity = decimal.Parse(messageValues[@"humidity"]);
HumidityTemperature = decimal.Parse(messageValues[@"tempH"]); HumidityTemperature = decimal.Parse(messageValues[@"tempH"]);

View File

@@ -0,0 +1,42 @@
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
namespace ChrisKaczor.HomeMonitor.Weather.Models
{
[PublicAPI]
public class WeatherReading
{
public DateTimeOffset Timestamp { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public WindDirection WindDirection { get; set; }
public decimal WindSpeed { get; set; }
public decimal Humidity { get; set; }
public decimal HumidityTemperature { get; set; }
public decimal Rain { get; set; }
public decimal Pressure { get; set; }
public decimal PressureTemperature { get; set; }
public decimal BatteryLevel { get; set; }
public decimal LightLevel { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public decimal Altitude { get; set; }
public int SatelliteCount { get; set; }
public DateTimeOffset GpsTimestamp { get; set; }
}
}

View File

@@ -0,0 +1,26 @@
using JetBrains.Annotations;
namespace ChrisKaczor.HomeMonitor.Weather.Models
{
[PublicAPI]
public enum WindDirection
{
None = -1,
North = 0,
East = 90,
South = 180,
West = 270,
NorthEast = 45,
SouthEast = 135,
SouthWest = 225,
NorthWest = 315,
NorthNorthEast = 23,
EastNorthEast = 68,
EastSouthEast = 113,
SouthSouthEast = 158,
SouthSouthWest = 203,
WestSouthWest = 248,
WestNorthWest = 293,
NorthNorthWest = 338
}
}