diff --git a/UserInterface/Views/CommandSettings.axaml b/UserInterface/Views/CommandSettings.axaml
index efc93f0..dea407b 100644
--- a/UserInterface/Views/CommandSettings.axaml
+++ b/UserInterface/Views/CommandSettings.axaml
@@ -3,24 +3,27 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
- MaxWidth="800"
- x:Class="UserInterface.Views.CommandSettings" >
-
- Commands
-
+ x:Class="UserInterface.Views.CommandSettings">
-
-
-
-
-
- Add some commands by clicking the "Add" button.
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UserInterface/Views/CommandSettings.axaml.cs b/UserInterface/Views/CommandSettings.axaml.cs
index fb963f4..0f1d9d0 100644
--- a/UserInterface/Views/CommandSettings.axaml.cs
+++ b/UserInterface/Views/CommandSettings.axaml.cs
@@ -1,82 +1,97 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
-using Microsoft.Extensions.DependencyInjection;
-using hass_workstation_service.Communication.NamedPipe;
-using JKang.IpcServiceFramework.Client;
-using System.Threading.Tasks;
-using Avalonia.Interactivity;
-using System.Reactive.Linq;
-using UserInterface.ViewModels;
-using System.Security;
-using hass_workstation_service.Communication.InterProcesCommunication.Models;
-using System.Collections.Generic;
-using System.Linq;
-using Avalonia.Controls.ApplicationLifetimes;
-
-namespace UserInterface.Views
-{
- public class CommandSettings : UserControl
- {
- private readonly IIpcClient client;
- private DataGrid _dataGrid { get; set; }
- private bool sensorsNeedToRefresh { get; set; }
-
- public CommandSettings()
- {
- this.InitializeComponent();
- // register IPC clients
- ServiceProvider serviceProvider = new ServiceCollection()
- .AddNamedPipeIpcClient("commands", pipeName: "pipeinternal")
- .BuildServiceProvider();
-
- // resolve IPC client factory
- IIpcClientFactory clientFactory = serviceProvider
- .GetRequiredService>();
-
- // create client
- this.client = clientFactory.CreateClient("commands");
-
-
- DataContext = new CommandSettingsViewModel();
- GetConfiguredCommands();
-
- this._dataGrid = this.FindControl("Grid");
- }
-
-
- public async void GetConfiguredCommands()
- {
- sensorsNeedToRefresh = false;
- List status = await this.client.InvokeAsync(x => x.GetConfiguredCommands());
-
- ((CommandSettingsViewModel)this.DataContext).ConfiguredCommands = status.Select(s => new CommandViewModel() { Name = s.Name, Type = s.Type, Id = s.Id}).ToList();
-
- }
- public void Delete(object sender, RoutedEventArgs args)
- {
- var item = ((CommandViewModel)this._dataGrid.SelectedItem);
- this.client.InvokeAsync(x => x.RemoveCommandById(item.Id));
- ((CommandSettingsViewModel)this.DataContext).ConfiguredCommands.Remove(item);
- this._dataGrid.SelectedIndex = -1;
- ((CommandSettingsViewModel)this.DataContext).TriggerUpdate();
- }
-
- public async void Add(object sender, RoutedEventArgs args)
- {
- AddCommandDialog dialog = new AddCommandDialog();
- if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- await dialog.ShowDialog(desktop.MainWindow);
- sensorsNeedToRefresh = true;
- GetConfiguredCommands();
- }
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
- }
-}
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Microsoft.Extensions.DependencyInjection;
+using hass_workstation_service.Communication.NamedPipe;
+using JKang.IpcServiceFramework.Client;
+using System.Threading.Tasks;
+using Avalonia.Interactivity;
+using System.Reactive.Linq;
+using UserInterface.ViewModels;
+using System.Security;
+using hass_workstation_service.Communication.InterProcesCommunication.Models;
+using System.Collections.Generic;
+using System.Linq;
+using Avalonia.Controls.ApplicationLifetimes;
+
+namespace UserInterface.Views
+{
+ public class CommandSettings : UserControl
+ {
+ private readonly IIpcClient _client;
+ private readonly DataGrid _dataGrid;
+ private bool _sensorsNeedToRefresh;
+
+ public CommandSettings()
+ {
+ this.InitializeComponent();
+ // register IPC clients
+ ServiceProvider serviceProvider = new ServiceCollection()
+ .AddNamedPipeIpcClient("commands", pipeName: "pipeinternal")
+ .BuildServiceProvider();
+
+ // resolve IPC client factory
+ IIpcClientFactory clientFactory = serviceProvider
+ .GetRequiredService>();
+
+ // create client
+ this._client = clientFactory.CreateClient("commands");
+
+
+ DataContext = new CommandSettingsViewModel();
+ GetConfiguredCommands();
+
+ this._dataGrid = this.FindControl("Grid");
+ }
+
+ public async void GetConfiguredCommands()
+ {
+ _sensorsNeedToRefresh = false;
+ List status = await this._client.InvokeAsync(x => x.GetConfiguredCommands());
+
+ ((CommandSettingsViewModel)this.DataContext).ConfiguredCommands = status.Select(s =>
+ new CommandViewModel()
+ {
+ Name = s.Name,
+ Type = s.Type,
+ Id = s.Id
+ }).ToList();
+ }
+
+ public async void AddCommand(object sender, RoutedEventArgs args)
+ {
+ var dialog = new AddCommandDialog();
+ if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
+ await dialog.ShowDialog(desktop.MainWindow);
+ _sensorsNeedToRefresh = true;
+ GetConfiguredCommands();
+ }
+ }
+
+ public void EditCommand(object sender, RoutedEventArgs args)
+ {
+
+ }
+
+ public void DeleteCommand(object sender, RoutedEventArgs args)
+ {
+ if (_dataGrid.SelectedItem is not CommandViewModel item)
+ return;
+
+ this._client.InvokeAsync(x => x.RemoveCommandById(item.Id));
+
+ if (DataContext is not CommandSettingsViewModel viewModel)
+ return;
+
+ viewModel.ConfiguredCommands.Remove(item);
+ _dataGrid.SelectedIndex = -1;
+ viewModel.TriggerUpdate();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+ }
+}
\ No newline at end of file
diff --git a/UserInterface/Views/SensorSettings.axaml b/UserInterface/Views/SensorSettings.axaml
index 4d8d085..a5b6924 100644
--- a/UserInterface/Views/SensorSettings.axaml
+++ b/UserInterface/Views/SensorSettings.axaml
@@ -3,30 +3,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
- MaxWidth="800"
- x:Class="UserInterface.Views.SensorSettings" >
-
- Sensors
-
+ x:Class="UserInterface.Views.SensorSettings">
-
-
-
-
-
-
-
- Add some sensors by clicking the "Add" button.
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UserInterface/Views/SensorSettings.axaml.cs b/UserInterface/Views/SensorSettings.axaml.cs
index 532006c..2ac4828 100644
--- a/UserInterface/Views/SensorSettings.axaml.cs
+++ b/UserInterface/Views/SensorSettings.axaml.cs
@@ -1,104 +1,123 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
-using Microsoft.Extensions.DependencyInjection;
-using hass_workstation_service.Communication.NamedPipe;
-using JKang.IpcServiceFramework.Client;
-using System.Threading.Tasks;
-using Avalonia.Interactivity;
-using System.Reactive.Linq;
-using UserInterface.ViewModels;
-using System.Security;
-using hass_workstation_service.Communication.InterProcesCommunication.Models;
-using System.Collections.Generic;
-using System.Linq;
-using Avalonia.Controls.ApplicationLifetimes;
-
-namespace UserInterface.Views
-{
- public class SensorSettings : UserControl
- {
- private readonly IIpcClient client;
- private DataGrid _dataGrid { get; set; }
- private bool sensorsNeedToRefresh { get; set; }
-
- public SensorSettings()
- {
- this.InitializeComponent();
- // register IPC clients
- ServiceProvider serviceProvider = new ServiceCollection()
- .AddNamedPipeIpcClient("sensors", pipeName: "pipeinternal")
- .BuildServiceProvider();
-
- // resolve IPC client factory
- IIpcClientFactory clientFactory = serviceProvider
- .GetRequiredService>();
-
- // create client
- this.client = clientFactory.CreateClient("sensors");
-
-
- DataContext = new SensorSettingsViewModel();
- GetConfiguredSensors();
-
- this._dataGrid = this.FindControl("Grid");
- }
-
-
- public async void GetConfiguredSensors()
- {
- sensorsNeedToRefresh = false;
- List status = await this.client.InvokeAsync(x => x.GetConfiguredSensors());
-
- ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors = status.Select(s => new SensorViewModel() { Name = s.Name, Type = s.Type, Value = s.Value, Id = s.Id, UpdateInterval = s.UpdateInterval, UnitOfMeasurement = s.UnitOfMeasurement }).ToList();
- while (!sensorsNeedToRefresh)
- {
- await Task.Delay(1000);
- List statusUpdated = await this.client.InvokeAsync(x => x.GetConfiguredSensors());
- var configuredSensors = ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors;
- // this is a workaround for the list showing before it has been completely loaded in the service
- if (statusUpdated.Count != configuredSensors.Count) {
- sensorsNeedToRefresh = true;
- GetConfiguredSensors();
- }
- statusUpdated.ForEach(s =>
- {
- var configuredSensor = configuredSensors.FirstOrDefault(cs => cs.Id == s.Id);
- if (configuredSensor != null)
- {
- configuredSensor.Value = s.Value;
-
- configuredSensors.FirstOrDefault(cs => cs.Id == s.Id).Value = s.Value;
- }
- });
- }
-
- }
- public void Delete(object sender, RoutedEventArgs args)
- {
- var item = ((SensorViewModel)this._dataGrid.SelectedItem);
- this.client.InvokeAsync(x => x.RemoveSensorById(item.Id));
- ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors.Remove(item);
- this._dataGrid.SelectedIndex = -1;
- ((SensorSettingsViewModel)this.DataContext).TriggerUpdate();
- }
-
- public async void AddSensor(object sender, RoutedEventArgs args)
- {
- AddSensorDialog dialog = new AddSensorDialog();
- if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- await dialog.ShowDialog(desktop.MainWindow);
- sensorsNeedToRefresh = true;
- GetConfiguredSensors();
- }
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
-
- }
-}
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Microsoft.Extensions.DependencyInjection;
+using hass_workstation_service.Communication.NamedPipe;
+using JKang.IpcServiceFramework.Client;
+using System.Threading.Tasks;
+using Avalonia.Interactivity;
+using System.Reactive.Linq;
+using UserInterface.ViewModels;
+using System.Security;
+using hass_workstation_service.Communication.InterProcesCommunication.Models;
+using System.Collections.Generic;
+using System.Linq;
+using Avalonia.Controls.ApplicationLifetimes;
+
+namespace UserInterface.Views
+{
+ public class SensorSettings : UserControl
+ {
+ private readonly IIpcClient _client;
+ private readonly DataGrid _dataGrid;
+ private bool _sensorsNeedToRefresh;
+
+ public SensorSettings()
+ {
+ this.InitializeComponent();
+ // register IPC clients
+ ServiceProvider serviceProvider = new ServiceCollection()
+ .AddNamedPipeIpcClient("sensors", pipeName: "pipeinternal")
+ .BuildServiceProvider();
+
+ // resolve IPC client factory
+ IIpcClientFactory clientFactory = serviceProvider
+ .GetRequiredService>();
+
+ // create client
+ this._client = clientFactory.CreateClient("sensors");
+
+
+ DataContext = new SensorSettingsViewModel();
+ GetConfiguredSensors();
+
+ this._dataGrid = this.FindControl("Grid");
+ }
+
+ public async void GetConfiguredSensors()
+ {
+ _sensorsNeedToRefresh = false;
+ List status = await this._client.InvokeAsync(x => x.GetConfiguredSensors());
+
+ ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors = status.Select(s =>
+ new SensorViewModel()
+ {
+ Name = s.Name,
+ Type = s.Type,
+ Value = s.Value,
+ Id = s.Id,
+ UpdateInterval = s.UpdateInterval,
+ UnitOfMeasurement = s.UnitOfMeasurement
+ }).ToList();
+
+ while (!_sensorsNeedToRefresh)
+ {
+ await Task.Delay(1000);
+ List statusUpdated = await this._client.InvokeAsync(x => x.GetConfiguredSensors());
+ var configuredSensors = ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors;
+ // this is a workaround for the list showing before it has been completely loaded in the service
+ if (statusUpdated.Count != configuredSensors.Count)
+ {
+ _sensorsNeedToRefresh = true;
+ GetConfiguredSensors();
+ }
+ statusUpdated.ForEach(s =>
+ {
+ var configuredSensor = configuredSensors.FirstOrDefault(cs => cs.Id == s.Id);
+ if (configuredSensor != null)
+ {
+ configuredSensor.Value = s.Value;
+
+ configuredSensors.FirstOrDefault(cs => cs.Id == s.Id).Value = s.Value;
+ }
+ });
+ }
+ }
+
+ public async void AddSensor(object sender, RoutedEventArgs args)
+ {
+ var dialog = new AddSensorDialog();
+ if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
+ await dialog.ShowDialog(desktop.MainWindow);
+ _sensorsNeedToRefresh = true;
+ GetConfiguredSensors();
+ }
+ }
+
+ public void EditSensor(object sender, RoutedEventArgs args)
+ {
+
+ }
+
+ public void DeleteSensor(object sender, RoutedEventArgs args)
+ {
+ if (_dataGrid.SelectedItem is not SensorViewModel item)
+ return;
+
+ this._client.InvokeAsync(x => x.RemoveSensorById(item.Id));
+
+ if (DataContext is not SensorSettingsViewModel viewModel)
+ return;
+
+ viewModel.ConfiguredSensors.Remove(item);
+ _dataGrid.SelectedIndex = -1;
+ viewModel.TriggerUpdate();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+ }
+}
\ No newline at end of file