[bluetooth.enoceanble] Prevent that channels are triggered multiple times per click (#11381)
Signed-off-by: Patrick Fink <mail@pfink.de>
This commit is contained in:
parent
04ba8d3e5e
commit
3fc968a980
|
@ -12,6 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth.enoceanble.internal;
|
package org.openhab.binding.bluetooth.enoceanble.internal;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,9 +32,15 @@ public class EnoceanBlePtm215Event {
|
||||||
private static final byte BUTTON2_DIR2 = 0x2;
|
private static final byte BUTTON2_DIR2 = 0x2;
|
||||||
|
|
||||||
private final byte byteState;
|
private final byte byteState;
|
||||||
|
private final int sequence;
|
||||||
|
|
||||||
public EnoceanBlePtm215Event(byte[] manufacturerData) {
|
public EnoceanBlePtm215Event(byte[] manufacturerData) {
|
||||||
byteState = manufacturerData[6];
|
byteState = manufacturerData[6];
|
||||||
|
|
||||||
|
byte[] sequenceBytes = new byte[] { manufacturerData[5], manufacturerData[4], manufacturerData[3],
|
||||||
|
manufacturerData[2] };
|
||||||
|
ByteBuffer sequenceBytesBuffered = ByteBuffer.wrap(sequenceBytes); // big-endian by default
|
||||||
|
sequence = sequenceBytesBuffered.getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPressed() {
|
public boolean isPressed() {
|
||||||
|
@ -59,9 +67,13 @@ public class EnoceanBlePtm215Event {
|
||||||
return (byteState & flag) == flag;
|
return (byteState & flag) == flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSequence() {
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Button " + (isButton1() ? 1 : 2) + " Dir " + (isDir1() ? 1 : 2) + " "
|
return "Button " + (isButton1() ? 1 : 2) + " Dir " + (isDir1() ? 1 : 2) + " "
|
||||||
+ (isPressed() ? "PRESSED" : "RELEASED");
|
+ (isPressed() ? "PRESSED" : "RELEASED") + " (seq. " + this.sequence + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||||
public class EnoceanBleRockerHandler extends BeaconBluetoothHandler {
|
public class EnoceanBleRockerHandler extends BeaconBluetoothHandler {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(EnoceanBleRockerHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(EnoceanBleRockerHandler.class);
|
||||||
|
private int lastSequence = Integer.MIN_VALUE;
|
||||||
|
|
||||||
public EnoceanBleRockerHandler(Thing thing) {
|
public EnoceanBleRockerHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
|
@ -44,7 +45,12 @@ public class EnoceanBleRockerHandler extends BeaconBluetoothHandler {
|
||||||
if (manufacturerData != null && manufacturerData.length > 0) {
|
if (manufacturerData != null && manufacturerData.length > 0) {
|
||||||
EnoceanBlePtm215Event event = new EnoceanBlePtm215Event(manufacturerData);
|
EnoceanBlePtm215Event event = new EnoceanBlePtm215Event(manufacturerData);
|
||||||
logger.debug("Parsed manufacturer data to PTM215B event: {}", event);
|
logger.debug("Parsed manufacturer data to PTM215B event: {}", event);
|
||||||
triggerChannel(resolveChannel(event), resolveTriggerEvent(event));
|
synchronized (this) {
|
||||||
|
if (event.getSequence() > lastSequence) {
|
||||||
|
lastSequence = event.getSequence();
|
||||||
|
triggerChannel(resolveChannel(event), resolveTriggerEvent(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
logger.warn("PTM215B event could not be parsed correctly, exception occured:", e);
|
logger.warn("PTM215B event could not be parsed correctly, exception occured:", e);
|
||||||
|
|
Loading…
Reference in New Issue