Search in sources :

Example 1 with ChannelType

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();
    }
}
Also used : Locale(java.util.Locale) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) 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 ChannelType

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();
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ChannelBuilder(org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 3 with ChannelType

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();
}
Also used : ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType)

Example 4 with ChannelType

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());
}
Also used : ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 5 with ChannelType

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;
}
Also used : ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

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