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: case AvailableSensors.IdleTimeSensor:
sensorToCreate = new IdleTimeSensor(this._publisher,(int)model.UpdateInterval, model.Name); sensorToCreate = new IdleTimeSensor(this._publisher,(int)model.UpdateInterval, model.Name);
break; break;
case AvailableSensors.UpTimeSensor:
sensorToCreate = new UpTimeSensor(this._publisher, (int)model.UpdateInterval, model.Name);
break;
default: default:
Log.Logger.Error("Unknown sensortype"); Log.Logger.Error("Unknown sensortype");
break; break;

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

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

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