From a248bd4f3059df190140260e6b9f9595057584c3 Mon Sep 17 00:00:00 2001 From: Ryan Wagoner Date: Wed, 28 Jul 2021 20:33:06 -0400 Subject: [PATCH] - Add MQTT area and zone user code support and update packages --- OmniLinkBridge/Extensions.cs | 11 +++++ OmniLinkBridge/MQTT/MessageProcessor.cs | 18 ++++++-- OmniLinkBridge/OmniLinkBridge.csproj | 13 +++--- OmniLinkBridgeTest/ExtensionTest.cs | 17 ++++++++ OmniLinkBridgeTest/MQTTTest.cs | 57 +++++++++++++++++-------- README.md | 4 ++ 6 files changed, 93 insertions(+), 27 deletions(-) diff --git a/OmniLinkBridge/Extensions.cs b/OmniLinkBridge/Extensions.cs index 681834f..a6af11e 100644 --- a/OmniLinkBridge/Extensions.cs +++ b/OmniLinkBridge/Extensions.cs @@ -24,6 +24,17 @@ namespace OmniLinkBridge return (b & (1 << pos)) != 0; } + public static (string, int) ToCommandCode(this string payload) + { + string[] payloads = payload.Split(','); + + int code = 0; + if (payloads.Length > 1) + int.TryParse(payloads[1], out code); + + return (payloads[0], code); + } + public static string ToSpaceTitleCase(this string phrase) { return Regex.Replace(phrase, "(\\B[A-Z])", " $1"); diff --git a/OmniLinkBridge/MQTT/MessageProcessor.cs b/OmniLinkBridge/MQTT/MessageProcessor.cs index c025886..8be0930 100644 --- a/OmniLinkBridge/MQTT/MessageProcessor.cs +++ b/OmniLinkBridge/MQTT/MessageProcessor.cs @@ -38,7 +38,7 @@ namespace OmniLinkBridge.MQTT if (type == CommandTypes.area && id <= OmniLink.Controller.Areas.Count) ProcessAreaReceived(OmniLink.Controller.Areas[id], topic, payload); - else if (type == CommandTypes.zone && id > 0 && id <= OmniLink.Controller.Zones.Count) + else if (type == CommandTypes.zone && id <= OmniLink.Controller.Zones.Count) ProcessZoneReceived(OmniLink.Controller.Zones[id], topic, payload); else if (type == CommandTypes.unit && id > 0 && id <= OmniLink.Controller.Units.Count) ProcessUnitReceived(OmniLink.Controller.Units[id], topic, payload); @@ -64,13 +64,16 @@ namespace OmniLinkBridge.MQTT private void ProcessAreaReceived(clsArea area, Topic command, string payload) { + int code; + (payload, code) = payload.ToCommandCode(); + if (command == Topic.command && Enum.TryParse(payload, true, out AreaCommands cmd)) { if (area.Number == 0) log.Debug("SetArea: 0 implies all areas will be changed"); log.Debug("SetArea: {id} to {value}", area.Number, cmd.ToString().Replace("arm_", "").Replace("_", " ")); - OmniLink.SendCommand(AreaMapping[cmd], 0, (ushort)area.Number); + OmniLink.SendCommand(AreaMapping[cmd], (byte)code, (ushort)area.Number); } else if (command == Topic.alarm_command && area.Number > 0 && Enum.TryParse(payload, true, out AlarmCommands alarm)) { @@ -92,10 +95,17 @@ namespace OmniLinkBridge.MQTT private void ProcessZoneReceived(clsZone zone, Topic command, string payload) { - if (command == Topic.command && Enum.TryParse(payload, true, out ZoneCommands cmd)) + int code; + (payload, code) = payload.ToCommandCode(); + + if (command == Topic.command && Enum.TryParse(payload, true, out ZoneCommands cmd) && + !(zone.Number == 0 && cmd == ZoneCommands.bypass)) { + if (zone.Number == 0) + log.Debug("SetZone: 0 implies all zones will be restored"); + log.Debug("SetZone: {id} to {value}", zone.Number, payload); - OmniLink.SendCommand(ZoneMapping[cmd], 0, (ushort)zone.Number); + OmniLink.SendCommand(ZoneMapping[cmd], (byte)code, (ushort)zone.Number); } } diff --git a/OmniLinkBridge/OmniLinkBridge.csproj b/OmniLinkBridge/OmniLinkBridge.csproj index 09a164d..6de1c37 100644 --- a/OmniLinkBridge/OmniLinkBridge.csproj +++ b/OmniLinkBridge/OmniLinkBridge.csproj @@ -173,10 +173,10 @@ 4.5.0 - 3.0.13 + 3.0.16 - 12.0.3 + 13.0.1 2.10.0 @@ -185,17 +185,20 @@ 1.1.0 - 1.4.0 + 1.5.0 - 3.1.1 + 4.0.0 - 4.1.0 + 5.0.0 7.2.0 + + 4.5.0 +