]> git.basschouten.com Git - openhab-addons.git/commitdiff
[velbus] Fix multiple channel status in one packet (#15272)
authorDaniel Rosengarten <github@praetorians.be>
Tue, 18 Jul 2023 17:54:20 +0000 (19:54 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Jul 2023 17:54:20 +0000 (19:54 +0200)
Fix bug : Manage more than one channel status in the packet.

Signed-off-by: Daniel Rosengarten <github@praetorians.be>
bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java

index 744c71a25daf4f619b21895cd7afe5b9e0358a42..b86cf3e3d9e19740e2bbe8f9fcb3395044ebeb08 100644 (file)
@@ -141,28 +141,33 @@ public class VelbusSensorHandler extends VelbusThingHandler {
             byte command = packet[4];
 
             if (command == COMMAND_PUSH_BUTTON_STATUS && packet.length >= 6) {
-                byte channelJustPressed = packet[5];
-                if (channelJustPressed != 0) {
-                    VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
-                            channelJustPressed);
-                    triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
-                            CommonTriggerEvents.PRESSED);
-                }
-
-                byte channelJustReleased = packet[6];
-                if (channelJustReleased != 0) {
-                    VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
-                            channelJustReleased);
-                    triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
-                            CommonTriggerEvents.RELEASED);
-                }
 
-                byte channelLongPressed = packet[7];
-                if (channelLongPressed != 0) {
-                    VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
-                            channelLongPressed);
-                    triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
-                            CommonTriggerEvents.LONG_PRESSED);
+                for (int channel = 0; channel < 8; channel++) {
+                    byte channelMask = (byte) Math.pow(2, channel);
+
+                    byte channelJustPressed = (byte) (packet[5] & channelMask);
+                    if (channelJustPressed != 0) {
+                        VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
+                                channelJustPressed);
+                        triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
+                                CommonTriggerEvents.PRESSED);
+                    }
+
+                    byte channelJustReleased = (byte) (packet[6] & channelMask);
+                    if (channelJustReleased != 0) {
+                        VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
+                                channelJustReleased);
+                        triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
+                                CommonTriggerEvents.RELEASED);
+                    }
+
+                    byte channelLongPressed = (byte) (packet[7] & channelMask);
+                    if (channelLongPressed != 0) {
+                        VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address,
+                                channelLongPressed);
+                        triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier),
+                                CommonTriggerEvents.LONG_PRESSED);
+                    }
                 }
             }
         }