You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using hass_workstation_service.Communication;
|
|
|
|
namespace hass_workstation_service.Domain.Sensors
|
|
{
|
|
public class DummySensor : AbstractSensor
|
|
{
|
|
private readonly Random _random;
|
|
public DummySensor(MqttPublisher publisher, string name = "Dummy")
|
|
{
|
|
this.Id = Guid.NewGuid();
|
|
this.Name = name;
|
|
this.Publisher = publisher;
|
|
this._random = new Random();
|
|
}
|
|
|
|
public DummySensor(MqttPublisher publisher, string name, Guid id)
|
|
{
|
|
this.Id = id;
|
|
this.Name = name;
|
|
this.Publisher = publisher;
|
|
this._random = new Random();
|
|
}
|
|
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"
|
|
});
|
|
}
|
|
|
|
public override string GetState()
|
|
{
|
|
return _random.Next(0, 100).ToString();
|
|
}
|
|
}
|
|
} |