Change CaptorsResponse according to Wiki
This commit is contained in:
41
PlantBox.Shared/Communication/Commands/CaptorValue.cs
Normal file
41
PlantBox.Shared/Communication/Commands/CaptorValue.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user