Search in sources :

Example 16 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class ItemChannelLinkResource method unlink.

@DELETE
@Path("/{itemName}/{channelUID}")
@ApiOperation(value = "Unlinks item from a channel.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Link not found."), @ApiResponse(code = 405, message = "Link not editable.") })
public Response unlink(@PathParam("itemName") @ApiParam(value = "itemName") String itemName, @PathParam("channelUID") @ApiParam(value = "channelUID") String channelUid) {
    String linkId = AbstractLink.getIDFor(itemName, new ChannelUID(channelUid));
    if (itemChannelLinkRegistry.get(linkId) == null) {
        String message = "Link " + linkId + " does not exist!";
        return JSONResponse.createResponse(Status.NOT_FOUND, null, message);
    }
    ItemChannelLink result = itemChannelLinkRegistry.remove(AbstractLink.getIDFor(itemName, new ChannelUID(channelUid)));
    if (result != null) {
        return Response.ok(null, MediaType.TEXT_PLAIN).build();
    } else {
        return JSONResponse.createErrorResponse(Status.METHOD_NOT_ALLOWED, "Channel is read-only.");
    }
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class ThingResource method unlinkChannelIfAlreadyLinked.

private void unlinkChannelIfAlreadyLinked(ChannelUID channelUID) {
    Collection<ItemChannelLink> links = managedItemChannelLinkProvider.getAll();
    for (ItemChannelLink link : links) {
        if (link.getLinkedUID().equals(channelUID)) {
            logger.debug("Channel '{}' is already linked to item '{}' and will be unlinked before it will be linked to the new item.", channelUID, link.getItemName());
            managedItemChannelLinkProvider.remove(link.getUID());
        }
    }
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink)

Aggregations

ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)17 Test (org.junit.Test)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)4 Channel (org.eclipse.smarthome.core.thing.Channel)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Configuration (org.eclipse.smarthome.config.core.Configuration)2 Item (org.eclipse.smarthome.core.items.Item)2 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)2 StringItem (org.eclipse.smarthome.core.library.items.StringItem)2 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Field (java.lang.reflect.Field)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1