Convert UpTimeSensor to LastBootSensor

pull/19/head
Chris Mancini 4 years ago
parent 776fd6274b
commit d8280bdd63

@ -106,9 +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
### LastBoot
This sensor returns theup time from Windows in seconds.
This sensor returns the date/time that Windows was last booted.
### SessionState

@ -142,9 +142,9 @@ namespace UserInterface.Views
item.ShowWindowNameInput = false;
item.UpdateInterval = 5;
break;
case AvailableSensors.UpTimeSensor:
item.Description = "This sensor returns the uptime from Windows in seconds";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#uptime";
case AvailableSensors.LastBootSensor:
item.Description = "This sensor returns the date/time that Windows was last booted";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#lastboot";
item.ShowQueryInput = false;
item.ShowWindowNameInput = false;
item.UpdateInterval = 5;

@ -118,8 +118,8 @@ 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);
case AvailableSensors.LastBootSensor:
sensorToCreate = new LastBootSensor(this._publisher, (int)model.UpdateInterval, model.Name);
break;
case AvailableSensors.SessionStateSensor:
sensorToCreate = new SessionStateSensor(this._publisher, (int)model.UpdateInterval, model.Name);

@ -43,7 +43,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
ActiveWindowSensor,
NamedWindowSensor,
IdleTimeSensor,
UpTimeSensor,
LastBootSensor,
SessionStateSensor
}
}

@ -96,8 +96,8 @@ 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);
case "LastBootSensor":
sensor = new LastBootSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
case "WebcamActiveSensor":
sensor = new WebcamActiveSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);

@ -26,8 +26,6 @@ namespace hass_workstation_service.Domain.Sensors
{
return GetLastInputTime().ToString();
}
static int GetLastInputTime()

@ -1,17 +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 UpTimeSensor : AbstractSensor
public class LastBootSensor : AbstractSensor
{
public UpTimeSensor(MqttPublisher publisher, int? updateInterval = 10, string name = "UpTime", Guid id = default) : base(publisher, name ?? "UpTime", updateInterval ?? 10, id)
public LastBootSensor(MqttPublisher publisher, int? updateInterval = 10, string name = "LastBoot", Guid id = default) : base(publisher, name ?? "LastBoot", updateInterval ?? 10, id)
{
@ -25,15 +21,13 @@ 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:clock-time-three-outline",
Unit_of_measurement = "seconds"
Icon = "mdi:clock-time-three-outline"
});
}
public override string GetState()
{
return (GetTickCount64() / 1000).ToString(); //return in seconds
return (DateTime.Now - TimeSpan.FromMilliseconds(GetTickCount64())).ToString("s");
}
[DllImport("kernel32")]
Loading…
Cancel
Save