diff --git a/README.md b/README.md index ac17f17..093c726 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,14 @@ Find us on [Discord](https://discord.gg/VraYT2N3wd). ## Development -Want to develop or build the application yourself? Make sure to install the .NET Runtime [.NET 5 Runtime](https://dotnet.microsoft.com/download/dotnet/current/runtime) and [.NET 5 SDK](https://dotnet.microsoft.com/download/dotnet/current). Run the following commands from the `hass-workstation-service\hass-workstation-service` directory to get you started: +If you want to help develop Hass Workstation service, make sure to install the .NET Runtime [.NET 5 Runtime](https://dotnet.microsoft.com/download/dotnet/current/runtime) and [.NET 5 SDK](https://dotnet.microsoft.com/download/dotnet/current). Run the following commands from the `hass-workstation-service\hass-workstation-service` directory to get you started: ```` powershell dotnet build dotnet publish ```` -In case you are using Visual Studio Code, open the `hass-workstation-service\hass-workstation-service` folder to take advantage of the predefined build and publish tasks. +If you are using [Visual Studio](https://visualstudio.microsoft.com/), open the `hass-workstation-service\hass-workstation-service` folder to take advantage of the predefined build and publish tasks, alternatively you can open the project directly from github using the green download button to use the integrated git tools. ## Sensors diff --git a/UserInterface/Views/AddCommandDialog.axaml.cs b/UserInterface/Views/AddCommandDialog.axaml.cs index e0e0b96..70a6ade 100644 --- a/UserInterface/Views/AddCommandDialog.axaml.cs +++ b/UserInterface/Views/AddCommandDialog.axaml.cs @@ -112,6 +112,12 @@ namespace UserInterface.Views item.ShowCommandInput = false; item.ShowKeyInput = false; break; + case AvailableCommands.HibernateCommand: + item.Description = "This command hibernates the PC immediately. "; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Commands.md#hibernatecommand"; + item.ShowCommandInput = false; + item.ShowKeyInput = false; + break; case AvailableCommands.LogOffCommand: item.Description = "This command logs the current user off immediately. "; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Commands.md#logoffcommand"; diff --git a/documentation/Commands.md b/documentation/Commands.md index 255bf62..0c0555a 100644 --- a/documentation/Commands.md +++ b/documentation/Commands.md @@ -10,6 +10,10 @@ This command shuts down the computer immediately. It runs `shutdown /s`. This command restarts the computer immediately. It runs `shutdown /r`. +### HibernateCommand + +This command hibernates the computer immediately. It runs `shutdown /h`. + ### LogOffCommand This command logs off the current user. It runs `shutdown /l`. diff --git a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs index e02e73e..1dc8761 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs @@ -201,6 +201,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication { AvailableCommands.ShutdownCommand => new ShutdownCommand(_publisher, model.Name), AvailableCommands.RestartCommand => new RestartCommand(_publisher, model.Name), + AvailableCommands.HibernateCommand => new HibernateCommand(_publisher, model.Name), AvailableCommands.LogOffCommand => new LogOffCommand(_publisher, model.Name), AvailableCommands.CustomCommand => new CustomCommand(_publisher, model.Command, model.Name), AvailableCommands.PlayPauseCommand => new PlayPauseCommand(_publisher, model.Name), diff --git a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs index 9a692ba..2ec85e5 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs @@ -110,6 +110,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models ShutdownCommand, LogOffCommand, RestartCommand, + HibernateCommand, KeyCommand, PlayPauseCommand, NextCommand, diff --git a/hass-workstation-service/Data/ConfigurationService.cs b/hass-workstation-service/Data/ConfigurationService.cs index dfdafc8..8a67026 100644 --- a/hass-workstation-service/Data/ConfigurationService.cs +++ b/hass-workstation-service/Data/ConfigurationService.cs @@ -190,6 +190,9 @@ namespace hass_workstation_service.Data case "RestartCommand": command = new RestartCommand(publisher, configuredCommand.Name, configuredCommand.Id); break; + case "HibernateCommand": + command = new HibernateCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; case "LogOffCommand": command = new LogOffCommand(publisher, configuredCommand.Name, configuredCommand.Id); break; diff --git a/hass-workstation-service/Domain/Commands/CustomCommand.cs b/hass-workstation-service/Domain/Commands/CustomCommand.cs index f4dced8..02d265a 100644 --- a/hass-workstation-service/Domain/Commands/CustomCommand.cs +++ b/hass-workstation-service/Domain/Commands/CustomCommand.cs @@ -30,6 +30,11 @@ namespace hass_workstation_service.Domain.Commands startInfo.FileName = "cmd.exe"; startInfo.Arguments = $"/C {this.Command}"; this.Process.StartInfo = startInfo; + + // turn off the sensor to guarantee disable the switch + // useful if command changes power state of device + this.State = "OFF"; + try { this.Process.Start(); @@ -39,12 +44,6 @@ namespace hass_workstation_service.Domain.Commands Log.Logger.Error($"Sensor {this.Name} failed", e); this.State = "FAILED"; } - - while (!this.Process.HasExited) - { - await Task.Delay(1000); - } - this.State = "OFF"; } diff --git a/hass-workstation-service/Domain/Commands/HibernateCommand.cs b/hass-workstation-service/Domain/Commands/HibernateCommand.cs new file mode 100644 index 0000000..e2e3d7a --- /dev/null +++ b/hass-workstation-service/Domain/Commands/HibernateCommand.cs @@ -0,0 +1,17 @@ +using hass_workstation_service.Communication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace hass_workstation_service.Domain.Commands +{ + public class HibernateCommand : CustomCommand + { + public HibernateCommand(MqttPublisher publisher, string name = "Hibernate", Guid id = default(Guid)) : base(publisher, "shutdown /h", name ?? "Hibernate", id) + { + this.State = "OFF"; + } + } +}