Update commands accorded to doc

Update Captors and Info commands
This commit is contained in:
2019-04-22 16:54:16 +02:00
parent 25891c6c9d
commit 9e78307541
3 changed files with 43 additions and 17 deletions

View File

@@ -11,19 +11,21 @@ namespace PlantBox.Shared.Communication.Commands
{
public override Command Command => Command.Captors;
public CaptorValue Humidity { get; set; }
public CaptorValue Luminosity { get; set; }
public CaptorValue Temperature { get; set; }
public double Humidity { get; set; }
public double Luminosity { get; set; }
public double Temperature { get; set; }
public double Tank { get; set; }
public CaptorsResponse()
{
}
public CaptorsResponse(CaptorValue humidity, CaptorValue luminosity, CaptorValue temperature)
public CaptorsResponse(double humidity, double luminosity, double temperature, double tank)
{
Humidity = humidity;
Luminosity = luminosity;
Temperature = temperature;
Tank = tank;
}
public override CaptorsResponse Deserialize(string[] arguments)
@@ -32,14 +34,15 @@ namespace PlantBox.Shared.Communication.Commands
{
throw new ArgumentNullException(nameof(arguments));
}
if (arguments.Length < 3)
if (arguments.Length < 4)
{
throw new ArgumentException($"Excepted 3 arguments, got {arguments.Length}");
throw new ArgumentException($"Excepted 4 arguments, got {arguments.Length}");
}
Humidity = new CaptorValue(arguments[0]);
Luminosity = new CaptorValue(arguments[1]);
Temperature = new CaptorValue(arguments[2]);
Humidity = arguments[0].ToDouble();
Luminosity = arguments[1].ToDouble();
Temperature = arguments[2].ToDouble();
Tank = arguments[3].ToDouble();
return this;
}
@@ -50,7 +53,8 @@ namespace PlantBox.Shared.Communication.Commands
{
Humidity.ToArgument(),
Luminosity.ToArgument(),
Temperature.ToArgument()
Temperature.ToArgument(),
Tank.ToArgument()
};
}
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace PlantBox.Shared.Communication.Commands
@@ -13,18 +14,29 @@ namespace PlantBox.Shared.Communication.Commands
public string Name { get; set; }
public PlantType Type { get; set; }
public PlantState State { get; set; }
public double Water { get; set; }
public double HumidityMin { get; set; }
public double HumidityMax { get; set; }
public double LuminosityMin { get; set; }
public double LuminosityMax { get; set; }
public double TemperatureMin { get; set; }
public double TemperatureMax { get; set; }
public InfoResponse()
{
}
public InfoResponse(string name, PlantType type, PlantState state, double water)
public InfoResponse(string name, PlantType type, PlantState state, double humidityMin, double humidityMax, double luminosityMin, double luminosityMax, double temperatureMin, double temperatureMax)
{
Name = name;
Type = type;
State = state;
Water = water;
HumidityMin = humidityMin;
HumidityMax = humidityMax;
LuminosityMin = luminosityMin;
LuminosityMax = luminosityMax;
TemperatureMin = temperatureMin;
TemperatureMax = temperatureMax;
}
public override InfoResponse Deserialize(string[] arguments)
@@ -33,15 +45,17 @@ namespace PlantBox.Shared.Communication.Commands
{
throw new ArgumentNullException(nameof(arguments));
}
if (arguments.Length < 4)
if (arguments.Length < 6)
{
throw new ArgumentException($"Excepted 4 arguments, got {arguments.Length}");
throw new ArgumentException($"Excepted 6 arguments, got {arguments.Length}");
}
Name = arguments[0];
Type = arguments[1].ToEnumValue<PlantType>();
State = arguments[2].ToEnumValue<PlantState>();
Water = arguments[3].ToDouble();
(HumidityMin, HumidityMax) = arguments[3].Split('/').Select(x => x.ToDouble()).ToArray().ToTuple();
(LuminosityMin, LuminosityMax) = arguments[4].Split('/').Select(x => x.ToDouble()).ToArray().ToTuple();
(TemperatureMin, TemperatureMax) = arguments[5].Split('/').Select(x => x.ToDouble()).ToArray().ToTuple();
return this;
}
@@ -53,7 +67,9 @@ namespace PlantBox.Shared.Communication.Commands
Name,
Type.ToString(),
State.ToString(),
Water.ToArgument()
$"{HumidityMin}/{HumidityMax}",
$"{LuminosityMin}/{LuminosityMax}",
$"{TemperatureMin}/{TemperatureMax}"
};
}
}

View File

@@ -7,6 +7,12 @@ namespace PlantBox.Shared.Extensions
{
public static class CommandSerializeExtensions
{
// Array extensions
public static (T first, T second) ToTuple<T>(this T[] array)
{
return (array[0], array[1]);
}
// String conversion
public static T ToEnumValue<T>(this string argument)
{