From 30adab9dbdcbd536ef4fe4d99d09cd444c34a59b Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Fri, 19 Feb 2021 22:43:16 +0100 Subject: [PATCH] use binary sensors if applicable --- .../Domain/Sensors/MicrophoneActiveSensor.cs | 6 +++--- .../Domain/Sensors/NamedWindowSensor.cs | 6 +++--- .../Domain/Sensors/WebcamActiveSensor.cs | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hass-workstation-service/Domain/Sensors/MicrophoneActiveSensor.cs b/hass-workstation-service/Domain/Sensors/MicrophoneActiveSensor.cs index 8a6a246..1a79238 100644 --- a/hass-workstation-service/Domain/Sensors/MicrophoneActiveSensor.cs +++ b/hass-workstation-service/Domain/Sensors/MicrophoneActiveSensor.cs @@ -10,6 +10,7 @@ namespace hass_workstation_service.Domain.Sensors 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) { } @@ -17,7 +18,7 @@ namespace hass_workstation_service.Domain.Sensors { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return IsMicrophoneInUse() ? "True" : "False"; + return IsMicrophoneInUse() ? "ON" : "OFF"; } else return "unsupported"; } @@ -29,8 +30,7 @@ namespace hass_workstation_service.Domain.Sensors Unique_id = this.Id.ToString(), Device = this.Publisher.DeviceConfigModel, State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", - Icon = "mdi:microphone", - Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability" + Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability" }); } diff --git a/hass-workstation-service/Domain/Sensors/NamedWindowSensor.cs b/hass-workstation-service/Domain/Sensors/NamedWindowSensor.cs index 1a5dc64..4577584 100644 --- a/hass-workstation-service/Domain/Sensors/NamedWindowSensor.cs +++ b/hass-workstation-service/Domain/Sensors/NamedWindowSensor.cs @@ -10,6 +10,7 @@ namespace hass_workstation_service.Domain.Sensors { public class NamedWindowSensor : AbstractSensor { + public override string Domain => "binary_sensor"; 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) { @@ -24,15 +25,14 @@ namespace hass_workstation_service.Domain.Sensors Unique_id = this.Id.ToString(), Device = this.Publisher.DeviceConfigModel, State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", - Icon = "mdi:window-maximize", - Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability" + Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability" }); } public override string GetState() { 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"; } diff --git a/hass-workstation-service/Domain/Sensors/WebcamActiveSensor.cs b/hass-workstation-service/Domain/Sensors/WebcamActiveSensor.cs index 205e467..598d3f9 100644 --- a/hass-workstation-service/Domain/Sensors/WebcamActiveSensor.cs +++ b/hass-workstation-service/Domain/Sensors/WebcamActiveSensor.cs @@ -9,14 +9,16 @@ namespace hass_workstation_service.Domain.Sensors { 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 override string GetState() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return IsWebCamInUseRegistry() ? "True" : "False"; + return IsWebCamInUseRegistry() ? "ON" : "OFF"; } else { @@ -31,8 +33,7 @@ namespace hass_workstation_service.Domain.Sensors Unique_id = this.Id.ToString(), Device = this.Publisher.DeviceConfigModel, State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{this.Name}/state", - Icon = "mdi:webcam", - Availability_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/availability" + Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability" }); }