From 85bb75b3328ef7a18939c548e49b7a2c3b75935f Mon Sep 17 00:00:00 2001 From: Generoso Martello Date: Fri, 4 Dec 2015 18:03:14 +0100 Subject: [PATCH] fix to switchbinary/multilevel cc --- ZWaveLib/CommandClasses/Basic.cs | 2 +- ZWaveLib/CommandClasses/SwitchBinary.cs | 15 ++++++++++----- ZWaveLib/CommandClasses/SwitchMultilevel.cs | 2 +- ZWaveLib/CommandClasses/WakeUp.cs | 2 +- ZWaveLib/Enums/EventParameter.cs | 4 +++- ZWaveLib/ZWaveLib.csproj | 2 +- ZWaveLib/ZWaveLib.nuspec | 8 ++++---- ZWaveLib/packages.config | 4 ++-- 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ZWaveLib/CommandClasses/Basic.cs b/ZWaveLib/CommandClasses/Basic.cs index e4345b4..05ada36 100644 --- a/ZWaveLib/CommandClasses/Basic.cs +++ b/ZWaveLib/CommandClasses/Basic.cs @@ -36,7 +36,7 @@ public NodeEvent GetEvent(ZWaveNode node, byte[] message) if (cmdType == (byte)Command.BasicReport || cmdType == (byte)Command.BasicSet) { int levelValue = (int)message[2]; - nodeEvent = new NodeEvent(node, EventParameter.Level, (double)levelValue, 0); + nodeEvent = new NodeEvent(node, EventParameter.Basic, (double)levelValue, 0); } return nodeEvent; } diff --git a/ZWaveLib/CommandClasses/SwitchBinary.cs b/ZWaveLib/CommandClasses/SwitchBinary.cs index 8680083..6945b9a 100644 --- a/ZWaveLib/CommandClasses/SwitchBinary.cs +++ b/ZWaveLib/CommandClasses/SwitchBinary.cs @@ -38,21 +38,26 @@ public NodeEvent GetEvent(ZWaveNode node, byte[] message) if (cmdType == (byte)Command.SwitchBinaryReport || cmdType == (byte)Command.SwitchBinarySet) // some devices use this instead of report { int levelValue = (int)message[2]; - nodeEvent = new NodeEvent(node, EventParameter.Level, (double)levelValue, 0); + nodeEvent = new NodeEvent(node, EventParameter.SwitchBinary, (double)levelValue, 0); } return nodeEvent; } public static ZWaveMessage Set(ZWaveNode node, int value) { - // same as basic class - return Basic.Set(node, value); + return node.SendDataRequest(new byte[] { + (byte)CommandClass.SwitchBinary, + (byte)Command.SwitchBinarySet, + byte.Parse(value.ToString()) + }); } public static ZWaveMessage Get(ZWaveNode node) { - // same as basic class - return Basic.Get(node); + return node.SendDataRequest(new byte[] { + (byte)CommandClass.SwitchBinary, + (byte)Command.SwitchBinaryGet + }); } } } diff --git a/ZWaveLib/CommandClasses/SwitchMultilevel.cs b/ZWaveLib/CommandClasses/SwitchMultilevel.cs index 6488800..e32f827 100644 --- a/ZWaveLib/CommandClasses/SwitchMultilevel.cs +++ b/ZWaveLib/CommandClasses/SwitchMultilevel.cs @@ -38,7 +38,7 @@ public NodeEvent GetEvent(ZWaveNode node, byte[] message) if (cmdType == (byte)Command.SwitchMultilevelReport || cmdType == (byte)Command.SwitchMultilevelSet) // some devices use this instead of report { int levelValue = (int)message[2]; - nodeEvent = new NodeEvent(node, EventParameter.Level, (double)levelValue, 0); + nodeEvent = new NodeEvent(node, EventParameter.SwitchMultilevel, (double)levelValue, 0); } return nodeEvent; } diff --git a/ZWaveLib/CommandClasses/WakeUp.cs b/ZWaveLib/CommandClasses/WakeUp.cs index f33ffb2..016ca01 100644 --- a/ZWaveLib/CommandClasses/WakeUp.cs +++ b/ZWaveLib/CommandClasses/WakeUp.cs @@ -118,7 +118,7 @@ public static void WakeUpNode(ZWaveNode node) public static void ResendOnWakeUp(ZWaveNode node, byte[] msg) { int minCommandLength = 8; - if (msg.Length >= minCommandLength && (msg[6] != (byte)CommandClass.WakeUp && msg[7] != (byte)Command.WakeUpNoMoreInfo)) + if (msg.Length >= minCommandLength && !(msg[6] == (byte)CommandClass.WakeUp && msg[7] == (byte)Command.WakeUpNoMoreInfo)) { byte[] command = new byte[minCommandLength]; Array.Copy(msg, 0, command, 0, minCommandLength); diff --git a/ZWaveLib/Enums/EventParameter.cs b/ZWaveLib/Enums/EventParameter.cs index 719d0f0..8a4f505 100644 --- a/ZWaveLib/Enums/EventParameter.cs +++ b/ZWaveLib/Enums/EventParameter.cs @@ -25,7 +25,9 @@ namespace ZWaveLib public enum EventParameter { - Level, + Basic, + SwitchBinary, + SwitchMultilevel, ManufacturerSpecific, MeterKwHour, MeterKvaHour, diff --git a/ZWaveLib/ZWaveLib.csproj b/ZWaveLib/ZWaveLib.csproj index 8ca0559..6bc9c66 100644 --- a/ZWaveLib/ZWaveLib.csproj +++ b/ZWaveLib/ZWaveLib.csproj @@ -40,7 +40,7 @@ ..\packages\NLog.4.1.0\lib\net45\NLog.dll - ..\packages\SerialPortLib.1.0.10\lib\SerialPortLib.dll + ..\packages\SerialPortLib.1.0.11\lib\SerialPortLib.dll diff --git a/ZWaveLib/ZWaveLib.nuspec b/ZWaveLib/ZWaveLib.nuspec index 90b1cee..219fb30 100644 --- a/ZWaveLib/ZWaveLib.nuspec +++ b/ZWaveLib/ZWaveLib.nuspec @@ -2,7 +2,7 @@ ZWaveLib - 1.0.9 + 1.0.10 ZWaveLib Generoso Martello G-Labs @@ -21,9 +21,9 @@ Features [Source Code and Home Page] https://github.com/genielabs/zwave-lib-dotnet Z-Wave library for Home Automation (.NET / Mono) - - Fixed packet fragmentation issue (affecting RaZberry) and timeout errors occurring with some devices (eg. Fibaro in wall switches). -- Added WakeUp.SendToSleep command -- Added WakeUp on NodeInfo + - Fixed WakeUp class bug, it was queuing send to sleep commands + - Fixed SwitchBinary class that was sending out messages as Basic cc + - Assigned proper events to Basic, SwitchBinary and SwitchMultilevel report G-Labs zwave z-wave home automation diff --git a/ZWaveLib/packages.config b/ZWaveLib/packages.config index 6bd5e0b..3e47985 100644 --- a/ZWaveLib/packages.config +++ b/ZWaveLib/packages.config @@ -1,5 +1,5 @@ - + - + \ No newline at end of file