Added: UpTime sensor

Changed: Icon for IdleTime sensor
pull/10/head
Pavel 4 years ago
parent 662c05ade5
commit c361b829dd

@ -131,6 +131,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;

@ -40,7 +40,8 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
MicrophoneActiveSensor,
ActiveWindowSensor,
NamedWindowSensor,
IdleTimeSensor
IdleTimeSensor,
UpTimeSensor
}
public enum WebcamDetectionMode

@ -94,6 +94,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.DetectionMode, configuredSensor.Id);
break;

@ -25,7 +25,7 @@ namespace hass_workstation_service.Domain.Sensors
Unique_id = this.Id.ToString(),
Device = this.Publisher.DeviceConfigModel,
State_topic = $"homeassistant/sensor/{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/{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