Search in sources :

Example 1 with ThingType

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;
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) URI(java.net.URI) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with ThingType

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();
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with ThingType

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;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with ThingType

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."));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 5 with ThingType

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."));
}
Also used : Bundle(org.osgi.framework.Bundle) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ThingType (org.eclipse.smarthome.core.thing.type.ThingType)26 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)15 Test (org.junit.Test)15 Bundle (org.osgi.framework.Bundle)15 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)7 List (java.util.List)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)3 ThingTypeProvider (org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)3 Before (org.junit.Before)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)2 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)2 Configuration (org.eclipse.smarthome.config.core.Configuration)2 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)2