commit
7684d65fd0
@ -0,0 +1,26 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="UserInterface.Views.AddCommandDialog"
|
||||||
|
SizeToContent="WidthAndHeight"
|
||||||
|
Title="Add sensor">
|
||||||
|
<StackPanel Margin="40" MinWidth="200">
|
||||||
|
<ContentControl Margin="0 20 0 10">Sensor type</ContentControl>
|
||||||
|
|
||||||
|
<ComboBox x:Name="ComboBox" SelectionChanged="ComboBoxClosed" SelectedItem="{Binding SelectedType}" MinHeight="27"></ComboBox>
|
||||||
|
<TextBlock Margin="0 10 0 10" MaxWidth="300" TextWrapping="Wrap" TextAlignment="Left" Text="{Binding Description}"></TextBlock>
|
||||||
|
<Button IsVisible="{Binding MoreInfoLink, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" Click="OpenInfo" Margin="0 10 0 10">Click for more information.</Button>
|
||||||
|
<ContentControl Margin="0 20 0 10">Name</ContentControl>
|
||||||
|
<TextBox Text="{Binding Name}" HorizontalAlignment="Left" MinWidth="150"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<TextBlock Text="{Binding UpdateInterval, StringFormat= Update every {0} seconds}" HorizontalAlignment="Left" MinWidth="150"/>
|
||||||
|
<ContentControl IsVisible="{Binding ShowCommandInput}" Margin="0 20 0 10">Command</ContentControl>
|
||||||
|
<TextBox IsVisible="{Binding ShowCommandInput}" Text="{Binding Command}" Watermark="Rundll32.exe user32.dll,LockWorkStation" HorizontalAlignment="Left" MinWidth="300"/>
|
||||||
|
<Button IsVisible="{Binding ShowCommandInput}" Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Test">Test</Button>
|
||||||
|
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Save">Save</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</Window>
|
@ -0,0 +1,17 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
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"
|
||||||
|
x:Class="UserInterface.Views.AppInfo">
|
||||||
|
<StackPanel Margin="30">
|
||||||
|
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Left">
|
||||||
|
<ContentControl FontSize="18" FontWeight="Bold" >Info</ContentControl>
|
||||||
|
<TextBlock Text="Need some help?" Margin="0 0 0 20"></TextBlock >
|
||||||
|
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Left" Orientation="Horizontal">
|
||||||
|
<Button Width="75" HorizontalAlignment="Right" Margin="10 10" Click="Github">Github</Button>
|
||||||
|
<Button Width="75" HorizontalAlignment="Left" Margin="10 10" Click="Discord">Discord</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
@ -0,0 +1,26 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
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" >
|
||||||
|
<StackPanel Margin="30" HorizontalAlignment="Left" >
|
||||||
|
<ContentControl FontSize="18" Margin="0 0 0 15" FontWeight="Bold">Commands</ContentControl>
|
||||||
|
<DataGrid x:Name="Grid" IsVisible="{Binding ConfiguredCommands.Count}" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" Items="{Binding ConfiguredCommands}">
|
||||||
|
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Name"
|
||||||
|
Binding="{Binding Name}"
|
||||||
|
Width="1*" />
|
||||||
|
<DataGridTextColumn Header="Type"
|
||||||
|
Binding="{Binding Type}"
|
||||||
|
Width="1*" />
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
<TextBlock IsVisible="{Binding !ConfiguredCommands.Count}">Add some commands by clicking the "Add" button. </TextBlock>
|
||||||
|
|
||||||
|
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Add">Add</Button>
|
||||||
|
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Delete">Delete</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
@ -0,0 +1,13 @@
|
|||||||
|
using hass_workstation_service.Domain.Sensors;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace hass_workstation_service.Data
|
||||||
|
{
|
||||||
|
public class ConfiguredCommand
|
||||||
|
{
|
||||||
|
public string Type { get; set; }
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Command { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using hass_workstation_service.Communication;
|
||||||
|
using MQTTnet;
|
||||||
|
|
||||||
|
namespace hass_workstation_service.Domain.Commands
|
||||||
|
{
|
||||||
|
|
||||||
|
public abstract class AbstractCommand : AbstractDiscoverable
|
||||||
|
{
|
||||||
|
public Guid Id { get; protected set; }
|
||||||
|
public string Name { get; protected set; }
|
||||||
|
/// <summary>
|
||||||
|
/// The update interval in seconds. It checks state only if the interval has passed.
|
||||||
|
/// </summary>
|
||||||
|
public int UpdateInterval { get => 1; }
|
||||||
|
public DateTime? LastUpdated { get; protected set; }
|
||||||
|
public string PreviousPublishedState { get; protected set; }
|
||||||
|
public MqttPublisher Publisher { get; protected set; }
|
||||||
|
public override string Domain { get => "switch"; }
|
||||||
|
public AbstractCommand(MqttPublisher publisher, string name, Guid id = default(Guid))
|
||||||
|
{
|
||||||
|
if (id == Guid.Empty)
|
||||||
|
{
|
||||||
|
this.Id = Guid.NewGuid();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Id = id;
|
||||||
|
}
|
||||||
|
this.Name = name;
|
||||||
|
this.Publisher = publisher;
|
||||||
|
publisher.Subscribe(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
protected CommandDiscoveryConfigModel _autoDiscoveryConfigModel;
|
||||||
|
protected CommandDiscoveryConfigModel SetAutoDiscoveryConfigModel(CommandDiscoveryConfigModel config)
|
||||||
|
{
|
||||||
|
this._autoDiscoveryConfigModel = config;
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract CommandDiscoveryConfigModel GetAutoDiscoveryConfig();
|
||||||
|
public abstract string GetState();
|
||||||
|
|
||||||
|
public async Task PublishStateAsync()
|
||||||
|
{
|
||||||
|
if (LastUpdated.HasValue && LastUpdated.Value.AddSeconds(this.UpdateInterval) > DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
// dont't even check the state if the update interval hasn't passed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string state = this.GetState();
|
||||||
|
if (this.PreviousPublishedState == state)
|
||||||
|
{
|
||||||
|
// don't publish the state if it hasn't changed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var message = new MqttApplicationMessageBuilder()
|
||||||
|
.WithTopic(this.GetAutoDiscoveryConfig().State_topic)
|
||||||
|
.WithPayload(state)
|
||||||
|
.WithExactlyOnceQoS()
|
||||||
|
.WithRetainFlag()
|
||||||
|
.Build();
|
||||||
|
await Publisher.Publish(message);
|
||||||
|
this.PreviousPublishedState = state;
|
||||||
|
this.LastUpdated = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
public async void PublishAutoDiscoveryConfigAsync()
|
||||||
|
{
|
||||||
|
await this.Publisher.AnnounceAutoDiscoveryConfig(this.GetAutoDiscoveryConfig(), this.Domain);
|
||||||
|
}
|
||||||
|
public async Task UnPublishAutoDiscoveryConfigAsync()
|
||||||
|
{
|
||||||
|
await this.Publisher.AnnounceAutoDiscoveryConfig(this.GetAutoDiscoveryConfig(), this.Domain, true);
|
||||||
|
}
|
||||||
|
public abstract void TurnOn();
|
||||||
|
public abstract void TurnOff();
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue