mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Update for new hardware
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
*.user
|
||||
|
||||
bin/
|
||||
log/
|
||||
obj/
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Weather.Models
|
||||
@@ -33,22 +32,28 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
||||
|
||||
var messageValues = messageParts.Select(m => m.Split('=')).ToDictionary(a => a[0], a => a[1]);
|
||||
|
||||
WindDirection = (WindDirection)Enum.Parse(typeof(WindDirection), messageValues[@"winddir"]);
|
||||
WindSpeed = decimal.Parse(messageValues[@"windspeedmph"]);
|
||||
Humidity = decimal.Parse(messageValues[@"humidity"]);
|
||||
HumidityTemperature = decimal.Parse(messageValues[@"tempH"]);
|
||||
Rain = decimal.Parse(messageValues[@"rain"]);
|
||||
Pressure = decimal.Parse(messageValues[@"pressure"]);
|
||||
PressureTemperature = decimal.Parse(messageValues[@"tempP"]);
|
||||
BatteryLevel = decimal.Parse(messageValues[@"batt_lvl"]);
|
||||
LightLevel = decimal.Parse(messageValues[@"light_lvl"]);
|
||||
Latitude = decimal.Parse(messageValues[@"lat"]);
|
||||
Longitude = decimal.Parse(messageValues[@"lng"]);
|
||||
Altitude = decimal.Parse(messageValues[@"altitude"]);
|
||||
SatelliteCount = int.Parse(messageValues[@"sats"]);
|
||||
WindDirection = GetWindDirection(double.Parse(messageValues[@"wd"]));
|
||||
WindSpeed = decimal.Parse(messageValues[@"ws"]);
|
||||
Humidity = decimal.Parse(messageValues[@"sh"]);
|
||||
HumidityTemperature = decimal.Parse(messageValues[@"st"]);
|
||||
Rain = decimal.Parse(messageValues[@"r"]);
|
||||
Pressure = decimal.Parse(messageValues[@"bp"]);
|
||||
PressureTemperature = decimal.Parse(messageValues[@"bt"]);
|
||||
LightLevel = decimal.Parse(messageValues[@"tl"]);
|
||||
Latitude = decimal.Parse(messageValues[@"glt"]);
|
||||
Longitude = decimal.Parse(messageValues[@"gln"]);
|
||||
Altitude = decimal.Parse(messageValues[@"ga"]);
|
||||
SatelliteCount = int.Parse(messageValues[@"gs"]);
|
||||
|
||||
DateTimeOffset.TryParseExact($"{messageValues[@"date"]} {messageValues[@"time"]}", "MM/dd/yyyy HH:mm:ss", null, DateTimeStyles.None, out var gpsTimestamp);
|
||||
GpsTimestamp = gpsTimestamp;
|
||||
var year = int.Parse(messageValues[@"gdy"]) + 2000;
|
||||
var month = int.Parse(messageValues[@"gdm"]);
|
||||
var day = int.Parse(messageValues[@"gdd"]);
|
||||
|
||||
var hour = int.Parse(messageValues[@"gth"]);
|
||||
var minute = int.Parse(messageValues[@"gtm"]);
|
||||
var second = int.Parse(messageValues[@"gts"]);
|
||||
|
||||
GpsTimestamp = new DateTimeOffset(year, month, day, hour, minute, second, 0, TimeSpan.Zero);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
@@ -59,5 +64,61 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
||||
|
||||
return new WeatherMessage { Message = message };
|
||||
}
|
||||
|
||||
private static WindDirection GetWindDirection(double degrees)
|
||||
{
|
||||
switch (degrees)
|
||||
{
|
||||
case 0:
|
||||
return WindDirection.North;
|
||||
|
||||
case 22.5:
|
||||
return WindDirection.NorthNorthEast;
|
||||
|
||||
case 45:
|
||||
return WindDirection.NorthEast;
|
||||
|
||||
case 67.5:
|
||||
return WindDirection.EastNorthEast;
|
||||
|
||||
case 90:
|
||||
return WindDirection.East;
|
||||
|
||||
case 112.5:
|
||||
return WindDirection.EastSouthEast;
|
||||
|
||||
case 135:
|
||||
return WindDirection.SouthEast;
|
||||
|
||||
case 157.5:
|
||||
return WindDirection.SouthSouthEast;
|
||||
|
||||
case 180:
|
||||
return WindDirection.South;
|
||||
|
||||
case 202.5:
|
||||
return WindDirection.SouthSouthWest;
|
||||
|
||||
case 225:
|
||||
return WindDirection.SouthWest;
|
||||
|
||||
case 247.5:
|
||||
return WindDirection.WestSouthWest;
|
||||
|
||||
case 270:
|
||||
return WindDirection.West;
|
||||
|
||||
case 292.5:
|
||||
return WindDirection.WestNorthWest;
|
||||
|
||||
case 315:
|
||||
return WindDirection.NorthWest;
|
||||
|
||||
case 337.5:
|
||||
return WindDirection.NorthNorthWest;
|
||||
}
|
||||
|
||||
return WindDirection.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,6 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
||||
|
||||
public decimal PressureTemperature { get; set; }
|
||||
|
||||
public decimal BatteryLevel { get; set; }
|
||||
|
||||
public decimal LightLevel { get; set; }
|
||||
|
||||
public decimal Latitude { get; set; }
|
||||
|
||||
@@ -5,22 +5,22 @@ 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
|
||||
None,
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
NorthEast,
|
||||
SouthEast,
|
||||
SouthWest,
|
||||
NorthWest,
|
||||
NorthNorthEast,
|
||||
EastNorthEast,
|
||||
EastSouthEast,
|
||||
SouthSouthEast,
|
||||
SouthSouthWest,
|
||||
WestSouthWest,
|
||||
WestNorthWest,
|
||||
NorthNorthWest
|
||||
}
|
||||
}
|
||||
|
||||
20
Weather/ModelsTests/ModelsTests.csproj
Normal file
20
Weather/ModelsTests/ModelsTests.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
33
Weather/ModelsTests/WeatherMessageTests.cs
Normal file
33
Weather/ModelsTests/WeatherMessageTests.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using ChrisKaczor.HomeMonitor.Weather.Models;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ModelsTests
|
||||
{
|
||||
[TestClass]
|
||||
public class WeatherMessageTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ParseTest()
|
||||
{
|
||||
var weatherMessage = WeatherMessage.Parse("$,ws=1.80,wg=1.15,wd=180.00,r=0.01,bt=14.44,bp=1016.76,tl=597.83,st=9.68,sh=78.95,gf=1,gs=13,glt=42.764725,gln=-71.042038,ga=20.70,gth=22,gtm=20,gts=11,gdy=21,gdm=5,gdd=28,#");
|
||||
|
||||
Assert.AreEqual(MessageType.Data, weatherMessage.Type);
|
||||
|
||||
Assert.AreEqual(WindDirection.South, weatherMessage.WindDirection);
|
||||
Assert.AreEqual(1.80M, weatherMessage.WindSpeed);
|
||||
Assert.AreEqual(42.764725M, weatherMessage.Latitude);
|
||||
Assert.AreEqual(-71.042038M, weatherMessage.Longitude);
|
||||
Assert.AreEqual(1016.76M, weatherMessage.Pressure);
|
||||
Assert.AreEqual(14.44M, weatherMessage.PressureTemperature);
|
||||
Assert.AreEqual(0.01M, weatherMessage.Rain);
|
||||
Assert.AreEqual(9.68M, weatherMessage.HumidityTemperature);
|
||||
Assert.AreEqual(78.95M, weatherMessage.Humidity);
|
||||
Assert.AreEqual(13, weatherMessage.SatelliteCount);
|
||||
Assert.AreEqual(20.70M, weatherMessage.Altitude);
|
||||
Assert.AreEqual(1.80M, weatherMessage.WindSpeed);
|
||||
Assert.AreEqual(597.83M, weatherMessage.LightLevel);
|
||||
Assert.AreEqual(DateTimeOffset.Parse("2021-05-28 22:20:11 +00:00"), weatherMessage.GpsTimestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerialReader", "SerialReade
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{39E5DE26-CD8D-47AF-AB94-6ACB0AF24EA1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelsTests", "ModelsTests\ModelsTests.csproj", "{F83A3E8C-3A03-4264-B136-1FBE569A9411}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -27,6 +29,10 @@ Global
|
||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=Locals/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=EnumMember/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=Property/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:Int64 x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/AutoNamingCompletedVersion/@EntryValue">2</s:Int64></wpf:ResourceDictionary>
|
||||
Reference in New Issue
Block a user