Merge pull request #10 from Diddlik/develop

Added: UpTime sensor
pull/19/head
sleevezipper 4 years ago committed by GitHub
commit d35497525e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -106,6 +106,9 @@ You can use [WMI Explorer](https://github.com/vinaypamnani/wmie2/tree/v2.0.0.2)
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.
### UpTime
This sensor returns the up time from windows in seconds
### Dummy
This sensor spits out a random number every second. Useful for testing, maybe you'll find some other use for it.

@ -143,6 +143,13 @@ namespace UserInterface.Views
item.ShowWindowNameInput = false;
item.UpdateInterval = 5;
break;
case AvailableSensors.UpTimeSensor:
item.Description = "This sensor returns the up time from windows in seconds";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#uptime";
item.ShowQueryInput = false;
item.ShowWindowNameInput = false;
item.UpdateInterval = 5;
break;
default:
item.Description = null;
item.MoreInfoLink = null;

@ -118,6 +118,9 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
case AvailableSensors.IdleTimeSensor:
sensorToCreate = new IdleTimeSensor(this._publisher,(int)model.UpdateInterval, model.Name);
break;
case AvailableSensors.UpTimeSensor:
sensorToCreate = new UpTimeSensor(this._publisher, (int)model.UpdateInterval, model.Name);
break;
default:
Log.Logger.Error("Unknown sensortype");
break;

@ -42,6 +42,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
MicrophoneActiveSensor,
ActiveWindowSensor,
NamedWindowSensor,
IdleTimeSensor
IdleTimeSensor,
UpTimeSensor
}
}

@ -99,6 +99,9 @@ namespace hass_workstation_service.Data
case "IdleTimeSensor":
sensor = new IdleTimeSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
case "UpTimeSensor":
sensor = new UpTimeSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
case "WebcamActiveSensor":
sensor = new WebcamActiveSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;

@ -17,7 +17,7 @@ namespace hass_workstation_service.Domain.Sensors
Unique_id = this.Id.ToString(),
Device = this.Publisher.DeviceConfigModel,
State_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/{this.Name}/state",
Icon = "mdi:window-maximize",
Icon = "mdi:clock-time-three-outline",
});
}

@ -0,0 +1,41 @@
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 UpTimeSensor : AbstractSensor
{
public UpTimeSensor(MqttPublisher publisher, int? updateInterval = 10, string name = "UpTime", Guid id = default) : base(publisher, name ?? "UpTime", updateInterval ?? 10, id)
{
}
public override AutoDiscoveryConfigModel GetAutoDiscoveryConfig()
{
return this._autoDiscoveryConfigModel ?? SetAutoDiscoveryConfigModel(new AutoDiscoveryConfigModel()
{
Name = this.Name,
Unique_id = this.Id.ToString(),
Device = this.Publisher.DeviceConfigModel,
State_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/{this.Name}/state",
Icon = "mdi:clock-time-three-outline",
});
}
public override string GetState()
{
return (GetTickCount64() / 1000).ToString(); //return in seconds
}
[DllImport("kernel32")]
extern static UInt64 GetTickCount64();
}
}
Loading…
Cancel
Save