Search in sources :

Example 1 with TriggerProfileType

use of org.eclipse.smarthome.core.thing.profiles.TriggerProfileType in project smarthome by eclipse.

the class ChannelTypeResource method getLinkableItemTypes.

@GET
@Path("/{channelTypeUID}/linkableItemTypes")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the item types the given trigger channel type UID can be linked to.", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class, responseContainer = "Set"), @ApiResponse(code = 204, message = "No content: channel type has no linkable items or is no trigger channel."), @ApiResponse(code = 404, message = "Given channel type UID not found.") })
public Response getLinkableItemTypes(@PathParam("channelTypeUID") @ApiParam(value = "channelTypeUID") String channelTypeUID) {
    ChannelTypeUID ctUID = new ChannelTypeUID(channelTypeUID);
    ChannelType channelType = channelTypeRegistry.getChannelType(ctUID);
    if (channelType == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (channelType.getKind() != ChannelKind.TRIGGER) {
        return Response.noContent().build();
    }
    Set<String> result = new HashSet<>();
    for (ProfileType profileType : profileTypeRegistry.getProfileTypes()) {
        if (profileType instanceof TriggerProfileType) {
            if (((TriggerProfileType) profileType).getSupportedChannelTypeUIDs().contains(ctUID)) {
                for (String itemType : profileType.getSupportedItemTypes()) {
                    result.add(itemType);
                }
            }
        }
    }
    if (result.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(result).build();
}
Also used : ProfileType(org.eclipse.smarthome.core.thing.profiles.ProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with TriggerProfileType

use of org.eclipse.smarthome.core.thing.profiles.TriggerProfileType in project smarthome by eclipse.

the class ChannelTypeResourceTest method returnLinkableItemTypesForTriggerChannelType.

@SuppressWarnings("unchecked")
@Test
public void returnLinkableItemTypesForTriggerChannelType() throws IOException {
    ChannelType channelType = mockChannelType("ct");
    ChannelTypeUID uid = channelType.getUID();
    ProfileTypeUID profileTypeUID = new ProfileTypeUID("system:profileType");
    when(channelTypeRegistry.getChannelType(uid)).thenReturn(channelType);
    TriggerProfileType profileType = mock(TriggerProfileType.class);
    when(profileType.getUID()).thenReturn(profileTypeUID);
    when(profileType.getSupportedChannelTypeUIDs()).thenReturn(Collections.singletonList(uid));
    when(profileType.getSupportedItemTypes()).thenReturn(Arrays.asList("Switch", "Dimmer"));
    when(profileTypeRegistry.getProfileTypes()).thenReturn(Collections.singletonList(profileType));
    Response response = channelTypeResource.getLinkableItemTypes(uid.getAsString());
    verify(channelTypeRegistry).getChannelType(uid);
    verify(profileTypeRegistry).getProfileTypes();
    assertThat(response.getStatus(), is(200));
    assertThat((Set<String>) response.getEntity(), IsCollectionContaining.hasItems("Switch", "Dimmer"));
}
Also used : Response(javax.ws.rs.core.Response) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Test(org.junit.Test)

Aggregations

TriggerProfileType (org.eclipse.smarthome.core.thing.profiles.TriggerProfileType)2 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)2 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 ProfileType (org.eclipse.smarthome.core.thing.profiles.ProfileType)1 ProfileTypeUID (org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)1 Test (org.junit.Test)1