From dfc8d6cdf31c35d61c1d30908609a5e5a53546a6 Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Fri, 8 Jan 2021 17:49:35 +0100 Subject: [PATCH] update UI and readme for idleTime sensor --- README.md | 4 ++++ UserInterface/Views/AddSensorDialog.axaml.cs | 7 +++++++ .../Domain/Sensors/IdleTimeSensor.cs | 13 ++----------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ea2b8cc..7a1a3d6 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ which results in `4008` for my PC. You can use [WMI Explorer](https://github.com/vinaypamnani/wmie2/tree/v2.0.0.2) to find see what data is available. +### IdleTime + +This sensor returns the amount of seconds the workstation has been idle for. It starts counting the moment you stop typing or moving your mouse. + ### Dummy This sensor spits out a random number every second. Useful for testing, maybe you'll find some other use for it. diff --git a/UserInterface/Views/AddSensorDialog.axaml.cs b/UserInterface/Views/AddSensorDialog.axaml.cs index 66e37da..8bdb602 100644 --- a/UserInterface/Views/AddSensorDialog.axaml.cs +++ b/UserInterface/Views/AddSensorDialog.axaml.cs @@ -139,6 +139,13 @@ namespace UserInterface.Views item.ShowWindowNameInput = true; item.UpdateInterval = 5; break; + case AvailableSensors.IdleTimeSensor: + item.Description = "This sensor returns the amount of seconds the workstation has been idle for. "; + item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#idletime"; + item.ShowQueryInput = false; + item.ShowWindowNameInput = false; + item.UpdateInterval = 5; + break; default: item.Description = null; item.MoreInfoLink = null; diff --git a/hass-workstation-service/Domain/Sensors/IdleTimeSensor.cs b/hass-workstation-service/Domain/Sensors/IdleTimeSensor.cs index 25ca311..870bf79 100644 --- a/hass-workstation-service/Domain/Sensors/IdleTimeSensor.cs +++ b/hass-workstation-service/Domain/Sensors/IdleTimeSensor.cs @@ -1,21 +1,13 @@ using hass_workstation_service.Communication; using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using HWND = System.IntPtr; namespace hass_workstation_service.Domain.Sensors { public class IdleTimeSensor : AbstractSensor { - public IdleTimeSensor(MqttPublisher publisher, int? updateInterval = 10, string name = "IdleTime", Guid id = default) : base(publisher, name ?? "IdleTime", updateInterval ?? 10, id) - { - - - } + public IdleTimeSensor(MqttPublisher publisher, int? updateInterval = 10, string name = "IdleTime", Guid id = default) : base(publisher, name ?? "IdleTime", updateInterval ?? 10, id){} public override AutoDiscoveryConfigModel GetAutoDiscoveryConfig() { @@ -24,14 +16,13 @@ namespace hass_workstation_service.Domain.Sensors Name = this.Name, Unique_id = this.Id.ToString(), Device = this.Publisher.DeviceConfigModel, - State_topic = $"homeassistant/sensor/{this.Name}/state", + State_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", Icon = "mdi:window-maximize", }); } public override string GetState() { - return GetLastInputTime().ToString(); }