Search in sources :

Example 16 with ThingType

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

the class SystemWideChannelTypesTest method systemChannelsShouldBeAddedWithoutThingTypes.

@Test
public void systemChannelsShouldBeAddedWithoutThingTypes() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    int initialNumberOfChannelTypes = getChannelTypes().size();
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_WITHOUT_THING_TYPES_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes));
    assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
    // uninstall test bundle
    sysBundle.uninstall();
    assertThat(sysBundle.getState(), is(Bundle.UNINSTALLED));
    assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes));
}
Also used : Bundle(org.osgi.framework.Bundle) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 17 with ThingType

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

the class SystemWideChannelTypesTest method systemChannelsShouldBeusedByOtherBinding.

@Test
public void systemChannelsShouldBeusedByOtherBinding() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    int initialNumberOfChannelTypes = getChannelTypes().size();
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    Bundle sysUserBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_USER_BUNDLE_NAME);
    assertThat(sysUserBundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
    assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
}
Also used : Bundle(org.osgi.framework.Bundle) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 18 with ThingType

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

the class SystemWideChannelTypesTest method thingTyoesShouldHaveProperChannelDefinitions.

@Test
public void thingTyoesShouldHaveProperChannelDefinitions() throws Exception {
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    ThingType wirelessRouterType = thingTypeProvider.getThingTypes(null).stream().filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
    assertThat(wirelessRouterType, is(notNullValue()));
    Collection<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
    assertThat(channelDefs.size(), is(3));
    ChannelDefinition myChannel = channelDefs.stream().filter(it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).findFirst().get();
    assertThat(myChannel, is(notNullValue()));
    ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
    assertThat(sigStr, is(notNullValue()));
    ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
    assertThat(lowBat, is(notNullValue()));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 19 with ThingType

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

the class AutomaticInboxProcessor method getRepresentationPropertyValueForThing.

@Nullable
private String getRepresentationPropertyValueForThing(Thing thing) {
    ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
    if (thingType != null) {
        String representationProperty = thingType.getRepresentationProperty();
        if (representationProperty == null) {
            return null;
        }
        Map<String, String> properties = thing.getProperties();
        if (properties.containsKey(representationProperty)) {
            return properties.get(representationProperty);
        }
        Configuration configuration = thing.getConfiguration();
        if (configuration.containsKey(representationProperty)) {
            return String.valueOf(configuration.get(representationProperty));
        }
    }
    return null;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 20 with ThingType

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

the class PersistentInbox method synchronizeConfiguration.

private boolean synchronizeConfiguration(ThingTypeUID thingTypeUID, Map<String, Object> properties, Configuration config) {
    boolean configUpdated = false;
    final Set<Map.Entry<String, Object>> propertySet = properties.entrySet();
    final ThingType thingType = thingTypeRegistry.getThingType(thingTypeUID);
    final List<ConfigDescriptionParameter> configDescParams = getConfigDescParams(thingType);
    for (Map.Entry<String, Object> propertyEntry : propertySet) {
        final String propertyKey = propertyEntry.getKey();
        final Object propertyValue = propertyEntry.getValue();
        // Check if the key is present in the configuration.
        if (!config.containsKey(propertyKey)) {
            continue;
        }
        // Normalize first
        ConfigDescriptionParameter configDescParam = getConfigDescriptionParam(configDescParams, propertyKey);
        Object normalizedValue = ConfigUtil.normalizeType(propertyValue, configDescParam);
        // If the value is equal to the one of the configuration, there is nothing to do.
        if (Objects.equals(normalizedValue, config.get(propertyKey))) {
            continue;
        }
        // - the given key is part of the configuration
        // - the values differ
        // update value
        config.put(propertyKey, normalizedValue);
        configUpdated = true;
    }
    return configUpdated;
}
Also used : ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

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