Skip to content

Commit 46dcfa6

Browse files
authored
[DSL generator] Consider a bridge thing as bridge if it contains things (openhab#4740)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
1 parent d0308a2 commit 46dcfa6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingFileConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private ModelThing buildModelThing(Thing thing, boolean hideDefaultParameters, b
101101
boolean topLevel, List<Thing> onlyThings, Set<Thing> handledThings) {
102102
ModelThing model;
103103
ModelBridge modelBridge;
104-
if (preferPresentationAsTree && thing instanceof Bridge bridge && !bridge.getThings().isEmpty()) {
104+
List<Thing> childThings = getChildThings(thing, onlyThings);
105+
if (preferPresentationAsTree && thing instanceof Bridge && !childThings.isEmpty()) {
105106
modelBridge = ThingFactory.eINSTANCE.createModelBridge();
106107
modelBridge.setBridge(true);
107108
model = modelBridge;
@@ -135,8 +136,8 @@ private ModelThing buildModelThing(Thing thing, boolean hideDefaultParameters, b
135136

136137
if (preferPresentationAsTree && modelBridge != null) {
137138
modelBridge.setThingsHeader(false);
138-
for (Thing child : getChildThings(thing)) {
139-
if (onlyThings.contains(child) && !handledThings.contains(child)) {
139+
for (Thing child : childThings) {
140+
if (!handledThings.contains(child)) {
140141
modelBridge.getThings()
141142
.add(buildModelThing(child, hideDefaultParameters, true, false, onlyThings, handledThings));
142143
}

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingFileGenerator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ protected record ConfigParameter(String name, Object value) {
6363
}
6464

6565
/**
66-
* Get the child things of a bridge thing, ordered by UID.
66+
* Get the child things of a bridge thing amongst a list of things, ordered by UID.
6767
*
6868
* @param thing the thing
69+
* @param fromThings the list of things to look for
6970
* @return the sorted list of child things or an empty list if the thing is not a bridge thing
7071
*/
71-
protected List<Thing> getChildThings(Thing thing) {
72+
protected List<Thing> getChildThings(Thing thing, List<Thing> fromThings) {
7273
if (thing instanceof Bridge bridge) {
73-
return bridge.getThings().stream().sorted((thing1, thing2) -> {
74-
return thing1.getUID().getAsString().compareTo(thing2.getUID().getAsString());
75-
}).collect(Collectors.toList());
74+
return fromThings.stream().filter(th -> bridge.getUID().equals(th.getBridgeUID()))
75+
.sorted((thing1, thing2) -> {
76+
return thing1.getUID().getAsString().compareTo(thing2.getUID().getAsString());
77+
}).collect(Collectors.toList());
7678
}
7779
return List.of();
7880
}

0 commit comments

Comments
 (0)