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();
}
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"));
}
Aggregations