use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.
the class ChannelTypeResource method getByUID.
@GET
@Path("/{channelTypeUID}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets channel type by UID.", response = ChannelTypeDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Channel type with provided channelTypeUID does not exist.", response = ChannelTypeDTO.class), @ApiResponse(code = 404, message = "No content") })
public Response getByUID(@PathParam("channelTypeUID") @ApiParam(value = "channelTypeUID") String channelTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
Locale locale = LocaleUtil.getLocale(language);
ChannelType channelType = channelTypeRegistry.getChannelType(new ChannelTypeUID(channelTypeUID), locale);
if (channelType != null) {
return Response.ok(convertToChannelTypeDTO(channelType, locale)).build();
} else {
return Response.noContent().build();
}
}
use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.
the class ThingFactoryHelper method createChannel.
private static Channel createChannel(ChannelDefinition channelDefinition, ThingUID thingUID, String groupId, ConfigDescriptionRegistry configDescriptionRegistry) {
ChannelType type = withChannelTypeRegistry(channelTypeRegistry -> {
return (channelTypeRegistry != null) ? channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()) : null;
});
if (type == null) {
logger.warn("Could not create channel '{}' for thing type '{}', because channel type '{}' could not be found.", channelDefinition.getId(), thingUID, channelDefinition.getChannelTypeUID());
return null;
}
ChannelUID channelUID = new ChannelUID(thingUID, groupId, channelDefinition.getId());
ChannelBuilder channelBuilder = createChannelBuilder(channelUID, type, configDescriptionRegistry);
// If we want to override the label, add it...
if (channelDefinition.getLabel() != null) {
channelBuilder = channelBuilder.withLabel(channelDefinition.getLabel());
}
// If we want to override the description, add it...
if (channelDefinition.getDescription() != null) {
channelBuilder = channelBuilder.withDescription(channelDefinition.getDescription());
}
channelBuilder = channelBuilder.withProperties(channelDefinition.getProperties());
return channelBuilder.build();
}
use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.
the class ThingTypeI18nLocalizationService method createLocalizedThingType.
public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Locale locale) {
final String label = this.thingTypeI18nUtil.getLabel(bundle, thingType.getUID(), thingType.getLabel(), locale);
final String description = this.thingTypeI18nUtil.getDescription(bundle, thingType.getUID(), thingType.getDescription(), locale);
final List<ChannelDefinition> localizedChannelDefinitions = new ArrayList<>(thingType.getChannelDefinitions().size());
for (final ChannelDefinition channelDefinition : thingType.getChannelDefinitions()) {
String channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, thingType.getUID(), channelDefinition, channelDefinition.getLabel(), locale);
String channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, thingType.getUID(), channelDefinition, channelDefinition.getDescription(), locale);
if (channelLabel == null || channelDescription == null) {
ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
if (channelType != null) {
if (channelLabel == null) {
channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, channelType.getUID(), channelType.getLabel(), locale);
}
if (channelDescription == null) {
channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, channelType.getUID(), channelType.getDescription(), locale);
}
}
}
localizedChannelDefinitions.add(new ChannelDefinition(channelDefinition.getId(), channelDefinition.getChannelTypeUID(), channelDefinition.getProperties(), channelLabel, channelDescription));
}
final List<ChannelGroupDefinition> localizedChannelGroupDefinitions = new ArrayList<>(thingType.getChannelGroupDefinitions().size());
for (final ChannelGroupDefinition channelGroupDefinition : thingType.getChannelGroupDefinitions()) {
String channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getLabel(), locale);
String channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getDescription(), locale);
if (channelGroupLabel == null || channelGroupDescription == null) {
ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
if (channelGroupType != null) {
if (channelGroupLabel == null) {
channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupType.getUID(), channelGroupType.getLabel(), locale);
}
if (channelGroupDescription == null) {
channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupType.getUID(), channelGroupType.getDescription(), locale);
}
}
}
localizedChannelGroupDefinitions.add(new ChannelGroupDefinition(channelGroupDefinition.getId(), channelGroupDefinition.getTypeUID(), channelGroupLabel, channelGroupDescription));
}
ThingTypeBuilder builder = ThingTypeBuilder.instance(thingType).withLabel(label).withDescription(description).withChannelDefinitions(localizedChannelDefinitions).withChannelGroupDefinitions(localizedChannelGroupDefinitions);
if (thingType instanceof BridgeType) {
return builder.buildBridge();
}
return builder.build();
}
use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.
the class XmlChannelTypeProvider method localize.
@Override
protected ChannelType localize(Bundle bundle, ChannelType channelType, Locale locale) {
if (thingTypeI18nUtil == null) {
return null;
}
ChannelTypeUID channelTypeUID = channelType.getUID();
String label = thingTypeI18nUtil.getChannelLabel(bundle, channelTypeUID, channelType.getLabel(), locale);
String description = thingTypeI18nUtil.getChannelDescription(bundle, channelTypeUID, channelType.getDescription(), locale);
StateDescription state = createLocalizedChannelState(bundle, channelType, channelTypeUID, locale);
return new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label, description, channelType.getCategory(), channelType.getTags(), state, channelType.getEvent(), channelType.getConfigDescriptionURI());
}
use of org.eclipse.smarthome.core.thing.type.ChannelType in project smarthome by eclipse.
the class DefaultSystemChannelTypeProvider method createLocalizedChannelType.
private ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, Locale locale) {
LocalizedChannelTypeKey localizedChannelTypeKey = getLocalizedChannelTypeKey(channelType.getUID(), locale);
ChannelType cachedEntry = localizedChannelTypeCache.get(localizedChannelTypeKey);
if (cachedEntry != null) {
return cachedEntry;
}
if (thingTypeI18nUtil != null) {
ChannelTypeUID channelTypeUID = channelType.getUID();
String label = thingTypeI18nUtil.getChannelLabel(bundle, channelTypeUID, channelType.getLabel(), locale);
String description = thingTypeI18nUtil.getChannelDescription(bundle, channelTypeUID, channelType.getDescription(), locale);
StateDescription state = createLocalizedChannelState(bundle, channelType, channelTypeUID, locale);
ChannelType localizedChannelType = new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label, description, channelType.getCategory(), channelType.getTags(), state, channelType.getEvent(), channelType.getConfigDescriptionURI());
localizedChannelTypeCache.put(localizedChannelTypeKey, localizedChannelType);
return localizedChannelType;
}
return channelType;
}
Aggregations