52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace PlantBox.Shared.Communication.Commands
|
|
{
|
|
public class CaptorsResponse : CommandSerializable<CaptorsResponse>
|
|
{
|
|
public override Command Command => Command.Captors;
|
|
|
|
public double Humidity { get; set; }
|
|
public double Luminosity { get; set; }
|
|
public double Temperature { get; set; }
|
|
|
|
public CaptorsResponse()
|
|
{
|
|
|
|
}
|
|
public CaptorsResponse(double humidity, double luminosity, double temperature)
|
|
{
|
|
Humidity = humidity;
|
|
Luminosity = luminosity;
|
|
Temperature = temperature;
|
|
}
|
|
|
|
public override CaptorsResponse 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();
|
|
}
|
|
}
|
|
}
|