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