Files
PlantBox/PlantBox.Shared/Communication/Commands/InfoResponse.cs
2019-03-24 19:40:53 +01:00

61 lines
1.6 KiB
C#

using PlantBox.Shared.Extensions;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace PlantBox.Shared.Communication.Commands
{
public class InfoResponse : CommandSerializable<InfoResponse>
{
public override Command Command => Command.Info;
public string Name { get; set; }
public PlantType Type { get; set; }
public PlantState State { get; set; }
public double Water { get; set; }
public InfoResponse()
{
}
public InfoResponse(string name, PlantType type, PlantState state, double water)
{
Name = name;
Type = type;
State = state;
Water = water;
}
public override InfoResponse Deserialize(string[] arguments)
{
if (arguments == null)
{
throw new ArgumentNullException(nameof(arguments));
}
if (arguments.Length < 4)
{
throw new ArgumentException($"Excepted 4 arguments, got {arguments.Length}");
}
Name = arguments[0];
Type = arguments[1].ToEnumValue<PlantType>();
State = arguments[2].ToEnumValue<PlantState>();
Water = arguments[3].ToDouble();
return this;
}
public override string[] Serialize()
{
return new[]
{
Name,
Type.ToString(),
State.ToString(),
Water.ToArgument()
};
}
}
}