Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] ActionInputsHelper: Enable seconds for time & datetime #4436

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does one in this context mean? one second?

Copy link
Contributor Author

@florian-h05 florian-h05 Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.
The step size for datetime and time contexts defaults to 60 seconds, setting it to 1 second enables them to display seconds as well.

For reference: openhab/openhab-webui#2848.

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