Search in sources :

Example 21 with ChannelType

use of org.eclipse.smarthome.core.thing.type.ChannelType 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)

Example 22 with ChannelType

use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.

the class ThingResource method normalizeConfiguration.

private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, ChannelTypeUID channelTypeUID, ChannelUID channelUID) {
    if (properties == null || properties.isEmpty()) {
        return properties;
    }
    ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID);
    if (channelType == null) {
        return properties;
    }
    List<ConfigDescription> configDescriptions = new ArrayList<>(2);
    if (channelType.getConfigDescriptionURI() != null) {
        ConfigDescription typeConfigDesc = configDescRegistry.getConfigDescription(channelType.getConfigDescriptionURI());
        if (typeConfigDesc != null) {
            configDescriptions.add(typeConfigDesc);
        }
    }
    if (getConfigDescriptionURI(channelUID) != null) {
        ConfigDescription channelConfigDesc = configDescRegistry.getConfigDescription(getConfigDescriptionURI(channelUID));
        if (channelConfigDesc != null) {
            configDescriptions.add(channelConfigDesc);
        }
    }
    if (configDescriptions.isEmpty()) {
        return properties;
    }
    return ConfigUtil.normalizeTypes(properties, configDescriptions);
}
Also used : ArrayList(java.util.ArrayList) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 23 with ChannelType

use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.

the class ThingTypeResource method convertToChannelDefinitionDTOs.

private List<ChannelDefinitionDTO> convertToChannelDefinitionDTOs(List<ChannelDefinition> channelDefinitions, Locale locale) {
    List<ChannelDefinitionDTO> channelDefinitionDTOs = new ArrayList<>();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
        if (channelType == null) {
            logger.warn("Cannot find channel type: {}", channelDefinition.getChannelTypeUID());
            return null;
        }
        // Default to the channelDefinition label to override the
        // channelType
        String label = channelDefinition.getLabel();
        if (label == null) {
            label = channelType.getLabel();
        }
        // Default to the channelDefinition description to override the
        // channelType
        String description = channelDefinition.getDescription();
        if (description == null) {
            description = channelType.getDescription();
        }
        ChannelDefinitionDTO channelDefinitionDTO = new ChannelDefinitionDTO(channelDefinition.getId(), channelDefinition.getChannelTypeUID().toString(), label, description, channelType.getTags(), channelType.getCategory(), channelType.getState(), channelType.isAdvanced(), channelDefinition.getProperties());
        channelDefinitionDTOs.add(channelDefinitionDTO);
    }
    return channelDefinitionDTOs;
}
Also used : ChannelDefinitionDTO(org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Aggregations

ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)23 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)9 StateDescription (org.eclipse.smarthome.core.types.StateDescription)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Bundle (org.osgi.framework.Bundle)5 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)4 Locale (java.util.Locale)3 Channel (org.eclipse.smarthome.core.thing.Channel)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)3 ChannelTypeProvider (org.eclipse.smarthome.core.thing.type.ChannelTypeProvider)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 Collection (java.util.Collection)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2