Skip to content

Commit

Permalink
1.1.10 - Add MQTT zone bypass switch discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
rwagoner committed Jul 21, 2021
1 parent 37aed0e commit 92012fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
15 changes: 15 additions & 0 deletions OmniLinkBridge/MQTT/MappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ public static Sensor ToConfigSensor(this clsZone zone)
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
Expand Down
13 changes: 12 additions & 1 deletion OmniLinkBridge/MQTT/Switch.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
3 changes: 3 additions & 0 deletions OmniLinkBridge/Modules/MQTTModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ private void PublishZones()
{
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;
Expand All @@ -286,6 +287,8 @@ private void PublishZones()
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",
Expand Down
4 changes: 2 additions & 2 deletions OmniLinkBridge/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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")]

0 comments on commit 92012fc

Please sign in to comment.