From fa8608b44b175079da7d5a888ee884b6f9b38565 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Sun, 24 Mar 2019 12:48:33 +0100 Subject: [PATCH] Change CaptorsResponse according to Wiki --- .../Communication/Commands/CaptorValue.cs | 41 +++++++++++++++++++ .../Communication/Commands/CaptorsResponse.cs | 14 +++---- 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 PlantBox.Shared/Communication/Commands/CaptorValue.cs diff --git a/PlantBox.Shared/Communication/Commands/CaptorValue.cs b/PlantBox.Shared/Communication/Commands/CaptorValue.cs new file mode 100644 index 0000000..a760d66 --- /dev/null +++ b/PlantBox.Shared/Communication/Commands/CaptorValue.cs @@ -0,0 +1,41 @@ +using PlantBox.Shared.Extensions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace PlantBox.Shared.Communication.Commands +{ + public class CaptorValue + { + public const char ValueSeparator = '/'; + + public double Min { get; set; } + public double Max { get; set; } + public double Value { get; set; } + + public CaptorValue(string argument) + { + string[] arguments = argument.Split(ValueSeparator); + + Min = arguments[0].ToDouble(); + Max = arguments[1].ToDouble(); + Value = arguments[2].ToDouble(); + } + public CaptorValue(double min, double max, double value) + { + Min = min; + Max = max; + Value = value; + } + + public string ToArgument() + { + return $"{Min}{ValueSeparator}{Max}{ValueSeparator}{Value}"; + } + + public override string ToString() + { + return ToArgument(); + } + } +} diff --git a/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs b/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs index e3d4f46..fbf3128 100644 --- a/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs +++ b/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs @@ -11,15 +11,15 @@ namespace PlantBox.Shared.Communication.Commands { public override Command Command => Command.Captors; - public double Humidity { get; set; } - public double Luminosity { get; set; } - public double Temperature { get; set; } + public CaptorValue Humidity { get; set; } + public CaptorValue Luminosity { get; set; } + public CaptorValue Temperature { get; set; } public CaptorsResponse() { } - public CaptorsResponse(double humidity, double luminosity, double temperature) + public CaptorsResponse(CaptorValue humidity, CaptorValue luminosity, CaptorValue temperature) { Humidity = humidity; Luminosity = luminosity; @@ -37,9 +37,9 @@ namespace PlantBox.Shared.Communication.Commands throw new ArgumentException($"Excepted 3 arguments, got {arguments.Length}"); } - Humidity = arguments[0].ToDouble(); - Luminosity = arguments[1].ToDouble(); - Temperature = arguments[2].ToDouble(); + Humidity = new CaptorValue(arguments[0]); + Luminosity = new CaptorValue(arguments[1]); + Temperature = new CaptorValue(arguments[2]); return this; }