Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java
- index 03e6019f66..e2e63730fa 100644
- --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java
- +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java
- @@ -69,8 +69,12 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
- HmDatapoint vdp = getVirtualDatapoint(channel);
- int usPos = dp.getName().indexOf("_");
- String pressType = usPos == -1 ? dp.getName() : dp.getName().substring(usPos + 1);
- - boolean isLongPressActive = CommonTriggerEvents.LONG_PRESSED.equals(vdp.getValue())
- - || LONG_REPEATED_EVENT.equals(vdp.getValue());
- + Object previousValue = vdp.getValue();
- + boolean isLongPressActive = CommonTriggerEvents.LONG_PRESSED.equals(previousValue)
- + || LONG_REPEATED_EVENT.equals(previousValue);
- + logger.info("Handling virtual button event on {}:{}: dp {} = {}, vdp {}, long active {}, uses start {}",
- + deviceSerial, channel.getNumber(), dp.getName(), dp.getValue(), previousValue, isLongPressActive,
- + devicesUsingLongStartEvent.contains(deviceSerial));
- if (MiscUtils.isTrueValue(dp.getValue())) {
- switch (pressType) {
- case "SHORT": {
- @@ -84,9 +88,11 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
- // so clear previous value to force re-triggering of event
- vdp.setValue(null);
- vdp.setValue(LONG_REPEATED_EVENT);
- + logger.info("Handling LONG as repetition");
- } else {
- // HM devices start long press via LONG events
- vdp.setValue(CommonTriggerEvents.LONG_PRESSED);
- + logger.info("Handling LONG as start");
- }
- break;
- case "LONG_START":
- @@ -115,17 +121,18 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
- if (usedStartEvent.equals(pressType) && LONG_REPEATED_EVENT.equals(vdp.getValue())) {
- // If we're currently processing a repeated long-press event, don't let the initial LONG
- // event time out the repetitions, the CONT delay handler will take care of it
- + logger.info("start timeout while repetition");
- vdp.setValue(LONG_REPEATED_EVENT);
- } else if (isLongPressActive) {
- // We seemingly missed an event (either a CONT or the final LONG_RELEASE),
- // so end the long press cycle now
- + logger.info("repetition or end timeout -> released");
- vdp.setValue(LONG_RELEASED_EVENT);
- } else {
- vdp.setValue(null);
- }
- }
- - logger.debug("Handled virtual button event on {}:{}: press type {}, value {}, button state {} -> {}",
- - channel.getDevice().getAddress(), channel.getNumber(), pressType, dp.getValue(), vdp.getPreviousValue(),
- - vdp.getValue());
- + logger.info("Handled virtual button event on {}:{}: press type {}, value {}, button state {} -> {}",
- + deviceSerial, channel.getNumber(), pressType, dp.getValue(), previousValue, vdp.getValue());
- }
- }
- diff --git a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java
- index 02b6bdeeb3..8d88c0f5b7 100644
- --- a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java
- +++ b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java
- @@ -61,34 +61,62 @@ public class ButtonDatapointTest extends JavaTest {
- @Test
- public void testLongPressHm() throws IOException, HomematicClientException {
- - HmDatapoint longPressDp = createPressDatapoint("PRESS_LONG", Boolean.TRUE);
- + testLongPressCommon("PRESS_LONG", "PRESS_CONT", "PRESS_LONG_RELEASE");
- + }
- +
- + @Test
- + public void testLongPressHmIp() throws IOException, HomematicClientException {
- + testLongPressCommon("PRESS_LONG_START", "PRESS_LONG", "PRESS_LONG_RELEASE");
- + }
- +
- + private void testLongPressCommon(String startDpName, String contDpName, String releaseDpName)
- + throws IOException, HomematicClientException {
- + HmDatapoint longPressDp = createPressDatapoint(startDpName, Boolean.TRUE);
- HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(longPressDp);
- mockEventReceiver.eventReceived(longPressDp);
- assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.LONG_PRESSED));
- - HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, "PRESS_CONT", Boolean.TRUE);
- + HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, contDpName, Boolean.TRUE);
- mockEventReceiver.eventReceived(contPressDp);
- assertThat(buttonVirtualDatapoint.getValue(), is("LONG_REPEATED"));
- - HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
- + HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, releaseDpName, Boolean.TRUE);
- mockEventReceiver.eventReceived(releaseDp);
- assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
- }
- @Test
- - public void testLongPressHmIp() throws IOException, HomematicClientException {
- - HmDatapoint longPressDp = createPressDatapoint("PRESS_LONG_START", Boolean.TRUE);
- + public void testLongPressHmLateStart() throws IOException, HomematicClientException {
- + testLongPressLateStartCommon("PRESS_LONG", "PRESS_CONT", "PRESS_LONG_RELEASE");
- + }
- +
- + @Test
- + public void testLongPressHmIpLateStart() throws IOException, HomematicClientException {
- + testLongPressLateStartCommon("PRESS_LONG_START", "PRESS_CONT", "PRESS_LONG_RELEASE");
- + }
- +
- + private void testLongPressLateStartCommon(String startDpName, String contDpName, String releaseDpName)
- + throws IOException, HomematicClientException {
- + HmDatapoint longPressDp = createPressDatapoint(startDpName, Boolean.TRUE);
- + HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, contDpName, Boolean.TRUE);
- HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(longPressDp);
- + HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, releaseDpName, Boolean.TRUE);
- +
- + mockEventReceiver.eventReceived(contPressDp);
- + // If repetition arrives earlier than start, it's acceptable to yield either no or a LONG_PRESSED
- + // event. In the former case the start event will yield LONG_PRESSED, in the latter case the start
- + // event will not yield any event.
- + Object dpValueAfterCont = buttonVirtualDatapoint.getValue();
- + assertThat(dpValueAfterCont, anyOf(nullValue(), is(CommonTriggerEvents.LONG_PRESSED)));
- mockEventReceiver.eventReceived(longPressDp);
- assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.LONG_PRESSED));
- + assertThat(buttonVirtualDatapoint.getPreviousValue(), is(dpValueAfterCont));
- - HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, "PRESS_LONG", Boolean.TRUE);
- mockEventReceiver.eventReceived(contPressDp);
- assertThat(buttonVirtualDatapoint.getValue(), is("LONG_REPEATED"));
- - HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
- mockEventReceiver.eventReceived(releaseDp);
- assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement