[homematic] Fix HM-IP long press button handling (#18570)

When starting a long press right after a short press, the short press
wrongly was emitted twice.

Reported in the forum: https://community.openhab.org/t/homematic-ip-wired-virtual-datapoints-of-buttons-long-press-fires-short-pressed-command/163673

Signed-off-by: Danny Baumann <dannybaumann@web.de>
This commit is contained in:
maniac103
2025-04-17 15:50:45 +02:00
committed by GitHub
parent 6632628e12
commit 1877c8b0cf
2 changed files with 15 additions and 3 deletions
@@ -80,10 +80,10 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
} }
case "LONG": case "LONG":
if (usesLongStart) { if (usesLongStart) {
// HM-IP devices do long press repetitions via LONG instead of CONT events, // HM-IP devices do long press repetitions via LONG instead of CONT events;
// so clear previous value to force re-triggering of event // besides that the logic is the same as in the CONT handling below
vdp.setValue(null);
if (isLongPressActive) { if (isLongPressActive) {
vdp.setValue(null);
vdp.setValue(LONG_REPEATED_EVENT); vdp.setValue(LONG_REPEATED_EVENT);
} }
} else { } else {
@@ -80,6 +80,12 @@ public class ButtonDatapointTest extends JavaTest {
HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE); HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
mockEventReceiver.eventReceived(releaseDp); mockEventReceiver.eventReceived(releaseDp);
assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED")); assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
// A CONT event right after a SHORT event should not trigger another SHORT_PRESSED event
HmDatapoint shortPressDp = createPressDatapointFrom(longPressDp, "PRESS_SHORT", Boolean.TRUE);
mockEventReceiver.eventReceived(shortPressDp);
mockEventReceiver.eventReceived(contPressDp);
assertThat(buttonVirtualDatapoint.getValue(), nullValue());
} }
@Test @Test
@@ -98,6 +104,12 @@ public class ButtonDatapointTest extends JavaTest {
HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE); HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
mockEventReceiver.eventReceived(releaseDp); mockEventReceiver.eventReceived(releaseDp);
assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED")); assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
// A LONG event right after a SHORT event should not trigger another SHORT_PRESSED event
HmDatapoint shortPressDp = createPressDatapointFrom(longPressDp, "PRESS_SHORT", Boolean.TRUE);
mockEventReceiver.eventReceived(shortPressDp);
mockEventReceiver.eventReceived(contPressDp);
assertThat(buttonVirtualDatapoint.getValue(), nullValue());
} }
@Test @Test