From 92012fc0b764619580aa5a941b476cc967d9c85a Mon Sep 17 00:00:00 2001 From: Ryan Wagoner Date: Tue, 20 Jul 2021 23:28:10 -0400 Subject: [PATCH] 1.1.10 - Add MQTT zone bypass switch discovery --- OmniLinkBridge/MQTT/MappingExtensions.cs | 15 +++++++++++++++ OmniLinkBridge/MQTT/Switch.cs | 13 ++++++++++++- OmniLinkBridge/Modules/MQTTModule.cs | 3 +++ OmniLinkBridge/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/OmniLinkBridge/MQTT/MappingExtensions.cs b/OmniLinkBridge/MQTT/MappingExtensions.cs index e6d499d..bf85342 100644 --- a/OmniLinkBridge/MQTT/MappingExtensions.cs +++ b/OmniLinkBridge/MQTT/MappingExtensions.cs @@ -275,6 +275,21 @@ namespace OmniLinkBridge.MQTT return ret; } + public static Switch ToConfigSwitch(this clsZone zone) + { + Switch ret = new Switch + { + unique_id = $"{Global.mqtt_prefix}zone{zone.Number}switch", + name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Bypass", + state_topic = zone.ToTopic(Topic.state), + command_topic = zone.ToTopic(Topic.command), + payload_off = "restore", + payload_on = "bypass", + value_template = "{% if value == 'bypassed' %} bypass {%- else -%} restore {%- endif %}" + }; + return ret; + } + public static BinarySensor ToConfig(this clsZone zone) { BinarySensor ret = new BinarySensor diff --git a/OmniLinkBridge/MQTT/Switch.cs b/OmniLinkBridge/MQTT/Switch.cs index 55ed155..5a1e332 100644 --- a/OmniLinkBridge/MQTT/Switch.cs +++ b/OmniLinkBridge/MQTT/Switch.cs @@ -1,7 +1,18 @@ -namespace OmniLinkBridge.MQTT +using Newtonsoft.Json; + +namespace OmniLinkBridge.MQTT { public class Switch : Device { public string command_topic { get; set; } + + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public string payload_off { get; set; } + + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public string payload_on { get; set; } + + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public string value_template { get; set; } } } diff --git a/OmniLinkBridge/Modules/MQTTModule.cs b/OmniLinkBridge/Modules/MQTTModule.cs index 2e0f640..2f9da5d 100644 --- a/OmniLinkBridge/Modules/MQTTModule.cs +++ b/OmniLinkBridge/Modules/MQTTModule.cs @@ -277,6 +277,7 @@ namespace OmniLinkBridge.Modules { PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config", null); + PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/zone{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}humidity/config", null); continue; @@ -286,6 +287,8 @@ namespace OmniLinkBridge.Modules JsonConvert.SerializeObject(zone.ToConfig())); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config", JsonConvert.SerializeObject(zone.ToConfigSensor())); + PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/zone{i}/config", + JsonConvert.SerializeObject(zone.ToConfigSwitch())); if (zone.IsTemperatureZone()) PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config", diff --git a/OmniLinkBridge/Properties/AssemblyInfo.cs b/OmniLinkBridge/Properties/AssemblyInfo.cs index 2b0dbb2..1fd737e 100644 --- a/OmniLinkBridge/Properties/AssemblyInfo.cs +++ b/OmniLinkBridge/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.9.0")] -[assembly: AssemblyFileVersion("1.1.9.0")] +[assembly: AssemblyVersion("1.1.10.0")] +[assembly: AssemblyFileVersion("1.1.10.0")]