[automation] ActionInputsHelper: Set step size to 1 for datetime & time to enable seconds (#4436)

Refs https://github.com/openhab/openhab-webui/pull/2848.
Discussion in https://github.com/openhab/openhab-webui/issues/2847#issuecomment-2446426478.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
This commit is contained in:
Florian Hotze 2024-11-06 09:17:29 +01:00 committed by GitHub
parent 591d8d956a
commit a31e8376a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -102,9 +102,11 @@ public class ActionInputsHelper {
Unit<?> unit = null; Unit<?> unit = null;
boolean required = false; boolean required = false;
String context = null; String context = null;
BigDecimal step = null;
Matcher matcher = QUANTITY_TYPE_PATTERN.matcher(input.getType()); Matcher matcher = QUANTITY_TYPE_PATTERN.matcher(input.getType());
if (matcher.matches()) { if (matcher.matches()) {
parameterType = ConfigDescriptionParameter.Type.DECIMAL; parameterType = ConfigDescriptionParameter.Type.DECIMAL;
step = BigDecimal.ZERO;
try { try {
unit = getDefaultUnit(matcher.group("dimension")); unit = getDefaultUnit(matcher.group("dimension"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -140,6 +142,7 @@ public class ActionInputsHelper {
case "java.lang.Number": case "java.lang.Number":
case "org.openhab.core.library.types.DecimalType": case "org.openhab.core.library.types.DecimalType":
parameterType = ConfigDescriptionParameter.Type.DECIMAL; parameterType = ConfigDescriptionParameter.Type.DECIMAL;
step = BigDecimal.ZERO;
break; break;
case "java.lang.String": case "java.lang.String":
break; break;
@ -148,10 +151,12 @@ public class ActionInputsHelper {
break; break;
case "java.time.LocalTime": case "java.time.LocalTime":
context = "time"; context = "time";
step = BigDecimal.ONE;
break; break;
case "java.time.LocalDateTime": case "java.time.LocalDateTime":
case "java.util.Date": case "java.util.Date":
context = "datetime"; context = "datetime";
step = BigDecimal.ONE;
break; break;
case "java.time.ZonedDateTime": case "java.time.ZonedDateTime":
case "java.time.Instant": case "java.time.Instant":
@ -178,8 +183,8 @@ public class ActionInputsHelper {
if (unit != null) { if (unit != null) {
builder = builder.withUnit(unit.getSymbol()); builder = builder.withUnit(unit.getSymbol());
} }
if (parameterType == ConfigDescriptionParameter.Type.DECIMAL) { if (step != null) {
builder = builder.withStepSize(BigDecimal.ZERO); builder = builder.withStepSize(step);
} }
return builder.build(); return builder.build();
} }

View File

@ -152,19 +152,19 @@ public class ActionInputHelperTest {
@Test @Test
public void testMapActionInputToConfigDescriptionParameterWhenLocalTime() { public void testMapActionInputToConfigDescriptionParameterWhenLocalTime() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.time.LocalTime")), 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 @Test
public void testMapActionInputToConfigDescriptionParameterWhenLocalDateTime() { public void testMapActionInputToConfigDescriptionParameterWhenLocalDateTime() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.time.LocalDateTime")), 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 @Test
public void testMapActionInputToConfigDescriptionParameterWhenDate() { public void testMapActionInputToConfigDescriptionParameterWhenDate() {
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.util.Date")), 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 @Test