From b650454d944d74c54dca3e1932f22c28a7139d0e Mon Sep 17 00:00:00 2001 From: Daniel Rosengarten Date: Tue, 18 Jul 2023 19:54:20 +0200 Subject: [PATCH] [velbus] Fix multiple channel status in one packet (#15272) Fix bug : Manage more than one channel status in the packet. Signed-off-by: Daniel Rosengarten --- .../internal/handler/VelbusSensorHandler.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java index 744c71a25da..b86cf3e3d9e 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java @@ -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); - } + for (int channel = 0; channel < 8; channel++) { + byte channelMask = (byte) Math.pow(2, channel); - byte channelLongPressed = packet[7]; - if (channelLongPressed != 0) { - VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address, - channelLongPressed); - triggerChannel("input#" + getModuleAddress().getChannelId(velbusChannelIdentifier), - CommonTriggerEvents.LONG_PRESSED); + 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); + } } } }