From 493fdd489cfa0828faafc74351b4b3cc07a15491 Mon Sep 17 00:00:00 2001 From: LAB02 Research Date: Tue, 8 Mar 2022 17:57:52 +0100 Subject: [PATCH] v2022.3.8 --- .../HASSAgent/Commands/CommandsManager.cs | 5 +- src/HASS.Agent/HASSAgent/Enums/CommandType.cs | 20 +++++ src/HASS.Agent/HASSAgent/Enums/SensorType.cs | 29 ++++++++ .../Forms/ChildApplications/Restart.cs | 2 +- .../Forms/Commands/CommandsMod.Designer.cs | 73 +++++++++++-------- .../HASSAgent/Forms/Commands/CommandsMod.cs | 62 ++++++++++++++-- .../Forms/QuickActions/QuickActionsMod.cs | 6 +- .../HASSAgent/Forms/Sensors/SensorsMod.cs | 18 ++--- .../HASSAgent/Functions/HelperFunctions.cs | 54 ++++++++++++++ src/HASS.Agent/HASSAgent/HASSAgent.csproj | 2 + .../Models/Config/ConfiguredCommand.cs | 2 + .../Commands/MultipleKeysCommand.cs | 59 +++++++++++++++ .../SingleValue/LoggedUserSensor.cs | 32 ++++++++ .../HASSAgent/Properties/AssemblyInfo.cs | 4 +- .../HASSAgent/Sensors/SensorsManager.cs | 1 + .../HASSAgent/Settings/StoredCommands.cs | 15 ++++ .../HASSAgent/Settings/StoredSensors.cs | 3 + 17 files changed, 333 insertions(+), 54 deletions(-) create mode 100644 src/HASS.Agent/HASSAgent/Models/HomeAssistant/Commands/MultipleKeysCommand.cs create mode 100644 src/HASS.Agent/HASSAgent/Models/HomeAssistant/Sensors/GeneralSensors/SingleValue/LoggedUserSensor.cs diff --git a/src/HASS.Agent/HASSAgent/Commands/CommandsManager.cs b/src/HASS.Agent/HASSAgent/Commands/CommandsManager.cs index 10ee7a3..632eaaa 100644 --- a/src/HASS.Agent/HASSAgent/Commands/CommandsManager.cs +++ b/src/HASS.Agent/HASSAgent/Commands/CommandsManager.cs @@ -271,10 +271,11 @@ private static void LoadCommandInfo() CommandInfo.Add(CommandType.MediaVolumeUpCommand, "Simulates 'volume up' key."); CommandInfo.Add(CommandType.MediaVolumeDownCommand, "Simulates 'volume down' key."); CommandInfo.Add(CommandType.MediaMuteCommand, "Simulates 'mute' key."); - CommandInfo.Add(CommandType.KeyCommand, "Simulates a single keypress.\r\n\r\nYou can pick any of these values: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes \r\n\r\nAnother option is using a tool like AutoHotKey and binding it to a CustomCommand."); + CommandInfo.Add(CommandType.KeyCommand, "Simulates a single keypress.\r\n\r\nYou can pick any of these values: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes \r\n\r\nIf you need more keys and/or modifiers like CTRL, use the MultipleKeys command."); CommandInfo.Add(CommandType.PublishAllSensorsCommand, "Resets all sensor checks, forcing all sensors to process and send their value.\r\n\r\nUseful for example if you want to force HASS.Agent to update all your sensors after a HA reboot."); CommandInfo.Add(CommandType.LaunchUrlCommand, "Launches the provided URL, by default in your default browser.\r\n\r\nTo use 'incognito', provide a specific browser in Configuration -> External Tools."); CommandInfo.Add(CommandType.CustomExecutorCommand, "Executes the command through the configured custom executor (in Configuration -> External Tools).\r\n\r\nYour command is provided as an argument 'as is', so you have to supply your own quotes etc. if necessary."); + CommandInfo.Add(CommandType.MultipleKeysCommand, "Simulates pressing mulitple keys.\r\n\r\nYou need to put [ ] between every key, otherwise HASS.Agent can't tell them apart. So say you want to press X TAB Y SHIFT-Z, it'd be [X] [{TAB}] [Y] [+Z].\r\n\r\nThere are a few tricks you can use:\r\n\r\n- Special keys go between { }, like {TAB} or {UP}\r\n\r\n- Put a + in front of a key to add SHIFT, ^ for CTRL and % for ALT. So, +C is SHIFT-C. Or, +(CD) is SHIFT-C and SHIFT-D, while +CD is SHIFT-C and D\r\n\r\n- For multiple presses, use {z 15}, which means Z will get pressed 15 times.\r\n\r\nMore info: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys"); } } -} +} \ No newline at end of file diff --git a/src/HASS.Agent/HASSAgent/Enums/CommandType.cs b/src/HASS.Agent/HASSAgent/Enums/CommandType.cs index c8b4fb1..22bb3d7 100644 --- a/src/HASS.Agent/HASSAgent/Enums/CommandType.cs +++ b/src/HASS.Agent/HASSAgent/Enums/CommandType.cs @@ -6,38 +6,58 @@ public enum CommandType { [EnumMember(Value = "CustomCommand")] CustomCommand, + [EnumMember(Value = "CustomExecutorCommand")] CustomExecutorCommand, + [EnumMember(Value = "HibernateCommand")] HibernateCommand, + [EnumMember(Value = "KeyCommand")] KeyCommand, + [EnumMember(Value = "LaunchUrlCommand")] LaunchUrlCommand, + [EnumMember(Value = "LockCommand")] LockCommand, + [EnumMember(Value = "LogOffCommand")] LogOffCommand, + [EnumMember(Value = "MediaMuteCommand")] MediaMuteCommand, + [EnumMember(Value = "MediaNextCommand")] MediaNextCommand, + [EnumMember(Value = "MediaPlayPauseCommand")] MediaPlayPauseCommand, + [EnumMember(Value = "MediaPreviousCommand")] MediaPreviousCommand, + [EnumMember(Value = "MediaVolumeDownCommand")] MediaVolumeDownCommand, + [EnumMember(Value = "MediaVolumeUpCommand")] MediaVolumeUpCommand, + + [EnumMember(Value = "MultipleKeysCommand")] + MultipleKeysCommand, + [EnumMember(Value = "PowershellCommand")] PowershellCommand, + [EnumMember(Value = "PublishAllSensorsCommand")] PublishAllSensorsCommand, + [EnumMember(Value = "RestartCommand")] RestartCommand, + [EnumMember(Value = "ShutdownCommand")] ShutdownCommand, + [EnumMember(Value = "SleepCommand")] SleepCommand } diff --git a/src/HASS.Agent/HASSAgent/Enums/SensorType.cs b/src/HASS.Agent/HASSAgent/Enums/SensorType.cs index e911f0c..bf694ff 100644 --- a/src/HASS.Agent/HASSAgent/Enums/SensorType.cs +++ b/src/HASS.Agent/HASSAgent/Enums/SensorType.cs @@ -8,56 +8,85 @@ public enum SensorType { [EnumMember(Value = "ActiveWindowSensor")] ActiveWindowSensor, + [EnumMember(Value = "AudioSensors")] AudioSensors, + [EnumMember(Value = "BatterySensors")] BatterySensors, + [EnumMember(Value = "CpuLoadSensor")] CpuLoadSensor, + [EnumMember(Value = "CurrentClockSpeedSensor")] CurrentClockSpeedSensor, + [EnumMember(Value = "CurrentVolumeSensor")] CurrentVolumeSensor, + [EnumMember(Value = "DisplaySensors")] DisplaySensors, + [EnumMember(Value = "DummySensor")] DummySensor, + [EnumMember(Value = "GpuLoadSensor")] GpuLoadSensor, + [EnumMember(Value = "GpuTemperatureSensor")] GpuTemperatureSensor, + [EnumMember(Value = "LastActiveSensor")] LastActiveSensor, + [EnumMember(Value = "LastBootSensor")] LastBootSensor, + [EnumMember(Value = "LastSystemStateChangeSensor")] LastSystemStateChangeSensor, + + [EnumMember(Value = "LoggedUserSensor")] + LoggedUserSensor, + [EnumMember(Value = "LoggedUsersSensor")] LoggedUsersSensor, + [EnumMember(Value = "MemoryUsageSensor")] MemoryUsageSensor, + [EnumMember(Value = "MicrophoneActiveSensor")] MicrophoneActiveSensor, + [EnumMember(Value = "NamedWindowSensor")] NamedWindowSensor, + [EnumMember(Value = "NetworkSensors")] NetworkSensors, + [EnumMember(Value = "PerformanceCounterSensor")] PerformanceCounterSensor, + [EnumMember(Value = "ProcessActiveSensor")] ProcessActiveSensor, + [EnumMember(Value = "ServiceStateSensor")] ServiceStateSensor, + [EnumMember(Value = "SessionStateSensor")] SessionStateSensor, + [EnumMember(Value = "StorageSensors")] StorageSensors, + [EnumMember(Value = "UserNotificationStateSensor")] UserNotificationStateSensor, + [EnumMember(Value = "WebcamActiveSensor")] WebcamActiveSensor, + [EnumMember(Value = "WindowsUpdatesSensors")] WindowsUpdatesSensors, + [EnumMember(Value = "WmiQuerySensor")] WmiQuerySensor } diff --git a/src/HASS.Agent/HASSAgent/Forms/ChildApplications/Restart.cs b/src/HASS.Agent/HASSAgent/Forms/ChildApplications/Restart.cs index 89d410c..345ca6e 100644 --- a/src/HASS.Agent/HASSAgent/Forms/ChildApplications/Restart.cs +++ b/src/HASS.Agent/HASSAgent/Forms/ChildApplications/Restart.cs @@ -43,7 +43,7 @@ private async void ProcessRestart() if (!closed) { PbStep1WaitForInstances.Image = Resources.failed_32; - MessageBox.Show($"HASS.Agent is still active after {MaxWaitSeconds} seconds. Please close all instances and restart manually.\r\n\r\nCheck the logs for more info, and optionally inform the developers.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show($"HASS.Agent is still active after {MaxWaitSeconds} seconds. Please close all instances and restart manually.\r\n\r\nCheck the logs for more info, and optionally inform the developers.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); // close up _ = HelperFunctions.ShutdownAsync(); diff --git a/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.Designer.cs b/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.Designer.cs index cdeb2e5..fd74def 100644 --- a/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.Designer.cs +++ b/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.Designer.cs @@ -54,9 +54,10 @@ private void InitializeComponent() this.BtnStore.Dock = System.Windows.Forms.DockStyle.Bottom; this.BtnStore.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnStore.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); - this.BtnStore.Location = new System.Drawing.Point(0, 295); + this.BtnStore.Location = new System.Drawing.Point(0, 367); + this.BtnStore.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.BtnStore.Name = "BtnStore"; - this.BtnStore.Size = new System.Drawing.Size(756, 38); + this.BtnStore.Size = new System.Drawing.Size(944, 48); this.BtnStore.Style.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(63)))), ((int)(((byte)(70))))); this.BtnStore.Style.FocusedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(63)))), ((int)(((byte)(70))))); this.BtnStore.Style.FocusedForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); @@ -75,9 +76,10 @@ private void InitializeComponent() this.TbSetting.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.TbSetting.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.TbSetting.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); - this.TbSetting.Location = new System.Drawing.Point(12, 156); + this.TbSetting.Location = new System.Drawing.Point(15, 195); + this.TbSetting.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.TbSetting.Name = "TbSetting"; - this.TbSetting.Size = new System.Drawing.Size(328, 25); + this.TbSetting.Size = new System.Drawing.Size(410, 29); this.TbSetting.TabIndex = 2; this.TbSetting.Visible = false; // @@ -87,18 +89,20 @@ private void InitializeComponent() this.TbName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.TbName.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.TbName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); - this.TbName.Location = new System.Drawing.Point(12, 95); + this.TbName.Location = new System.Drawing.Point(15, 119); + this.TbName.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.TbName.Name = "TbName"; - this.TbName.Size = new System.Drawing.Size(328, 25); + this.TbName.Size = new System.Drawing.Size(410, 29); this.TbName.TabIndex = 1; // // LblSetting // this.LblSetting.AutoSize = true; this.LblSetting.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.LblSetting.Location = new System.Drawing.Point(9, 136); + this.LblSetting.Location = new System.Drawing.Point(11, 170); + this.LblSetting.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.LblSetting.Name = "LblSetting"; - this.LblSetting.Size = new System.Drawing.Size(44, 17); + this.LblSetting.Size = new System.Drawing.Size(57, 23); this.LblSetting.TabIndex = 12; this.LblSetting.Text = "config"; this.LblSetting.Visible = false; @@ -107,9 +111,10 @@ private void InitializeComponent() // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(9, 19); + this.label1.Location = new System.Drawing.Point(11, 24); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(33, 17); + this.label1.Size = new System.Drawing.Size(43, 23); this.label1.TabIndex = 3; this.label1.Text = "type"; // @@ -117,9 +122,10 @@ private void InitializeComponent() // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label4.Location = new System.Drawing.Point(9, 75); + this.label4.Location = new System.Drawing.Point(11, 94); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(40, 17); + this.label4.Size = new System.Drawing.Size(53, 23); this.label4.TabIndex = 10; this.label4.Text = "name"; // @@ -127,9 +133,10 @@ private void InitializeComponent() // this.PnlDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.PnlDescription.Controls.Add(this.TbDescription); - this.PnlDescription.Location = new System.Drawing.Point(387, 39); + this.PnlDescription.Location = new System.Drawing.Point(484, 49); + this.PnlDescription.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.PnlDescription.Name = "PnlDescription"; - this.PnlDescription.Size = new System.Drawing.Size(354, 229); + this.PnlDescription.Size = new System.Drawing.Size(442, 286); this.PnlDescription.TabIndex = 21; // // TbDescription @@ -140,9 +147,10 @@ private void InitializeComponent() this.TbDescription.Dock = System.Windows.Forms.DockStyle.Fill; this.TbDescription.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); this.TbDescription.Location = new System.Drawing.Point(0, 0); + this.TbDescription.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.TbDescription.Name = "TbDescription"; this.TbDescription.ReadOnly = true; - this.TbDescription.Size = new System.Drawing.Size(352, 227); + this.TbDescription.Size = new System.Drawing.Size(440, 284); this.TbDescription.TabIndex = 18; this.TbDescription.Text = ""; this.TbDescription.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.TbDescription_LinkClicked); @@ -151,9 +159,10 @@ private void InitializeComponent() // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label5.Location = new System.Drawing.Point(384, 19); + this.label5.Location = new System.Drawing.Point(480, 24); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(135, 17); + this.label5.Size = new System.Drawing.Size(176, 23); this.label5.TabIndex = 20; this.label5.Text = "command description"; // @@ -167,9 +176,10 @@ private void InitializeComponent() this.CbType.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); this.CbType.FormattingEnabled = true; this.CbType.IntegralHeight = false; - this.CbType.Location = new System.Drawing.Point(12, 40); + this.CbType.Location = new System.Drawing.Point(15, 50); + this.CbType.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.CbType.Name = "CbType"; - this.CbType.Size = new System.Drawing.Size(328, 26); + this.CbType.Size = new System.Drawing.Size(409, 30); this.CbType.TabIndex = 25; this.CbType.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.CbType_DrawItem); this.CbType.SelectedIndexChanged += new System.EventHandler(this.CbType_SelectedIndexChanged); @@ -178,9 +188,10 @@ private void InitializeComponent() // this.CbRunAsLowIntegrity.AutoSize = true; this.CbRunAsLowIntegrity.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CbRunAsLowIntegrity.Location = new System.Drawing.Point(12, 207); + this.CbRunAsLowIntegrity.Location = new System.Drawing.Point(15, 259); + this.CbRunAsLowIntegrity.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.CbRunAsLowIntegrity.Name = "CbRunAsLowIntegrity"; - this.CbRunAsLowIntegrity.Size = new System.Drawing.Size(144, 21); + this.CbRunAsLowIntegrity.Size = new System.Drawing.Size(186, 27); this.CbRunAsLowIntegrity.TabIndex = 26; this.CbRunAsLowIntegrity.Text = "run as \'low integrity\'"; this.CbRunAsLowIntegrity.UseVisualStyleBackColor = true; @@ -190,9 +201,10 @@ private void InitializeComponent() this.LblIntegrityInfo.AutoSize = true; this.LblIntegrityInfo.Cursor = System.Windows.Forms.Cursors.Hand; this.LblIntegrityInfo.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.LblIntegrityInfo.Location = new System.Drawing.Point(187, 208); + this.LblIntegrityInfo.Location = new System.Drawing.Point(234, 260); + this.LblIntegrityInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.LblIntegrityInfo.Name = "LblIntegrityInfo"; - this.LblIntegrityInfo.Size = new System.Drawing.Size(74, 17); + this.LblIntegrityInfo.Size = new System.Drawing.Size(98, 23); this.LblIntegrityInfo.TabIndex = 27; this.LblIntegrityInfo.Text = "what\'s this?"; this.LblIntegrityInfo.Visible = false; @@ -202,9 +214,10 @@ private void InitializeComponent() // this.CbCommandSpecific.AutoSize = true; this.CbCommandSpecific.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CbCommandSpecific.Location = new System.Drawing.Point(12, 247); + this.CbCommandSpecific.Location = new System.Drawing.Point(15, 309); + this.CbCommandSpecific.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.CbCommandSpecific.Name = "CbCommandSpecific"; - this.CbCommandSpecific.Size = new System.Drawing.Size(32, 21); + this.CbCommandSpecific.Size = new System.Drawing.Size(39, 27); this.CbCommandSpecific.TabIndex = 28; this.CbCommandSpecific.Text = "-"; this.CbCommandSpecific.UseVisualStyleBackColor = true; @@ -212,22 +225,23 @@ private void InitializeComponent() // LblInfo // this.LblInfo.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.LblInfo.Location = new System.Drawing.Point(12, 193); + this.LblInfo.Location = new System.Drawing.Point(15, 241); + this.LblInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.LblInfo.Name = "LblInfo"; - this.LblInfo.Size = new System.Drawing.Size(328, 74); + this.LblInfo.Size = new System.Drawing.Size(410, 92); this.LblInfo.TabIndex = 29; this.LblInfo.Text = "-"; this.LblInfo.Visible = false; // // CommandsMod // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(48))))); this.CaptionBarColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(63)))), ((int)(((byte)(70))))); this.CaptionFont = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.CaptionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); - this.ClientSize = new System.Drawing.Size(756, 333); + this.ClientSize = new System.Drawing.Size(944, 415); this.Controls.Add(this.CbCommandSpecific); this.Controls.Add(this.LblIntegrityInfo); this.Controls.Add(this.CbRunAsLowIntegrity); @@ -245,6 +259,7 @@ private void InitializeComponent() this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(241)))), ((int)(((byte)(241)))), ((int)(((byte)(241))))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.MaximizeBox = false; this.MetroColor = System.Drawing.Color.FromArgb(((int)(((byte)(129)))), ((int)(((byte)(129)))), ((int)(((byte)(131))))); this.Name = "CommandsMod"; diff --git a/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.cs b/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.cs index d99909a..509e9c7 100644 --- a/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.cs +++ b/src/HASS.Agent/HASSAgent/Forms/Commands/CommandsMod.cs @@ -81,6 +81,12 @@ private void LoadCommand() TbSetting.Text = Command.KeyCode.ToString(); break; + case CommandType.MultipleKeysCommand: + var commands = new StringBuilder(); + foreach (var command in Command.Keys) commands.Append($"[{command}] "); + TbSetting.Text = commands.ToString().Trim(); + break; + case CommandType.LaunchUrlCommand: var urlInfo = Command.Command; if (string.IsNullOrEmpty(urlInfo)) break; @@ -113,7 +119,7 @@ private void BtnStore_Click(object sender, EventArgs e) var typeStr = CbType.Text; if (string.IsNullOrEmpty(typeStr)) { - MessageBox.Show("Select a type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Select a type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbType; return; } @@ -122,7 +128,7 @@ private void BtnStore_Click(object sender, EventArgs e) var name = TbName.Text.Trim(); if (string.IsNullOrEmpty(name)) { - MessageBox.Show("Enter a name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbName; return; } @@ -142,7 +148,7 @@ private void BtnStore_Click(object sender, EventArgs e) var parsed = Enum.TryParse(CbType.SelectedValue.ToString(), out var type); if (!parsed) { - MessageBox.Show("Select a valid type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Select a valid type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbType; return; } @@ -153,7 +159,7 @@ private void BtnStore_Click(object sender, EventArgs e) var command = TbSetting.Text.Trim(); if (string.IsNullOrEmpty(command)) { - MessageBox.Show("Enter a command first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a command first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting; return; } @@ -164,7 +170,7 @@ private void BtnStore_Click(object sender, EventArgs e) var script = TbSetting.Text.Trim(); if (string.IsNullOrEmpty(script)) { - MessageBox.Show("Enter a command or script first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a command or script first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting; return; } @@ -175,18 +181,29 @@ private void BtnStore_Click(object sender, EventArgs e) var keycode = TbSetting.Text.Trim(); if (string.IsNullOrEmpty(keycode)) { - MessageBox.Show("Enter a keycode first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a keycode first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting; return; } Command.KeyCode = Encoding.ASCII.GetBytes(keycode).First(); break; + case CommandType.MultipleKeysCommand: + var keysParsed = HelperFunctions.ParseMultipleKeys(TbSetting.Text.Trim(), out var keys, out var errorMsg); + if (!keysParsed) + { + MessageBoxAdv.Show($"Processing keys failed: {errorMsg}", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + ActiveControl = TbSetting; + return; + } + Command.Keys = keys; + break; + case CommandType.LaunchUrlCommand: var url = TbSetting.Text.Trim(); if (string.IsNullOrEmpty(url)) { - MessageBox.Show("Enter a URL first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a URL first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting; return; } @@ -204,12 +221,14 @@ private void BtnStore_Click(object sender, EventArgs e) var executorCommand = TbSetting.Text.Trim(); if (string.IsNullOrEmpty(executorCommand)) { - MessageBox.Show("Enter a command or script first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a command or script first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting; return; } Command.Command = executorCommand; break; + + } Command.RunAsLowIntegrity = CbRunAsLowIntegrity.CheckState == CheckState.Checked; @@ -264,6 +283,10 @@ private void SetType(bool setInfo = true) SetKeyGui(); break; + case CommandType.MultipleKeysCommand: + SetMultipleKeysGui(); + break; + case CommandType.LaunchUrlCommand: SetUrlGui(); break; @@ -346,6 +369,29 @@ private void SetKeyGui() })); } + /// + /// Change the UI to a 'multiple keys' type + /// + private void SetMultipleKeysGui() + { + Invoke(new MethodInvoker(delegate + { + LblSetting.Text = "keycodes"; + LblSetting.Visible = true; + TbSetting.Visible = true; + + CbRunAsLowIntegrity.CheckState = CheckState.Unchecked; + CbRunAsLowIntegrity.Visible = false; + LblIntegrityInfo.Visible = false; + + CbCommandSpecific.CheckState = CheckState.Unchecked; + CbCommandSpecific.Visible = false; + + LblInfo.Text = string.Empty; + LblInfo.Visible = false; + })); + } + /// /// Change the UI to a 'url' type /// diff --git a/src/HASS.Agent/HASSAgent/Forms/QuickActions/QuickActionsMod.cs b/src/HASS.Agent/HASSAgent/Forms/QuickActions/QuickActionsMod.cs index 2a88381..aa5bf4f 100644 --- a/src/HASS.Agent/HASSAgent/Forms/QuickActions/QuickActionsMod.cs +++ b/src/HASS.Agent/HASSAgent/Forms/QuickActions/QuickActionsMod.cs @@ -155,7 +155,7 @@ private void BtnStore_Click(object sender, EventArgs e) var entity = CbEntity.Text; if (string.IsNullOrEmpty(entity)) { - MessageBox.Show("Select an entity first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Select an entity first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbEntity; return; } @@ -164,7 +164,7 @@ private void BtnStore_Click(object sender, EventArgs e) var parsed = Enum.TryParse(CbDomain.SelectedValue.ToString(), out var domain); if (!parsed) { - MessageBox.Show("Unknown domain, please select a valid one.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Unknown domain, please select a valid one.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbDomain; return; } @@ -173,7 +173,7 @@ private void BtnStore_Click(object sender, EventArgs e) parsed = Enum.TryParse(CbAction.SelectedValue.ToString(), out var action); if (!parsed) { - MessageBox.Show("Unknown action, please select a valid one.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Unknown action, please select a valid one.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbAction; return; } diff --git a/src/HASS.Agent/HASSAgent/Forms/Sensors/SensorsMod.cs b/src/HASS.Agent/HASSAgent/Forms/Sensors/SensorsMod.cs index 2ca7a38..7791e0c 100644 --- a/src/HASS.Agent/HASSAgent/Forms/Sensors/SensorsMod.cs +++ b/src/HASS.Agent/HASSAgent/Forms/Sensors/SensorsMod.cs @@ -279,7 +279,7 @@ private void BtnStore_Click(object sender, EventArgs e) var typeStr = CbType.Text; if (string.IsNullOrEmpty(typeStr)) { - MessageBox.Show("Select a type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Select a type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbType; return; } @@ -287,7 +287,7 @@ private void BtnStore_Click(object sender, EventArgs e) var parsed = Enum.TryParse(CbType.SelectedValue.ToString(), out var type); if (!parsed) { - MessageBox.Show("Select a valid type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Select a valid type first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = CbType; return; } @@ -296,7 +296,7 @@ private void BtnStore_Click(object sender, EventArgs e) var name = TbName.Text.Trim(); if (string.IsNullOrEmpty(name)) { - MessageBox.Show("Enter a name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbName; return; } @@ -326,7 +326,7 @@ private void BtnStore_Click(object sender, EventArgs e) var interval = (int)TbIntInterval.IntegerValue; if (interval < 1 || interval > 43200) { - MessageBox.Show("Enter an interval between 1 and 43200 (12 hours) first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter an interval between 1 and 43200 (12 hours) first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbIntInterval; return; } @@ -338,7 +338,7 @@ private void BtnStore_Click(object sender, EventArgs e) var window = TbSetting1.Text.Trim(); if (string.IsNullOrEmpty(window)) { - MessageBox.Show("Enter a window name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a window name first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting1; return; } @@ -350,7 +350,7 @@ private void BtnStore_Click(object sender, EventArgs e) var scope = TbSetting2.Text.Trim(); if (string.IsNullOrEmpty(query)) { - MessageBox.Show("Enter a query first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a query first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting1; return; } @@ -364,7 +364,7 @@ private void BtnStore_Click(object sender, EventArgs e) var instance = TbSetting3.Text.Trim(); if (string.IsNullOrEmpty(category) || string.IsNullOrEmpty(counter)) { - MessageBox.Show("Enter a category and instance first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter a category and instance first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting1; return; } @@ -377,7 +377,7 @@ private void BtnStore_Click(object sender, EventArgs e) var process = TbSetting1.Text.Trim(); if (string.IsNullOrEmpty(process)) { - MessageBox.Show("Enter the name of a process first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter the name of a process first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting1; return; } @@ -388,7 +388,7 @@ private void BtnStore_Click(object sender, EventArgs e) var service = TbSetting1.Text.Trim(); if (string.IsNullOrEmpty(service)) { - MessageBox.Show("Enter the name of a service first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxAdv.Show("Enter the name of a service first.", "HASS.Agent", MessageBoxButtons.OK, MessageBoxIcon.Error); ActiveControl = TbSetting1; return; } diff --git a/src/HASS.Agent/HASSAgent/Functions/HelperFunctions.cs b/src/HASS.Agent/HASSAgent/Functions/HelperFunctions.cs index 4d8007d..46a5693 100644 --- a/src/HASS.Agent/HASSAgent/Functions/HelperFunctions.cs +++ b/src/HASS.Agent/HASSAgent/Functions/HelperFunctions.cs @@ -210,6 +210,60 @@ internal static async Task ShutdownAsync(TimeSpan waitBeforeClosing) Environment.Exit(1); } } + + /// + /// Tries to parse the keyString into multiple keys (they need to be encapsuled in square brackets) + /// + /// + /// + /// + /// + internal static bool ParseMultipleKeys(string keyString, out List keys, out string errorMsg) + { + keys = new List(); + errorMsg = string.Empty; + + try + { + // any value? + if (string.IsNullOrWhiteSpace(keyString)) + { + errorMsg = "no keys found"; + return false; + } + + // any brackets? + if (!keyString.Contains('[') || !keyString.Contains(']')) + { + errorMsg = "brackets missing, start and close all keys with [ ]"; + return false; + } + + // lets see if the brackets corresponds + var leftBrackets = keyString.Count(x => x == '['); + var rightBrackets = keyString.Count(x => x == ']'); + + if (leftBrackets != rightBrackets) + { + errorMsg = $"the number of '[' brackets don't correspond to the ']' ones ({leftBrackets} to {rightBrackets})"; + return false; + } + + // ok, try parsen + var pattern = @"\[(.*?)\]"; + var matches = Regex.Matches(keyString, pattern); + keys.AddRange(from Match m in matches select m.Groups[1].ToString()); + + // done + return true; + } + catch (Exception ex) + { + errorMsg = "error while parsing keys, check the log for more info"; + Log.Error("[PARSER] Error parsing multiple keys: {msg}", ex.Message); + return false; + } + } /// /// Determine the amount of columns and rows needed for the amount of quickactions diff --git a/src/HASS.Agent/HASSAgent/HASSAgent.csproj b/src/HASS.Agent/HASSAgent/HASSAgent.csproj index 248cb0b..bd1ae35 100644 --- a/src/HASS.Agent/HASSAgent/HASSAgent.csproj +++ b/src/HASS.Agent/HASSAgent/HASSAgent.csproj @@ -295,6 +295,7 @@ + @@ -303,6 +304,7 @@ + diff --git a/src/HASS.Agent/HASSAgent/Models/Config/ConfiguredCommand.cs b/src/HASS.Agent/HASSAgent/Models/Config/ConfiguredCommand.cs index 84ca495..59818b5 100644 --- a/src/HASS.Agent/HASSAgent/Models/Config/ConfiguredCommand.cs +++ b/src/HASS.Agent/HASSAgent/Models/Config/ConfiguredCommand.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using HASSAgent.Enums; using HASSAgent.Functions; using Newtonsoft.Json; @@ -29,5 +30,6 @@ public class ConfiguredCommand public byte KeyCode { get; set; } public bool RunAsLowIntegrity { get; set; } = false; public string Name { get; set; } + public List Keys { get; set; } = new List(); } } diff --git a/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Commands/MultipleKeysCommand.cs b/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Commands/MultipleKeysCommand.cs new file mode 100644 index 0000000..fde81eb --- /dev/null +++ b/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Commands/MultipleKeysCommand.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using Serilog; +using System.Windows.Forms; + +namespace HASSAgent.Models.HomeAssistant.Commands +{ + [SuppressMessage("ReSharper", "InconsistentNaming")] + public class MultipleKeysCommand : AbstractCommand + { + public List Keys { get; set; } + + internal MultipleKeysCommand(List keys, string name = "MultipleKeys", string id = default) : base(name ?? "MultipleKeys", id) + { + Keys = keys; + } + + public override DiscoveryConfigModel GetAutoDiscoveryConfig() + { + return new CommandDiscoveryConfigModel + { + Name = Name, + Unique_id = Id, + Availability_topic = $"{Variables.AppSettings.MqttDiscoveryPrefix}/sensor/{Variables.DeviceConfig.Name}/availability", + Command_topic = $"{Variables.AppSettings.MqttDiscoveryPrefix}/{Domain}/{Variables.DeviceConfig.Name}/{ObjectId}/set", + State_topic = $"{Variables.AppSettings.MqttDiscoveryPrefix}/{Domain}/{Variables.DeviceConfig.Name}/{ObjectId}/state", + Device = Variables.DeviceConfig + }; + } + + public override string GetState() => "OFF"; + + public override void TurnOff() + { + // + } + + public override async void TurnOn() + { + try + { + foreach (var key in Keys) + { + SendKeys.SendWait(key); + SendKeys.Flush(); + await Task.Delay(50); + } + } + catch (Exception ex) + { + Log.Error("[COMMAND] Launching command '{name}' failed: {ex}", Name, ex.Message); + } + } + } +} diff --git a/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Sensors/GeneralSensors/SingleValue/LoggedUserSensor.cs b/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Sensors/GeneralSensors/SingleValue/LoggedUserSensor.cs new file mode 100644 index 0000000..027ecf6 --- /dev/null +++ b/src/HASS.Agent/HASSAgent/Models/HomeAssistant/Sensors/GeneralSensors/SingleValue/LoggedUserSensor.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Text; +using HASSAgent.Functions; +using Newtonsoft.Json; +using Serilog; + +namespace HASSAgent.Models.HomeAssistant.Sensors.GeneralSensors.SingleValue +{ + public class LoggedUserSensor : AbstractSingleValueSensor + { + public LoggedUserSensor(int? updateInterval = null, string name = "loggeduser", string id = default) : base(name ?? "loggeduser", updateInterval ?? 10, id) { } + + public override DiscoveryConfigModel GetAutoDiscoveryConfig() + { + return AutoDiscoveryConfigModel ?? SetAutoDiscoveryConfigModel(new SensorDiscoveryConfigModel() + { + Name = Name, + Unique_id = Id, + Device = Variables.DeviceConfig, + State_topic = $"{Variables.AppSettings.MqttDiscoveryPrefix}/{Domain}/{Variables.DeviceConfig.Name}/{ObjectId}/state", + Icon = "mdi:account-group", + Availability_topic = $"{Variables.AppSettings.MqttDiscoveryPrefix}/{Domain}/{Variables.DeviceConfig.Name}/availability" + }); + } + + public override string GetState() => Environment.UserName; + } +} diff --git a/src/HASS.Agent/HASSAgent/Properties/AssemblyInfo.cs b/src/HASS.Agent/HASSAgent/Properties/AssemblyInfo.cs index 1abb00c..40980a5 100644 --- a/src/HASS.Agent/HASSAgent/Properties/AssemblyInfo.cs +++ b/src/HASS.Agent/HASSAgent/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2022.3.1.0")] -[assembly: AssemblyFileVersion("2022.3.1.0")] +[assembly: AssemblyVersion("2022.3.8.0")] +[assembly: AssemblyFileVersion("2022.3.8.0")] diff --git a/src/HASS.Agent/HASSAgent/Sensors/SensorsManager.cs b/src/HASS.Agent/HASSAgent/Sensors/SensorsManager.cs index e4b697d..dda814e 100644 --- a/src/HASS.Agent/HASSAgent/Sensors/SensorsManager.cs +++ b/src/HASS.Agent/HASSAgent/Sensors/SensorsManager.cs @@ -367,6 +367,7 @@ private static void LoadSensorInfo() SensorInfo.Add(SensorType.ProcessActiveSensor, ("Provides the number of active instances of the process.", 10)); SensorInfo.Add(SensorType.ServiceStateSensor, ("Returns the state of the provided service: NotFound, Stopped, StartPending, StopPending, Running, ContinuePending, PausePending or Paused.\r\n\r\nMake sure to provide the 'Service name', not the 'Display name'.", 10)); SensorInfo.Add(SensorType.LoggedUsersSensor, ("Returns a json-formatted list of currently logged users.", 30)); + SensorInfo.Add(SensorType.LoggedUserSensor, ("Returns the name of the currently logged user.", 30)); } } } diff --git a/src/HASS.Agent/HASSAgent/Settings/StoredCommands.cs b/src/HASS.Agent/HASSAgent/Settings/StoredCommands.cs index 8a5ebf4..1ea263d 100644 --- a/src/HASS.Agent/HASSAgent/Settings/StoredCommands.cs +++ b/src/HASS.Agent/HASSAgent/Settings/StoredCommands.cs @@ -148,6 +148,9 @@ internal static AbstractCommand ConvertConfiguredToAbstract(ConfiguredCommand co case CommandType.CustomExecutorCommand: abstractCommand = new CustomExecutorCommand(command.Name, command.Command, command.Id.ToString()); break; + case CommandType.MultipleKeysCommand: + abstractCommand = new MultipleKeysCommand(command.Keys, command.Name, command.Id.ToString()); + break; default: Log.Error("[SETTINGS_COMMANDS] [{name}] Unknown configured command type: {type}", command.Name, command.Type.ToString()); break; @@ -213,6 +216,18 @@ internal static ConfiguredCommand ConvertAbstractToConfigured(AbstractCommand co Type = type, }; } + + case MultipleKeysCommand multipleKeysCommand: + { + _ = Enum.TryParse(multipleKeysCommand.GetType().Name, out var type); + return new ConfiguredCommand() + { + Id = Guid.Parse(multipleKeysCommand.Id), + Name = multipleKeysCommand.Name, + Keys = multipleKeysCommand.Keys ?? new List(), + Type = type, + }; + } } return null; diff --git a/src/HASS.Agent/HASSAgent/Settings/StoredSensors.cs b/src/HASS.Agent/HASSAgent/Settings/StoredSensors.cs index b4f96f9..0f19139 100644 --- a/src/HASS.Agent/HASSAgent/Settings/StoredSensors.cs +++ b/src/HASS.Agent/HASSAgent/Settings/StoredSensors.cs @@ -161,6 +161,9 @@ internal static AbstractSingleValueSensor ConvertConfiguredToAbstractSingleValue case SensorType.LoggedUsersSensor: abstractSensor = new LoggedUsersSensor(sensor.UpdateInterval, sensor.Name, sensor.Id.ToString()); break; + case SensorType.LoggedUserSensor: + abstractSensor = new LoggedUserSensor(sensor.UpdateInterval, sensor.Name, sensor.Id.ToString()); + break; default: Log.Error("[SETTINGS_SENSORS] [{name}] Unknown configured single-value sensor type: {type}", sensor.Name, sensor.Type.ToString()); break;