Add CaptorsCommand
This commit is contained in:
49
PlantBox.Shared/Communication/Commands/CaptorsCommand.cs
Normal file
49
PlantBox.Shared/Communication/Commands/CaptorsCommand.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Shared.Communication.Commands
|
||||||
|
{
|
||||||
|
class CaptorsCommand : CommandSerializable<CaptorsCommand>
|
||||||
|
{
|
||||||
|
public double Humidity { get; set; }
|
||||||
|
public double Luminosity { get; set; }
|
||||||
|
public double Temperature { get; set; }
|
||||||
|
|
||||||
|
public CaptorsCommand()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public CaptorsCommand(double humidity, double luminosity, double temperature)
|
||||||
|
{
|
||||||
|
Humidity = humidity;
|
||||||
|
Luminosity = luminosity;
|
||||||
|
Temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CaptorsCommand Deserialize(string[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(arguments));
|
||||||
|
}
|
||||||
|
if (arguments.Length < 3)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Excepted 3 arguments, got {arguments.Length}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Humidity = double.Parse(arguments[0], CultureInfo.InvariantCulture);
|
||||||
|
Luminosity = double.Parse(arguments[1], CultureInfo.InvariantCulture);
|
||||||
|
Temperature = double.Parse(arguments[2], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] Serialize()
|
||||||
|
{
|
||||||
|
return new[] { Humidity, Luminosity, Temperature }.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user