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