[DSL generator] Handle config parameter value of type Double (#4629)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo
2025-03-09 10:51:09 +01:00
committed by GitHub
parent 67303fa5f3
commit 3af47e9c30
2 changed files with 13 additions and 0 deletions
@@ -13,6 +13,7 @@
package org.openhab.core.model.item.internal.fileconverter;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -191,6 +192,11 @@ public class DslItemFileConverter extends AbstractItemFileGenerator {
} else {
property = null;
}
} else if (value instanceof Double doubleValue) {
// It was discovered that configuration parameter value of an item metadata can be of type Double
// when the metadata is added through Main UI.
// A conversion to a BigDecimal is then required to avoid an exception later when generating DSL
property.getValue().add(BigDecimal.valueOf(doubleValue));
} else {
property.getValue().add(value);
}
@@ -15,6 +15,7 @@ package org.openhab.core.model.thing.internal.fileconverter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -184,6 +185,12 @@ public class DslThingFileConverter extends AbstractThingFileGenerator {
} else {
property = null;
}
} else if (value instanceof Double doubleValue) {
// DSL thing syntax does not like a configuration parameter value provided as Double type.
// By security, we apply a conversion to a BigDecimal in case this would happen.
logger.debug("Configuration parameter {} with value {} is provided unexpectedly as Double type", key,
value);
property.getValue().add(BigDecimal.valueOf(doubleValue));
} else {
property.getValue().add(value);
}