From 9e78307541d43c6221e0bd457d996fd604a0efdd Mon Sep 17 00:00:00 2001 From: Eveldee Date: Mon, 22 Apr 2019 16:54:16 +0200 Subject: [PATCH] Update commands accorded to doc Update Captors and Info commands --- .../Communication/Commands/CaptorsResponse.cs | 24 ++++++++------- .../Communication/Commands/InfoResponse.cs | 30 ++++++++++++++----- .../Extensions/CommandSerializeExtensions.cs | 6 ++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs b/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs index fbf3128..9158c89 100644 --- a/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs +++ b/PlantBox.Shared/Communication/Commands/CaptorsResponse.cs @@ -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() }; } } diff --git a/PlantBox.Shared/Communication/Commands/InfoResponse.cs b/PlantBox.Shared/Communication/Commands/InfoResponse.cs index e486a46..41acd24 100644 --- a/PlantBox.Shared/Communication/Commands/InfoResponse.cs +++ b/PlantBox.Shared/Communication/Commands/InfoResponse.cs @@ -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(); State = arguments[2].ToEnumValue(); - 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}" }; } } diff --git a/PlantBox.Shared/Extensions/CommandSerializeExtensions.cs b/PlantBox.Shared/Extensions/CommandSerializeExtensions.cs index ebeeb0e..8c1db38 100644 --- a/PlantBox.Shared/Extensions/CommandSerializeExtensions.cs +++ b/PlantBox.Shared/Extensions/CommandSerializeExtensions.cs @@ -7,6 +7,12 @@ namespace PlantBox.Shared.Extensions { public static class CommandSerializeExtensions { + // Array extensions + public static (T first, T second) ToTuple(this T[] array) + { + return (array[0], array[1]); + } + // String conversion public static T ToEnumValue(this string argument) {