diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultBuilder.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultBuilder.java index 6297328d8..1ab1acd96 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultBuilder.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultBuilder.java @@ -115,7 +115,6 @@ public class DiscoveryResultBuilder { * @return the updated builder */ public DiscoveryResultBuilder withBridge(@Nullable ThingUID bridgeUID) { - validateThingUID(bridgeUID); this.bridgeUID = bridgeUID; return this; } @@ -164,14 +163,6 @@ public class DiscoveryResultBuilder { ttl); } - private void validateThingUID(@Nullable ThingUID bridgeUID) { - if (bridgeUID != null && (!thingUID.getBindingId().equals(bridgeUID.getBindingId()) - || !thingUID.getBridgeIds().contains(bridgeUID.getId()))) { - throw new IllegalArgumentException( - "Thing UID '" + thingUID + "' does not match bridge UID '" + bridgeUID + "'"); - } - } - private String getStackTrace(final Thread thread) { StackTraceElement[] elements = thread.getStackTrace(); return Arrays.stream(elements).map(element -> "\tat " + element.toString()).collect(Collectors.joining("\n")); diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java index 0906ccf6f..50a678341 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java @@ -15,7 +15,6 @@ package org.openhab.core.config.discovery; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsMapContaining.hasEntry; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Map; @@ -107,8 +106,10 @@ public class DiscoveryResultBuilderTest { @Test public void testDiscoveryResultBuilderWithBridge() { - assertThrows(IllegalArgumentException.class, () -> DiscoveryResultBuilder - .create(new ThingUID(THING_TYPE_UID, "otherThingId")).withBridge(BRIDGE_UID).build()); + DiscoveryResult otherDiscoveryResult = DiscoveryResultBuilder + .create(new ThingUID(THING_TYPE_UID, "otherThingId")).withBridge(BRIDGE_UID).build(); + + assertThat(otherDiscoveryResult.getBridgeUID(), is(BRIDGE_UID)); } @Test diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java index 169c1f73d..a7c0859f1 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java @@ -228,7 +228,6 @@ public class ThingResource implements RESTResource { @Operation(operationId = "createThingInRegistry", summary = "Creates a new thing and adds it to the registry.", security = { @SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = { @ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))), - @ApiResponse(responseCode = "400", description = "Thing uid does not match bridge uid."), @ApiResponse(responseCode = "400", description = "A uid must be provided, if no binding can create a thing of this type."), @ApiResponse(responseCode = "409", description = "A thing with the same uid already exists.") }) public Response create( @@ -253,11 +252,6 @@ public class ThingResource implements RESTResource { if (thingBean.bridgeUID != null) { bridgeUID = new ThingUID(thingBean.bridgeUID); - if (thingUID != null && (!thingUID.getBindingId().equals(bridgeUID.getBindingId()) - || !thingUID.getBridgeIds().contains(bridgeUID.getId()))) { - return Response.status(Status.BAD_REQUEST) - .entity("Thing UID '" + thingUID + "' does not match bridge UID '" + bridgeUID + "'").build(); - } } // turn the ThingDTO's configuration into a Configuration diff --git a/bundles/org.openhab.core.thing/schema/thing/thing-description-1.0.0.xsd b/bundles/org.openhab.core.thing/schema/thing/thing-description-1.0.0.xsd index 039e0feb7..a8981d144 100644 --- a/bundles/org.openhab.core.thing/schema/thing/thing-description-1.0.0.xsd +++ b/bundles/org.openhab.core.thing/schema/thing/thing-description-1.0.0.xsd @@ -104,6 +104,7 @@ + diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java index 443dc56f1..eabf773fb 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java @@ -12,6 +12,7 @@ */ package org.openhab.core.thing.xml.internal; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -19,6 +20,7 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.config.core.xml.util.ConverterAttributeMapValidator; +import org.openhab.core.config.core.xml.util.NodeAttributes; import org.openhab.core.config.core.xml.util.NodeIterator; import org.openhab.core.config.core.xml.util.NodeList; import org.openhab.core.config.core.xml.util.NodeValue; @@ -68,11 +70,30 @@ public class ThingTypeConverter extends AbstractDescriptionTypeConverter nodes = (List) nodeList.getList(); + List uids = new ArrayList<>(nodes.size()); - return ((NodeList) nextNode).getAttributes("bridge-type-ref", "id", uidFormat); + for (NodeAttributes node : nodes) { + if ("bridge-type-ref".equals(node.getNodeName())) { + String id = node.getAttribute("id"); + String bindingId = node.getAttribute("bindingId"); + + if (id == null) { + throw new ConversionException("Missing attribute 'id' in 'bridge-type-ref'!"); + } + if (bindingId == null) { + bindingId = thisBindingId; + } + uids.add(String.format("%s:%s", bindingId, id)); + } else { + throw new ConversionException("Invalid element in 'supported-bridge-type-refs'!"); + } + } + + return uids; } return null; diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java index e61474057..4c1496271 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java @@ -63,6 +63,10 @@ public class ThingDescriptionReaderTest { assertThat(thingTypeXmlResult.label, is("HUE Lamp")); assertThat(thingTypeXmlResult.description, is("My own great HUE Lamp.")); assertThat(thingTypeXmlResult.semanticEquipmentTag, is("LightBulb")); + List supportedBridgeTypeUIDs = thingTypeXmlResult.getBuilder().build().getSupportedBridgeTypeUIDs(); + assertThat(supportedBridgeTypeUIDs.size(), is(2)); + assertTrue(supportedBridgeTypeUIDs.contains("hue:bridge")); + assertTrue(supportedBridgeTypeUIDs.contains("mqtt:broker")); assertThat(channelGroupTypeXmlResults.size(), is(1)); diff --git a/bundles/org.openhab.core.thing/src/test/resources/thing/thing-types.xml b/bundles/org.openhab.core.thing/src/test/resources/thing/thing-types.xml index 78f270fda..747397e07 100644 --- a/bundles/org.openhab.core.thing/src/test/resources/thing/thing-types.xml +++ b/bundles/org.openhab.core.thing/src/test/resources/thing/thing-types.xml @@ -7,6 +7,7 @@ +