use binary sensors if applicable

#21-media-commands
sleevezipper 4 years ago
parent d9e704f460
commit 30adab9dbd

@ -10,6 +10,7 @@ namespace hass_workstation_service.Domain.Sensors
public class MicrophoneActiveSensor : AbstractSensor public class MicrophoneActiveSensor : AbstractSensor
{ {
public override string Domain => "binary_sensor";
public MicrophoneActiveSensor(MqttPublisher publisher, int? updateInterval = null, string name = "MicrophoneActive", Guid id = default(Guid)) : base(publisher, name ?? "MicrophoneActive", updateInterval ?? 10, id) public MicrophoneActiveSensor(MqttPublisher publisher, int? updateInterval = null, string name = "MicrophoneActive", Guid id = default(Guid)) : base(publisher, name ?? "MicrophoneActive", updateInterval ?? 10, id)
{ {
} }
@ -17,7 +18,7 @@ namespace hass_workstation_service.Domain.Sensors
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
return IsMicrophoneInUse() ? "True" : "False"; return IsMicrophoneInUse() ? "ON" : "OFF";
} }
else return "unsupported"; else return "unsupported";
} }
@ -29,8 +30,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/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state",
Icon = "mdi:microphone", Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability"
Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability"
}); });
} }

@ -10,6 +10,7 @@ namespace hass_workstation_service.Domain.Sensors
{ {
public class NamedWindowSensor : AbstractSensor public class NamedWindowSensor : AbstractSensor
{ {
public override string Domain => "binary_sensor";
public string WindowName { get; protected set; } public string WindowName { get; protected set; }
public NamedWindowSensor(MqttPublisher publisher, string windowName, string name = "NamedWindow", int? updateInterval = 10, Guid id = default) : base(publisher, name ?? "NamedWindow", updateInterval ?? 10, id) public NamedWindowSensor(MqttPublisher publisher, string windowName, string name = "NamedWindow", int? updateInterval = 10, Guid id = default) : base(publisher, name ?? "NamedWindow", updateInterval ?? 10, id)
{ {
@ -24,15 +25,14 @@ 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/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state",
Icon = "mdi:window-maximize", Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability"
Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability"
}); });
} }
public override string GetState() public override string GetState()
{ {
var windowNames = GetOpenWindows().Values; var windowNames = GetOpenWindows().Values;
return windowNames.Any(v => v.Contains(this.WindowName, StringComparison.OrdinalIgnoreCase)) ? "True" : "False"; return windowNames.Any(v => v.Contains(this.WindowName, StringComparison.OrdinalIgnoreCase)) ? "ON" : "OFF";
} }

@ -9,14 +9,16 @@ namespace hass_workstation_service.Domain.Sensors
{ {
public class WebcamActiveSensor : AbstractSensor public class WebcamActiveSensor : AbstractSensor
{ {
public override string Domain => "binary_sensor";
public WebcamActiveSensor(MqttPublisher publisher, int? updateInterval = null, string name = "WebcamActive", Guid id = default) : base(publisher, name ?? "WebcamActive", updateInterval ?? 10, id) public WebcamActiveSensor(MqttPublisher publisher, int? updateInterval = null, string name = "WebcamActive", Guid id = default) : base(publisher, name ?? "WebcamActive", updateInterval ?? 10, id)
{ {
} }
public override string GetState() public override string GetState()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
return IsWebCamInUseRegistry() ? "True" : "False"; return IsWebCamInUseRegistry() ? "ON" : "OFF";
} }
else else
{ {
@ -31,8 +33,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/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state",
Icon = "mdi:webcam", Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability"
Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability"
}); });
} }

Loading…
Cancel
Save