Search in sources :

Example 16 with ChannelType

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

the class ThingTypeXmlProvider method addingFinished.

@Override
public synchronized void addingFinished() {
    Map<String, ChannelType> channelTypes = new HashMap<>(10);
    // create channel types
    for (ChannelTypeXmlResult type : this.channelTypeRefs) {
        ChannelType channelType = type.toChannelType();
        channelTypes.put(channelType.getUID().getAsString(), channelType);
        this.channelTypeProvider.add(this.bundle, channelType);
    }
    // create channel group types
    for (ChannelGroupTypeXmlResult type : this.channelGroupTypeRefs) {
        this.channelGroupTypeProvider.add(this.bundle, type.toChannelGroupType());
    }
    // create thing and bridge types
    for (ThingTypeXmlResult type : this.thingTypeRefs) {
        this.thingTypeProvider.add(this.bundle, type.toThingType());
    }
    // release temporary cache
    this.thingTypeRefs.clear();
    this.channelGroupTypeRefs.clear();
    this.channelTypeRefs.clear();
}
Also used : HashMap(java.util.HashMap) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 17 with ChannelType

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

the class ThingTypeI18nTest method channelTypeShouldBeLocalized.

@Test
public void channelTypeShouldBeLocalized() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
    ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather")).findFirst().get();
    assertThat(weatherType, is(notNullValue()));
    assertThat(weatherType.getChannelDefinitions().size(), is(2));
    ChannelType temperatureChannelType = channelTypeRegistry.getChannelType(weatherType.getChannelDefinitions().stream().filter(it -> it.getId().equals("temperature")).findFirst().get().getChannelTypeUID(), Locale.GERMAN);
    assertThat(temperatureChannelType, is(notNullValue()));
    assertThat(temperatureChannelType.getLabel(), is("Temperatur"));
    assertThat(temperatureChannelType.getDescription(), is("Aktuelle Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
    assertThat(temperatureChannelType.getState().getPattern(), is("%d Grad Celsius"));
    assertThat(temperatureChannelType.getState().getOptions().get(0).getLabel(), is("Mein String"));
}
Also used : Bundle(org.osgi.framework.Bundle) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 18 with ChannelType

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

the class ChannelTypeConverter method unmarshalType.

@Override
protected ChannelTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    boolean advanced = readBoolean(attributes, "advanced", false);
    boolean system = readBoolean(attributes, "system", false);
    String uid = system ? XmlHelper.getSystemUID(super.getID(attributes)) : super.getUID(attributes, context);
    ChannelTypeUID channelTypeUID = new ChannelTypeUID(uid);
    String itemType = readItemType(nodeIterator);
    String kind = readKind(nodeIterator);
    String label = super.readLabel(nodeIterator);
    String description = super.readDescription(nodeIterator);
    String category = readCategory(nodeIterator);
    Set<String> tags = readTags(nodeIterator);
    StateDescription stateDescription = readStateDescription(nodeIterator);
    EventDescription eventDescription = readEventDescription(nodeIterator);
    Object[] configDescriptionObjects = super.getConfigDescriptionObjects(nodeIterator);
    if (kind == null) {
        // Default for kind is 'state'
        kind = "state";
    }
    ChannelType channelType = new ChannelType(channelTypeUID, advanced, itemType, ChannelKind.parse(kind), label, description, category, tags, stateDescription, eventDescription, (URI) configDescriptionObjects[0]);
    ChannelTypeXmlResult channelTypeXmlResult = new ChannelTypeXmlResult(channelType, (ConfigDescription) configDescriptionObjects[1], system);
    return channelTypeXmlResult;
}
Also used : ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) EventDescription(org.eclipse.smarthome.core.types.EventDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 19 with ChannelType

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

the class DefaultSystemChannelTypeProvider method getChannelTypes.

@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
    final List<ChannelType> allChannelTypes = new ArrayList<>(10);
    final Bundle bundle = FrameworkUtil.getBundle(DefaultSystemChannelTypeProvider.class);
    for (final ChannelType channelType : channelTypes) {
        allChannelTypes.add(createLocalizedChannelType(bundle, channelType, locale));
    }
    return allChannelTypes;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 20 with ChannelType

use of org.eclipse.smarthome.core.thing.type.ChannelType 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();
}
Also used : ProfileType(org.eclipse.smarthome.core.thing.profiles.ProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) HashSet(java.util.HashSet) 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)

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