From 086c10d126b85ff0430a77124fad6498ea500899 Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Sat, 6 Mar 2021 23:42:53 +0100 Subject: [PATCH 1/3] add basic media commands --- UserInterface/Views/AddCommandDialog.axaml.cs | 20 +++++++ .../InterProcessApi.cs | 12 ++++ .../ServiceContractModels.cs | 4 ++ .../Data/ConfigurationService.cs | 20 ++++++- .../Data/ConfiguredCommand.cs | 1 + .../Domain/Commands/KeyCommand.cs | 57 +++++++++++++++++++ .../Domain/Commands/MediaNextCommand.cs | 14 +++++ .../Domain/Commands/MediaPlayPauseCommand.cs | 14 +++++ .../Domain/Commands/MediaPreviousCommand.cs | 14 +++++ 9 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 hass-workstation-service/Domain/Commands/KeyCommand.cs create mode 100644 hass-workstation-service/Domain/Commands/MediaNextCommand.cs create mode 100644 hass-workstation-service/Domain/Commands/MediaPlayPauseCommand.cs create mode 100644 hass-workstation-service/Domain/Commands/MediaPreviousCommand.cs diff --git a/UserInterface/Views/AddCommandDialog.axaml.cs b/UserInterface/Views/AddCommandDialog.axaml.cs index a7d7a1f..000d3e3 100644 --- a/UserInterface/Views/AddCommandDialog.axaml.cs +++ b/UserInterface/Views/AddCommandDialog.axaml.cs @@ -78,6 +78,26 @@ namespace UserInterface.Views item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#logoffcommand"; item.ShowCommandInput = false; break; + case AvailableCommands.KeyCommand: + item.Description = "This commands can be used to send emulate a keystroke."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#keycommand"; + item.ShowCommandInput = false; + break; + case AvailableCommands.PlayPauseCommand: + item.Description = "This command plays or pauses currently playing media."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#playpausecommand"; + item.ShowCommandInput = false; + break; + case AvailableCommands.NextCommand: + item.Description = "This command skips to the next media."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#nextcommand"; + item.ShowCommandInput = false; + break; + case AvailableCommands.PreviousCommand: + item.Description = "This command plays previous media."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#previouscommand"; + item.ShowCommandInput = false; + break; default: item.Description = null; item.MoreInfoLink = null; diff --git a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs index d724082..9d18fb6 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs @@ -188,6 +188,18 @@ namespace hass_workstation_service.Communication.InterProcesCommunication case AvailableCommands.CustomCommand: commandToCreate = new CustomCommand(this._publisher, model.Command, model.Name); break; + case AvailableCommands.PlayPauseCommand: + commandToCreate = new MediaPlayPauseCommand(this._publisher, model.Name); + break; + case AvailableCommands.NextCommand: + commandToCreate = new MediaNextCommand(this._publisher, model.Name); + break; + case AvailableCommands.PreviousCommand: + commandToCreate = new MediaPreviousCommand(this._publisher, model.Name); + break; + case AvailableCommands.KeyCommand: + commandToCreate = new KeyCommand(this._publisher, (byte)model.KeyCode, model.Name); + break; default: Log.Logger.Error("Unknown sensortype"); break; diff --git a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs index 7c5a7bc..ccfaad5 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs @@ -60,5 +60,9 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models ShutdownCommand, LogOffCommand, RestartCommand, + KeyCommand, + PlayPauseCommand, + NextCommand, + PreviousCommand } } diff --git a/hass-workstation-service/Data/ConfigurationService.cs b/hass-workstation-service/Data/ConfigurationService.cs index 8337d35..f9f2987 100644 --- a/hass-workstation-service/Data/ConfigurationService.cs +++ b/hass-workstation-service/Data/ConfigurationService.cs @@ -174,6 +174,18 @@ namespace hass_workstation_service.Data case "CustomCommand": command = new CustomCommand(publisher, configuredCommand.Command, configuredCommand.Name, configuredCommand.Id); break; + case "MediaPlayPauseCommand": + command = new MediaPlayPauseCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; + case "MediaNextCommand": + command = new MediaNextCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; + case "MediaPreviousCommand": + command = new MediaPreviousCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; + case "KeyCommand": + command = new KeyCommand(publisher, configuredCommand.KeyCode, configuredCommand.Name, configuredCommand.Id); + break; default: Log.Logger.Error("unsupported command type in config"); break; @@ -292,9 +304,13 @@ namespace hass_workstation_service.Data Log.Logger.Information($"writing configured commands to: {stream.Name}"); foreach (AbstractCommand command in this.ConfiguredCommands) { - if (command is CustomCommand customcommand) + if (command is CustomCommand customCommand) + { + configuredCommandsToSave.Add(new ConfiguredCommand() { Id = customCommand.Id, Name = customCommand.Name, Type = customCommand.GetType().Name, Command = customCommand.Command }); + } + if (command is KeyCommand customKeyCommand) { - configuredCommandsToSave.Add(new ConfiguredCommand() { Id = customcommand.Id, Name = customcommand.Name, Type = customcommand.GetType().Name, Command = customcommand.Command }); + configuredCommandsToSave.Add(new ConfiguredCommand() { Id = customKeyCommand.Id, Name = customKeyCommand.Name, Type = customKeyCommand.GetType().Name, KeyCode = customKeyCommand.KeyCode }); } } diff --git a/hass-workstation-service/Data/ConfiguredCommand.cs b/hass-workstation-service/Data/ConfiguredCommand.cs index d5d6b48..49544f6 100644 --- a/hass-workstation-service/Data/ConfiguredCommand.cs +++ b/hass-workstation-service/Data/ConfiguredCommand.cs @@ -9,5 +9,6 @@ namespace hass_workstation_service.Data public Guid Id { get; set; } public string Name { get; set; } public string Command { get; set; } + public byte KeyCode { get; set; } } } \ No newline at end of file diff --git a/hass-workstation-service/Domain/Commands/KeyCommand.cs b/hass-workstation-service/Domain/Commands/KeyCommand.cs new file mode 100644 index 0000000..58a3142 --- /dev/null +++ b/hass-workstation-service/Domain/Commands/KeyCommand.cs @@ -0,0 +1,57 @@ +using hass_workstation_service.Communication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace hass_workstation_service.Domain.Commands +{ + public class KeyCommand : AbstractCommand + { + public const int KEYEVENTF_EXTENTEDKEY = 1; + public const int KEYEVENTF_KEYUP = 0; + public const int VK_MEDIA_NEXT_TRACK = 0xB0; + public const int VK_MEDIA_PLAY_PAUSE = 0xB3; + public const int VK_MEDIA_PREV_TRACK = 0xB1; + + public byte KeyCode { get; protected set; } + + public KeyCommand(MqttPublisher publisher, byte keyCode, string name = "Key", Guid id = default(Guid)) : base(publisher, name ?? "Key", id) { + this.KeyCode = keyCode; + } + + public override CommandDiscoveryConfigModel GetAutoDiscoveryConfig() + { + return new CommandDiscoveryConfigModel() + { + Name = this.Name, + Unique_id = this.Id.ToString(), + Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability", + Command_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/set", + State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", + Device = this.Publisher.DeviceConfigModel, + }; + } + + [DllImport("user32.dll")] + public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo); + + + public override string GetState() + { + return "OFF"; + } + + public override void TurnOff() + { + + } + + public override void TurnOn() + { + keybd_event(this.KeyCode, 0, KEYEVENTF_EXTENTEDKEY, IntPtr.Zero); + } + } +} diff --git a/hass-workstation-service/Domain/Commands/MediaNextCommand.cs b/hass-workstation-service/Domain/Commands/MediaNextCommand.cs new file mode 100644 index 0000000..6f7cb7f --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaNextCommand.cs @@ -0,0 +1,14 @@ +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 MediaNextCommand : KeyCommand + { + public MediaNextCommand(MqttPublisher publisher, string name = "Next", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_MEDIA_NEXT_TRACK, name ?? "Next", id) { } + } +} diff --git a/hass-workstation-service/Domain/Commands/MediaPlayPauseCommand.cs b/hass-workstation-service/Domain/Commands/MediaPlayPauseCommand.cs new file mode 100644 index 0000000..695b258 --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaPlayPauseCommand.cs @@ -0,0 +1,14 @@ +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 MediaPlayPauseCommand : KeyCommand + { + public MediaPlayPauseCommand(MqttPublisher publisher, string name = "PlayPause", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_MEDIA_PLAY_PAUSE, name ?? "PlayPause", id) { } + } +} diff --git a/hass-workstation-service/Domain/Commands/MediaPreviousCommand.cs b/hass-workstation-service/Domain/Commands/MediaPreviousCommand.cs new file mode 100644 index 0000000..fe35544 --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaPreviousCommand.cs @@ -0,0 +1,14 @@ +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 MediaPreviousCommand : KeyCommand + { + public MediaPreviousCommand(MqttPublisher publisher, string name = "Previous", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_MEDIA_PREV_TRACK, name ?? "Previous", id) { } + } +} From f6d184fa2fabacfc681ebb01efa50a1d26807c5d Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Sun, 7 Mar 2021 02:03:12 +0100 Subject: [PATCH 2/3] add media commands and keycommand --- README.md | 15 +++++++ .../ViewModels/AddCommandViewModel.cs | 3 ++ UserInterface/Views/AddCommandDialog.axaml | 2 + UserInterface/Views/AddCommandDialog.axaml.cs | 39 ++++++++++++++++--- .../InterProcessApi.cs | 11 +++++- .../ServiceContractModels.cs | 5 ++- .../Data/ConfigurationService.cs | 9 +++++ .../Domain/Commands/KeyCommand.cs | 3 ++ .../Domain/Commands/MediaMuteCommand.cs | 14 +++++++ .../Domain/Commands/MediaVolumeDownCommand.cs | 14 +++++++ .../Domain/Commands/MediaVolumeUpCommand.cs | 14 +++++++ 11 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 hass-workstation-service/Domain/Commands/MediaMuteCommand.cs create mode 100644 hass-workstation-service/Domain/Commands/MediaVolumeDownCommand.cs create mode 100644 hass-workstation-service/Domain/Commands/MediaVolumeUpCommand.cs diff --git a/README.md b/README.md index 055df7f..d2a95dc 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,21 @@ This command allows you to run any Windows Commands. The command will be run in |shutdown /s /t 300|Shuts the PC down after 5 minutes (300 seconds).| |C:\path\to\your\batchfile.bat|Run the specified batch file.| +### KeyCommand + +Sends a keystroke with the specified key. You can pick [any of these](https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) key codes. + +### Media Commands + +There's several media commands available which are very self exlanatory. + +- Play/Pause +- Next +- Previous +- Volume up +- Volume down +- Mute (toggle) + ## Credits This project depends on work done by others and they should at least get a mention. Please note that this list is not complete yet. diff --git a/UserInterface/ViewModels/AddCommandViewModel.cs b/UserInterface/ViewModels/AddCommandViewModel.cs index 7fc458a..133bfca 100644 --- a/UserInterface/ViewModels/AddCommandViewModel.cs +++ b/UserInterface/ViewModels/AddCommandViewModel.cs @@ -13,9 +13,11 @@ namespace UserInterface.ViewModels public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); } public bool ShowCommandInput { get => showCommandInput; set => this.RaiseAndSetIfChanged(ref showCommandInput, value); } + public bool ShowKeyInput { get => showKeyInput; set => this.RaiseAndSetIfChanged(ref showKeyInput, value); } private string moreInfoLink; private bool showCommandInput; + private bool showKeyInput; public string MoreInfoLink { @@ -27,5 +29,6 @@ namespace UserInterface.ViewModels public string Name { get; set; } public string Command { get; set; } + public string Key { get; set; } } } diff --git a/UserInterface/Views/AddCommandDialog.axaml b/UserInterface/Views/AddCommandDialog.axaml index c4f6639..dc2e967 100644 --- a/UserInterface/Views/AddCommandDialog.axaml +++ b/UserInterface/Views/AddCommandDialog.axaml @@ -20,6 +20,8 @@ Command + Key + diff --git a/UserInterface/Views/AddCommandDialog.axaml.cs b/UserInterface/Views/AddCommandDialog.axaml.cs index 000d3e3..a0bd1f4 100644 --- a/UserInterface/Views/AddCommandDialog.axaml.cs +++ b/UserInterface/Views/AddCommandDialog.axaml.cs @@ -47,7 +47,7 @@ namespace UserInterface.Views public async void Save(object sender, RoutedEventArgs args) { var item = ((AddCommandViewModel)this.DataContext); - dynamic model = new { item.Name, item.Command}; + dynamic model = new { item.Name, item.Command, item.Key}; string json = JsonSerializer.Serialize(model); await this.client.InvokeAsync(x => x.AddCommand(item.SelectedType, json)); Close(); @@ -62,50 +62,77 @@ namespace UserInterface.Views item.Description = "This command lets you execute any command you want. It will run in a Windows Command Prompt silently. "; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#customcommand"; item.ShowCommandInput = true; + item.ShowKeyInput = false; break; case AvailableCommands.ShutdownCommand: item.Description = "This command shuts down the PC immediately. "; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#shutdowncommand"; item.ShowCommandInput = false; + item.ShowKeyInput = false; break; case AvailableCommands.RestartCommand: item.Description = "This command restarts the PC immediately. "; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#restartcommand"; 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#logoffcommand"; item.ShowCommandInput = false; + item.ShowKeyInput = false; break; case AvailableCommands.KeyCommand: - item.Description = "This commands can be used to send emulate a keystroke."; + item.Description = "This command can be used to emulate a keystroke. It requires a key code which you can find by clicking the info button below."; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#keycommand"; item.ShowCommandInput = false; + item.ShowKeyInput = true; break; case AvailableCommands.PlayPauseCommand: item.Description = "This command plays or pauses currently playing media."; - item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#playpausecommand"; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; item.ShowCommandInput = false; + item.ShowKeyInput = false; break; case AvailableCommands.NextCommand: item.Description = "This command skips to the next media."; - item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#nextcommand"; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; item.ShowCommandInput = false; + item.ShowKeyInput = false; break; case AvailableCommands.PreviousCommand: item.Description = "This command plays previous media."; - item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#previouscommand"; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; item.ShowCommandInput = false; + item.ShowKeyInput = false; + break; + case AvailableCommands.VolumeDownCommand: + item.Description = "Lowers the system volume."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; + item.ShowCommandInput = false; + item.ShowKeyInput = false; + break; + case AvailableCommands.VolumeUpCommand: + item.Description = "Raises the system volume."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; + item.ShowCommandInput = false; + item.ShowKeyInput = false; + break; + case AvailableCommands.MuteCommand: + item.Description = "Toggles muting the system volume."; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands"; + item.ShowCommandInput = false; + item.ShowKeyInput = false; break; default: item.Description = null; item.MoreInfoLink = null; item.ShowCommandInput = false; + item.ShowKeyInput = false; break; } } - public void OpenInfo(object sender, RoutedEventArgs args) + public void OpenInfo(object sender, RoutedEventArgs args) { var item = ((AddCommandViewModel)this.DataContext); BrowserUtil.OpenBrowser(item.MoreInfoLink); diff --git a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs index 9d18fb6..25eff46 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs @@ -197,8 +197,17 @@ namespace hass_workstation_service.Communication.InterProcesCommunication case AvailableCommands.PreviousCommand: commandToCreate = new MediaPreviousCommand(this._publisher, model.Name); break; + case AvailableCommands.VolumeUpCommand: + commandToCreate = new MediaVolumeUpCommand(this._publisher, model.Name); + break; + case AvailableCommands.VolumeDownCommand: + commandToCreate = new MediaVolumeDownCommand(this._publisher, model.Name); + break; + case AvailableCommands.MuteCommand: + commandToCreate = new MediaMuteCommand(this._publisher, model.Name); + break; case AvailableCommands.KeyCommand: - commandToCreate = new KeyCommand(this._publisher, (byte)model.KeyCode, model.Name); + commandToCreate = new KeyCommand(this._publisher, Convert.ToByte(model.Key, 16), model.Name); break; default: Log.Logger.Error("Unknown sensortype"); diff --git a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs index ccfaad5..768f5e8 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractModels.cs @@ -63,6 +63,9 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models KeyCommand, PlayPauseCommand, NextCommand, - PreviousCommand + PreviousCommand, + VolumeUpCommand, + VolumeDownCommand, + MuteCommand } } diff --git a/hass-workstation-service/Data/ConfigurationService.cs b/hass-workstation-service/Data/ConfigurationService.cs index f9f2987..e58d95e 100644 --- a/hass-workstation-service/Data/ConfigurationService.cs +++ b/hass-workstation-service/Data/ConfigurationService.cs @@ -183,6 +183,15 @@ namespace hass_workstation_service.Data case "MediaPreviousCommand": command = new MediaPreviousCommand(publisher, configuredCommand.Name, configuredCommand.Id); break; + case "MediaVolumeUpCommand": + command = new MediaVolumeUpCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; + case "MediaVolumeDownCommand": + command = new MediaVolumeDownCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; + case "MediaMuteCommand": + command = new MediaMuteCommand(publisher, configuredCommand.Name, configuredCommand.Id); + break; case "KeyCommand": command = new KeyCommand(publisher, configuredCommand.KeyCode, configuredCommand.Name, configuredCommand.Id); break; diff --git a/hass-workstation-service/Domain/Commands/KeyCommand.cs b/hass-workstation-service/Domain/Commands/KeyCommand.cs index 58a3142..93c636d 100644 --- a/hass-workstation-service/Domain/Commands/KeyCommand.cs +++ b/hass-workstation-service/Domain/Commands/KeyCommand.cs @@ -15,6 +15,9 @@ namespace hass_workstation_service.Domain.Commands public const int VK_MEDIA_NEXT_TRACK = 0xB0; public const int VK_MEDIA_PLAY_PAUSE = 0xB3; public const int VK_MEDIA_PREV_TRACK = 0xB1; + public const int VK_VOLUME_MUTE = 0xAD; + public const int VK_VOLUME_UP = 0xAF; + public const int VK_VOLUME_DOWN = 0xAE; public byte KeyCode { get; protected set; } diff --git a/hass-workstation-service/Domain/Commands/MediaMuteCommand.cs b/hass-workstation-service/Domain/Commands/MediaMuteCommand.cs new file mode 100644 index 0000000..3dd4dbc --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaMuteCommand.cs @@ -0,0 +1,14 @@ +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 MediaMuteCommand : KeyCommand + { + public MediaMuteCommand(MqttPublisher publisher, string name = "Mute", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_MUTE, name ?? "Mute", id) { } + } +} diff --git a/hass-workstation-service/Domain/Commands/MediaVolumeDownCommand.cs b/hass-workstation-service/Domain/Commands/MediaVolumeDownCommand.cs new file mode 100644 index 0000000..4096e3c --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaVolumeDownCommand.cs @@ -0,0 +1,14 @@ +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 MediaVolumeDownCommand : KeyCommand + { + public MediaVolumeDownCommand(MqttPublisher publisher, string name = "VolumeDown", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_DOWN, name ?? "VolumeDown", id) { } + } +} diff --git a/hass-workstation-service/Domain/Commands/MediaVolumeUpCommand.cs b/hass-workstation-service/Domain/Commands/MediaVolumeUpCommand.cs new file mode 100644 index 0000000..0631160 --- /dev/null +++ b/hass-workstation-service/Domain/Commands/MediaVolumeUpCommand.cs @@ -0,0 +1,14 @@ +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 MediaVolumeUpCommand : KeyCommand + { + public MediaVolumeUpCommand(MqttPublisher publisher, string name = "VolumeUp", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_UP, name ?? "VolumeUp", id) { } + } +} From f361aac31f020f33b425d1365adc0222f1b90426 Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Sun, 7 Mar 2021 02:20:48 +0100 Subject: [PATCH 3/3] small memory optimization --- .../Domain/Sensors/CurrentVolumeSensor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hass-workstation-service/Domain/Sensors/CurrentVolumeSensor.cs b/hass-workstation-service/Domain/Sensors/CurrentVolumeSensor.cs index 9201d26..aa5d33d 100644 --- a/hass-workstation-service/Domain/Sensors/CurrentVolumeSensor.cs +++ b/hass-workstation-service/Domain/Sensors/CurrentVolumeSensor.cs @@ -12,8 +12,10 @@ namespace hass_workstation_service.Domain.Sensors { public class CurrentVolumeSensor : AbstractSensor { - - public CurrentVolumeSensor(MqttPublisher publisher, int? updateInterval = null, string name = "CurrentVolume", Guid id = default(Guid)) : base(publisher, name ?? "CurrentVolume", updateInterval ?? 10, id) { } + private MMDeviceEnumerator DevEnum; + public CurrentVolumeSensor(MqttPublisher publisher, int? updateInterval = null, string name = "CurrentVolume", Guid id = default(Guid)) : base(publisher, name ?? "CurrentVolume", updateInterval ?? 10, id) { + this.DevEnum = new MMDeviceEnumerator(); + } public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig() { return this._autoDiscoveryConfigModel ?? SetAutoDiscoveryConfigModel(new SensorDiscoveryConfigModel() @@ -33,8 +35,6 @@ namespace hass_workstation_service.Domain.Sensors public override string GetState() { - MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); - var collection = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE); List peaks = new List();