use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.
the class ThingConfigDescriptionAliasProvider method getThingConfigDescriptionURI.
@Nullable
private URI getThingConfigDescriptionURI(URI uri) {
// First, get the thing type so we get the generic config descriptions
ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart());
Thing thing = thingRegistry.get(thingUID);
if (thing == null) {
return null;
}
ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
if (thingType == null) {
return null;
}
// Get the config description URI for this thing type
URI configURI = thingType.getConfigDescriptionURI();
return configURI;
}
use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.
the class ThingManager method initializeHandler.
private void initializeHandler(Thing thing) {
if (!isHandlerRegistered(thing)) {
return;
}
Lock lock = getLockForThing(thing.getUID());
try {
lock.lock();
if (ThingHandlerHelper.isHandlerInitialized(thing)) {
logger.debug("Attempt to initialize the already initialized thing '{}' will be ignored.", thing.getUID());
return;
}
if (isInitializing(thing)) {
logger.debug("Attempt to initialize a handler twice for thing '{}' at the same time will be ignored.", thing.getUID());
return;
}
ThingHandler handler = thing.getHandler();
if (handler == null) {
throw new IllegalStateException("Handler should not be null here");
} else {
if (handler.getThing() != thing) {
logger.warn("The model of {} is inconsistent [thing.getHandler().getThing() != thing]", thing.getUID());
}
}
ThingType thingType = getThingType(thing);
applyDefaultConfiguration(thing, thingType);
if (isInitializable(thing, thingType)) {
setThingStatus(thing, buildStatusInfo(ThingStatus.INITIALIZING, ThingStatusDetail.NONE));
doInitializeHandler(thing.getHandler());
} else {
logger.debug("Thing '{}' not initializable, check required configuration parameters.", thing.getUID());
setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING));
}
} finally {
lock.unlock();
}
}
use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.
the class BaseThingHandlerFactory method createThing.
/**
* Creates a thing based on given thing type uid.
*
* @param thingTypeUID thing type uid (must not be null)
* @param thingUID thingUID (can be null)
* @param configuration (must not be null)
* @param bridgeUID (can be null)
* @return thing (can be null, if thing type is unknown)
*/
@Override
@Nullable
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
ThingUID effectiveUID = thingUID != null ? thingUID : ThingFactory.generateRandomThingUID(thingTypeUID);
ThingType thingType = getThingTypeByUID(thingTypeUID);
if (thingType != null) {
Thing thing = ThingFactory.createThing(thingType, effectiveUID, configuration, bridgeUID, getConfigDescriptionRegistry());
return thing;
} else {
return null;
}
}
use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.
the class ThingTypeI18nTest method channelGroupTypeShouldBeLocalized.
@Test
public void channelGroupTypeShouldBeLocalized() 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 weatherGroupType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertThat(weatherGroupType, is(notNullValue()));
ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
assertThat(channelGroupType, is(notNullValue()));
assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe"));
assertThat(channelGroupType.getDescription(), is("Wetterinformation mit Gruppe Beschreibung."));
}
use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.
the class ThingTypeI18nTest method channelGroupsShouldBeLocalized.
@Test
public void channelGroupsShouldBeLocalized() 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 weatherGroupType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertThat(weatherGroupType, is(notNullValue()));
assertThat(weatherGroupType.getChannelGroupDefinitions().size(), is(2));
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions().stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertThat(forecastTodayChannelGroupDefinition, is(notNullValue()));
assertThat(forecastTodayChannelGroupDefinition.getLabel(), is("Wettervorhersage heute"));
assertThat(forecastTodayChannelGroupDefinition.getDescription(), is("Wettervorhersage für den heutigen Tag."));
ChannelGroupDefinition forecastTomorrowChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions().stream().filter(it -> it.getId().equals("forecastTomorrow")).findFirst().get();
assertThat(forecastTomorrowChannelGroupDefinition, is(notNullValue()));
assertThat(forecastTomorrowChannelGroupDefinition.getLabel(), is("Wettervorhersage morgen"));
assertThat(forecastTomorrowChannelGroupDefinition.getDescription(), is("Wettervorhersage für den morgigen Tag."));
}
Aggregations