Skip to content

Commit 788b40f

Browse files
authored
[DSL generator] Check that metadata config value type is supported (#4720)
Signed-off-by: Laurent Garnier <[email protected]>
1 parent a085b03 commit 788b40f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemFileConverter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ private ModelItem buildModelItem(Item item, List<Metadata> channelLinks, List<Me
152152
ModelProperty property = buildModelProperty(param.name(), param.value());
153153
if (property != null) {
154154
binding.getProperties().add(property);
155+
} else {
156+
logger.warn(
157+
"Item \"{}\": configuration parameter \"{}\" for channel link \"{}\" is ignored because its value type is not supported!",
158+
item.getName(), param.name(), md.getValue());
155159
}
156160
}
157161
model.getBindings().add(binding);
@@ -167,6 +171,10 @@ private ModelItem buildModelItem(Item item, List<Metadata> channelLinks, List<Me
167171
ModelProperty property = buildModelProperty(param.name(), param.value());
168172
if (property != null) {
169173
binding.getProperties().add(property);
174+
} else {
175+
logger.warn(
176+
"Item \"{}\": configuration parameter \"{}\" for metadata namespace \"{}\" is ignored because its value type is not supported!",
177+
item.getName(), param.name(), namespace);
170178
}
171179
if ("stateDescription".equals(namespace) && "pattern".equals(param.name())) {
172180
statePattern = param.value().toString();
@@ -188,17 +196,28 @@ private ModelItem buildModelItem(Item item, List<Metadata> channelLinks, List<Me
188196
property.setKey(key);
189197
if (value instanceof List<?> list) {
190198
if (!list.isEmpty()) {
191-
property.getValue().addAll(list);
199+
for (Object val : list) {
200+
if (val instanceof String || val instanceof BigDecimal || val instanceof Boolean) {
201+
property.getValue().add(val);
202+
} else if (val instanceof Double doubleValue) {
203+
property.getValue().add(BigDecimal.valueOf(doubleValue));
204+
} else {
205+
property = null;
206+
break;
207+
}
208+
}
192209
} else {
193210
property = null;
194211
}
212+
} else if (value instanceof String || value instanceof BigDecimal || value instanceof Boolean) {
213+
property.getValue().add(value);
195214
} else if (value instanceof Double doubleValue) {
196215
// It was discovered that configuration parameter value of an item metadata can be of type Double
197216
// when the metadata is added through Main UI.
198217
// A conversion to a BigDecimal is then required to avoid an exception later when generating DSL
199218
property.getValue().add(BigDecimal.valueOf(doubleValue));
200219
} else {
201-
property.getValue().add(value);
220+
property = null;
202221
}
203222
return property;
204223
}

0 commit comments

Comments
 (0)