Change CaptorsResponse according to Wiki

This commit is contained in:
2019-03-24 12:48:33 +01:00
parent 73855e246c
commit fa8608b44b
2 changed files with 48 additions and 7 deletions

View File

@@ -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();
}
}
}

View File

@@ -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;
}