Skip to content

Commit a6012df

Browse files
committed
[DSL/YAML generator] Consider item pattern formatter even without label
Items without label but with a formatter is now properly considered when generating DSL and YAML syntax. Example: Number SceneItem "[MAP(scene.map):%s]" Bug was reported on the community forum. Signed-off-by: Laurent Garnier <[email protected]>
1 parent c56c016 commit a6012df

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,18 @@ private ModelItem buildModelItem(Item item, List<Metadata> channelLinks, List<Me
139139
String label = item.getLabel();
140140
boolean patternInjected = false;
141141
String defaultPattern = getDefaultStatePattern(item);
142-
if (label != null && !label.isEmpty()) {
143-
String patterToInject = stateFormatter != null && !stateFormatter.equals(defaultPattern) ? stateFormatter
144-
: null;
145-
if (patterToInject != null) {
146-
// Inject the pattern in the label
147-
patternInjected = true;
142+
String patterToInject = stateFormatter != null && !stateFormatter.equals(defaultPattern) ? stateFormatter
143+
: null;
144+
if (patterToInject != null) {
145+
// Inject the pattern in the label
146+
patternInjected = true;
147+
if (label != null && !label.isEmpty()) {
148148
model.setLabel("%s [%s]".formatted(label, patterToInject));
149149
} else {
150-
model.setLabel(label);
150+
model.setLabel("[%s]".formatted(patterToInject));
151151
}
152+
} else {
153+
model.setLabel(label);
152154
}
153155

154156
String category = item.getCategory();

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ private YamlItemDTO buildItemDTO(Item item, List<Metadata> channelLinks, List<Me
114114
String defaultPattern = getDefaultStatePattern(item);
115115
if (label != null && !label.isEmpty()) {
116116
dto.label = item.getLabel();
117-
String patterToSet = stateFormatter != null && !stateFormatter.equals(defaultPattern) ? stateFormatter
118-
: null;
119-
dto.format = patterToSet;
120-
patternSet = patterToSet != null;
121117
}
118+
String patterToSet = stateFormatter != null && !stateFormatter.equals(defaultPattern) ? stateFormatter : null;
119+
dto.format = patterToSet;
120+
patternSet = patterToSet != null;
122121

123122
dto.type = item.getType();
124123
String mainType = ItemUtil.getMainItemType(item.getType());

0 commit comments

Comments
 (0)