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