Skip to content

Commit

Permalink
[automation] ActionInputsHelper: Set step size to 1 for datetime & ti…
Browse files Browse the repository at this point in the history
…me to enable seconds

Refs openhab/openhab-webui#2848.
Discussion in openhab/openhab-webui#2847 (comment).

Signed-off-by: Florian Hotze <dev@florianhotze.com>
  • Loading branch information
florian-h05 committed Nov 1, 2024
1 parent 728c737 commit 2c5e311
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ public ConfigDescriptionParameter mapActionInputToConfigDescriptionParameter(Inp
Unit<?> unit = null;
boolean required = false;
String context = null;
BigDecimal step = null;
Matcher matcher = QUANTITY_TYPE_PATTERN.matcher(input.getType());
if (matcher.matches()) {
parameterType = ConfigDescriptionParameter.Type.DECIMAL;
step = BigDecimal.ZERO;
try {
unit = getDefaultUnit(matcher.group("dimension"));
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -140,6 +142,7 @@ public ConfigDescriptionParameter mapActionInputToConfigDescriptionParameter(Inp
case "java.lang.Number":
case "org.openhab.core.library.types.DecimalType":
parameterType = ConfigDescriptionParameter.Type.DECIMAL;
step = BigDecimal.ZERO;
break;
case "java.lang.String":
break;
Expand All @@ -148,10 +151,12 @@ public ConfigDescriptionParameter mapActionInputToConfigDescriptionParameter(Inp
break;
case "java.time.LocalTime":
context = "time";
step = BigDecimal.ONE;
break;
case "java.time.LocalDateTime":
case "java.util.Date":
context = "datetime";
step = BigDecimal.ONE;
break;
case "java.time.ZonedDateTime":
case "java.time.Instant":
Expand All @@ -178,8 +183,8 @@ public ConfigDescriptionParameter mapActionInputToConfigDescriptionParameter(Inp
if (unit != null) {
builder = builder.withUnit(unit.getSymbol());
}
if (parameterType == ConfigDescriptionParameter.Type.DECIMAL) {
builder = builder.withStepSize(BigDecimal.ZERO);
if (step != null) {
builder = builder.withStepSize(step);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ public void testMapActionInputToConfigDescriptionParameterWhenLocalDate() {
@Test
public void testMapActionInputToConfigDescriptionParameterWhenLocalTime() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.time.LocalTime")),
ConfigDescriptionParameter.Type.TEXT, false, null, "time", null, null);
ConfigDescriptionParameter.Type.TEXT, false, null, "time", null, BigDecimal.ONE);
}

@Test
public void testMapActionInputToConfigDescriptionParameterWhenLocalDateTime() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.time.LocalDateTime")),
ConfigDescriptionParameter.Type.TEXT, false, null, "datetime", null, null);
ConfigDescriptionParameter.Type.TEXT, false, null, "datetime", null, BigDecimal.ONE);
}

@Test
public void testMapActionInputToConfigDescriptionParameterWhenDate() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.util.Date")),
ConfigDescriptionParameter.Type.TEXT, false, null, "datetime", null, null);
ConfigDescriptionParameter.Type.TEXT, false, null, "datetime", null, BigDecimal.ONE);
}

@Test
Expand Down

0 comments on commit 2c5e311

Please sign in to comment.