Advertisement
Guest User

Untitled

a guest
Jan 20th, 2022
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.38 KB | None | 0 0
  1. 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
  2. index 03e6019f66..e2e63730fa 100644
  3. --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java
  4. +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java
  5. @@ -69,8 +69,12 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
  6.          HmDatapoint vdp = getVirtualDatapoint(channel);
  7.          int usPos = dp.getName().indexOf("_");
  8.          String pressType = usPos == -1 ? dp.getName() : dp.getName().substring(usPos + 1);
  9. -        boolean isLongPressActive = CommonTriggerEvents.LONG_PRESSED.equals(vdp.getValue())
  10. -                || LONG_REPEATED_EVENT.equals(vdp.getValue());
  11. +        Object previousValue = vdp.getValue();
  12. +        boolean isLongPressActive = CommonTriggerEvents.LONG_PRESSED.equals(previousValue)
  13. +                || LONG_REPEATED_EVENT.equals(previousValue);
  14. +        logger.info("Handling virtual button event on {}:{}: dp {} = {}, vdp {}, long active {}, uses start {}",
  15. +                deviceSerial, channel.getNumber(), dp.getName(), dp.getValue(), previousValue, isLongPressActive,
  16. +                devicesUsingLongStartEvent.contains(deviceSerial));
  17.          if (MiscUtils.isTrueValue(dp.getValue())) {
  18.              switch (pressType) {
  19.                  case "SHORT": {
  20. @@ -84,9 +88,11 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
  21.                          // so clear previous value to force re-triggering of event
  22.                          vdp.setValue(null);
  23.                          vdp.setValue(LONG_REPEATED_EVENT);
  24. +                        logger.info("Handling LONG as repetition");
  25.                      } else {
  26.                          // HM devices start long press via LONG events
  27.                          vdp.setValue(CommonTriggerEvents.LONG_PRESSED);
  28. +                        logger.info("Handling LONG as start");
  29.                      }
  30.                      break;
  31.                  case "LONG_START":
  32. @@ -115,17 +121,18 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
  33.              if (usedStartEvent.equals(pressType) && LONG_REPEATED_EVENT.equals(vdp.getValue())) {
  34.                  // If we're currently processing a repeated long-press event, don't let the initial LONG
  35.                  // event time out the repetitions, the CONT delay handler will take care of it
  36. +                logger.info("start timeout while repetition");
  37.                  vdp.setValue(LONG_REPEATED_EVENT);
  38.              } else if (isLongPressActive) {
  39.                  // We seemingly missed an event (either a CONT or the final LONG_RELEASE),
  40.                  // so end the long press cycle now
  41. +                logger.info("repetition or end timeout -> released");
  42.                  vdp.setValue(LONG_RELEASED_EVENT);
  43.              } else {
  44.                  vdp.setValue(null);
  45.              }
  46.          }
  47. -        logger.debug("Handled virtual button event on {}:{}: press type {}, value {}, button state {} -> {}",
  48. -                channel.getDevice().getAddress(), channel.getNumber(), pressType, dp.getValue(), vdp.getPreviousValue(),
  49. -                vdp.getValue());
  50. +        logger.info("Handled virtual button event on {}:{}: press type {}, value {}, button state {} -> {}",
  51. +                deviceSerial, channel.getNumber(), pressType, dp.getValue(), previousValue, vdp.getValue());
  52.      }
  53.  }
  54. 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
  55. index 02b6bdeeb3..8d88c0f5b7 100644
  56. --- a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java
  57. +++ b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonDatapointTest.java
  58. @@ -61,34 +61,62 @@ public class ButtonDatapointTest extends JavaTest {
  59.  
  60.      @Test
  61.      public void testLongPressHm() throws IOException, HomematicClientException {
  62. -        HmDatapoint longPressDp = createPressDatapoint("PRESS_LONG", Boolean.TRUE);
  63. +        testLongPressCommon("PRESS_LONG", "PRESS_CONT", "PRESS_LONG_RELEASE");
  64. +    }
  65. +
  66. +    @Test
  67. +    public void testLongPressHmIp() throws IOException, HomematicClientException {
  68. +        testLongPressCommon("PRESS_LONG_START", "PRESS_LONG", "PRESS_LONG_RELEASE");
  69. +    }
  70. +
  71. +    private void testLongPressCommon(String startDpName, String contDpName, String releaseDpName)
  72. +            throws IOException, HomematicClientException {
  73. +        HmDatapoint longPressDp = createPressDatapoint(startDpName, Boolean.TRUE);
  74.          HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(longPressDp);
  75.  
  76.          mockEventReceiver.eventReceived(longPressDp);
  77.          assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.LONG_PRESSED));
  78.  
  79. -        HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, "PRESS_CONT", Boolean.TRUE);
  80. +        HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, contDpName, Boolean.TRUE);
  81.          mockEventReceiver.eventReceived(contPressDp);
  82.          assertThat(buttonVirtualDatapoint.getValue(), is("LONG_REPEATED"));
  83.  
  84. -        HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
  85. +        HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, releaseDpName, Boolean.TRUE);
  86.          mockEventReceiver.eventReceived(releaseDp);
  87.          assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
  88.      }
  89.  
  90.      @Test
  91. -    public void testLongPressHmIp() throws IOException, HomematicClientException {
  92. -        HmDatapoint longPressDp = createPressDatapoint("PRESS_LONG_START", Boolean.TRUE);
  93. +    public void testLongPressHmLateStart() throws IOException, HomematicClientException {
  94. +        testLongPressLateStartCommon("PRESS_LONG", "PRESS_CONT", "PRESS_LONG_RELEASE");
  95. +    }
  96. +
  97. +    @Test
  98. +    public void testLongPressHmIpLateStart() throws IOException, HomematicClientException {
  99. +        testLongPressLateStartCommon("PRESS_LONG_START", "PRESS_CONT", "PRESS_LONG_RELEASE");
  100. +    }
  101. +
  102. +    private void testLongPressLateStartCommon(String startDpName, String contDpName, String releaseDpName)
  103. +            throws IOException, HomematicClientException {
  104. +        HmDatapoint longPressDp = createPressDatapoint(startDpName, Boolean.TRUE);
  105. +        HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, contDpName, Boolean.TRUE);
  106.          HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(longPressDp);
  107. +        HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, releaseDpName, Boolean.TRUE);
  108. +
  109. +        mockEventReceiver.eventReceived(contPressDp);
  110. +        // If repetition arrives earlier than start, it's acceptable to yield either no or a LONG_PRESSED
  111. +        // event. In the former case the start event will yield LONG_PRESSED, in the latter case the start
  112. +        // event will not yield any event.
  113. +        Object dpValueAfterCont = buttonVirtualDatapoint.getValue();
  114. +        assertThat(dpValueAfterCont, anyOf(nullValue(), is(CommonTriggerEvents.LONG_PRESSED)));
  115.  
  116.          mockEventReceiver.eventReceived(longPressDp);
  117.          assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.LONG_PRESSED));
  118. +        assertThat(buttonVirtualDatapoint.getPreviousValue(), is(dpValueAfterCont));
  119.  
  120. -        HmDatapoint contPressDp = createPressDatapointFrom(longPressDp, "PRESS_LONG", Boolean.TRUE);
  121.          mockEventReceiver.eventReceived(contPressDp);
  122.          assertThat(buttonVirtualDatapoint.getValue(), is("LONG_REPEATED"));
  123.  
  124. -        HmDatapoint releaseDp = createPressDatapointFrom(longPressDp, "PRESS_LONG_RELEASE", Boolean.TRUE);
  125.          mockEventReceiver.eventReceived(releaseDp);
  126.          assertThat(buttonVirtualDatapoint.getValue(), is("LONG_RELEASED"));
  127.      }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement