diff --git a/PlantBox.Client/PlantBox.Client/Forms/Controls/StatusBar.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/Controls/StatusBar.xaml.cs index 607cf75..09390a6 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Controls/StatusBar.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/Controls/StatusBar.xaml.cs @@ -14,7 +14,7 @@ namespace PlantBox.Client.Forms.Controls.StatusBar public partial class StatusBar : ContentView { // Progress - public static readonly BindableProperty ProgressProperty = BindableProperty.Create(nameof(Progress), typeof(double), typeof(StatusBar)); + public static readonly BindableProperty ProgressProperty = BindableProperty.Create(nameof(Progress), typeof(double), typeof(StatusBar), 0.5); public double Progress { get => (double)GetValue(ProgressProperty); diff --git a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml index 939044c..efedd37 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml +++ b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml @@ -34,7 +34,7 @@ BoundColor="DarkSlateGray" BoundHeight="2" LowerBound="{Binding LuminosityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}" - UpperBound="-1" + UpperBound="{Binding LuminosityCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}" Image="{extensions:ImageResource Luminosity_Icon.png}" FlexLayout.Basis="{StaticResource BarWidth}" /> LoadPlants(IEnumerable ids) { - // Mock - return new ObservableCollection - ( - new[] { - new PlantInfo("Salon", 0, PlantType.Ficus, PlantState.Good), - new PlantInfo("Chambre", 1, PlantType.Bamboo, PlantState.Warning), - new PlantInfo("Hellx", 2, PlantType.Cactus, PlantState.Bad), - new PlantInfo("Hello", 3, PlantType.Cactus, PlantState.Bad) - }.OrderBy(x => x.State).ThenBy(x => x.Name) - ); + IEnumerable infos = GetPlantInfos(ids); + + return new ObservableCollection(infos); + } + + private IEnumerable GetPlantInfos(IEnumerable ids) + { + using (var client = new TcpClient(App.Settings.BrokerIP, Connection.TCP_CLIENT_PORT)) + { + var stream = new CommandStream(client.GetStream()); + + foreach (ulong id in ids) + { + stream.Send(new InfoRequest().ToCommandPacket(id)); + (_, var responseInfo) = stream.Receive(); + + yield return new PlantInfo + ( + responseInfo.Name, + id, + responseInfo.Type, + responseInfo.State, + responseInfo.HumidityMin, + responseInfo.HumidityMax, + responseInfo.LuminosityMin, + responseInfo.LuminosityMax, + responseInfo.TemperatureMin, + responseInfo.TemperatureMax + ); + } + } } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs b/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs index 0b6fbd1..675e9e0 100644 --- a/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs +++ b/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs @@ -1,8 +1,10 @@ using PlantBox.Client.Models; +using PlantBox.Shared.Communication; using PlantBox.Shared.Communication.Commands; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Text; @@ -119,27 +121,38 @@ namespace PlantBox.Client.ViewModels private void LoadValues() { - // TODO - //throw new NotImplementedException(); + using (var client = new TcpClient(App.Settings.BrokerIP, Connection.TCP_CLIENT_PORT)) + { + var stream = new CommandStream(client.GetStream()); - // Temp - HumidityCaptor = new CaptorValue(20, 80, 21); - LuminosityCaptor = new CaptorValue(50, 1000, 375.6); - TemperatureCaptor = new CaptorValue(20, 35, 27); - TankValue = 78.45; + // Captors info + stream.Send(new CaptorsRequest().ToCommandPacket(PlantInfo.ID)); + (_, var captorsReponse) = stream.Receive(); - var humidities = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 }; - var luminosities = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 }; - var temperatures = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 }; - var humidities2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 }; - var luminosities2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 }; - var temperatures2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 }; + HumidityCaptor = new CaptorValue(PlantInfo.HumidityMin, PlantInfo.HumidityMax, captorsReponse.Humidity); + LuminosityCaptor = new CaptorValue(PlantInfo.LuminosityMin, PlantInfo.LuminosityMax, captorsReponse.Luminosity); + TemperatureCaptor = new CaptorValue(PlantInfo.TemperatureMin, PlantInfo.TemperatureMax, captorsReponse.Temperature); + TankValue = captorsReponse.Tank; - Historic = new Historic(new HistoricEntries(DateTime.Now, TimeSpan.FromMinutes(5), humidities, luminosities, temperatures), - new HistoricEntries(DateTime.Now, TimeSpan.FromHours(1), humidities2, luminosities2, temperatures2), - new HistoricEntries(DateTime.Now, TimeSpan.FromDays(1), humidities2, luminosities2, temperatures2), - new HistoricEntries(DateTime.Now, TimeSpan.FromDays(7), humidities2, luminosities2, temperatures2), - new HistoricEntries(DateTime.Now, TimeSpan.FromDays(31), humidities2, luminosities2, temperatures2)); + // Historic + stream.Send(new HistoricRequest(HistoricInterval.Minutely, 12).ToCommandPacket(PlantInfo.ID)); + (_, var minutelyHistoric) = stream.Receive(); + stream.Send(new HistoricRequest(HistoricInterval.Hourly, 48).ToCommandPacket(PlantInfo.ID)); + (_, var hourlyHistoric) = stream.Receive(); + stream.Send(new HistoricRequest(HistoricInterval.Daily, 186).ToCommandPacket(PlantInfo.ID)); + (_, var dailyHistoric) = stream.Receive(); + stream.Send(new HistoricRequest(HistoricInterval.Monthly, 36).ToCommandPacket(PlantInfo.ID)); + (_, var monthlyHistoric) = stream.Receive(); + + var historic = new Historic + ( + new HistoricEntries(minutelyHistoric, TimeSpan.FromMinutes(5)), + new HistoricEntries(hourlyHistoric, TimeSpan.FromHours(1)), + new HistoricEntries(dailyHistoric, TimeSpan.FromDays(1)), + new HistoricEntries(monthlyHistoric, TimeSpan.FromDays(31)) + ); + Historic = historic; + } } protected void OnPropertyChanged([CallerMemberName] string propertyName = null)