use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class LifxLightHandler method getPowerOnColor.
private HSBType getPowerOnColor() {
Channel channel = null;
if (product.isColor()) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
channel = getThing().getChannel(channelUID.getId());
}
if (channel == null) {
return null;
}
Configuration configuration = channel.getConfiguration();
Object powerOnColor = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_COLOR);
return powerOnColor == null ? null : new HSBType(powerOnColor.toString());
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class AutomaticInboxProcessorTest method setUp.
@Before
public void setUp() throws Exception {
initMocks(this);
when(thing.getConfiguration()).thenReturn(CONFIG);
when(thing.getThingTypeUID()).thenReturn(THING_TYPE_UID);
when(thing.getProperties()).thenReturn(THING_PROPERTIES);
when(thing.getStatus()).thenReturn(ThingStatus.ONLINE);
when(thing.getUID()).thenReturn(THING_UID);
when(thing2.getConfiguration()).thenReturn(CONFIG);
when(thing2.getThingTypeUID()).thenReturn(THING_TYPE_UID);
when(thing2.getProperties()).thenReturn(THING_PROPERTIES);
when(thing2.getStatus()).thenReturn(ThingStatus.ONLINE);
when(thing2.getUID()).thenReturn(THING_UID2);
when(thing3.getConfiguration()).thenReturn(CONFIG);
when(thing3.getThingTypeUID()).thenReturn(THING_TYPE_UID3);
when(thing3.getProperties()).thenReturn(OTHER_THING_PROPERTIES);
when(thing3.getStatus()).thenReturn(ThingStatus.ONLINE);
when(thing3.getUID()).thenReturn(THING_UID3);
when(thingRegistry.stream()).thenReturn(Stream.empty());
when(thingTypeRegistry.getThingType(THING_TYPE_UID)).thenReturn(THING_TYPE);
when(thingTypeRegistry.getThingType(THING_TYPE_UID2)).thenReturn(THING_TYPE2);
when(thingTypeRegistry.getThingType(THING_TYPE_UID3)).thenReturn(THING_TYPE3);
when(thingHandlerFactory.supportsThingType(eq(THING_TYPE_UID))).thenReturn(true);
when(thingHandlerFactory.createThing(eq(THING_TYPE_UID), any(Configuration.class), eq(THING_UID), any(ThingUID.class))).then(invocation -> ThingBuilder.create(THING_TYPE_UID, "test").withConfiguration((Configuration) invocation.getArguments()[1]).build());
inbox = new PersistentInbox();
inbox.setThingRegistry(thingRegistry);
inbox.setStorageService(new VolatileStorageService());
inbox.setManagedThingProvider(thingProvider);
inbox.setConfigDescriptionRegistry(configDescriptionRegistry);
inbox.setThingTypeRegistry(thingTypeRegistry);
inbox.addThingHandlerFactory(thingHandlerFactory);
inboxAutoIgnore = new AutomaticInboxProcessor();
inboxAutoIgnore.setThingRegistry(thingRegistry);
inboxAutoIgnore.setThingTypeRegistry(thingTypeRegistry);
inboxAutoIgnore.setInbox(inbox);
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class PersistentInboxTest method testConfigUpdateNormalization_guessType.
@Test
public void testConfigUpdateNormalization_guessType() {
Map<String, Object> props = new HashMap<>();
props.put("foo", 1);
Configuration config = new Configuration(props);
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withConfiguration(config).build();
when(thingRegistry.get(eq(THING_UID))).thenReturn(thing);
assertTrue(thing.getConfiguration().get("foo") instanceof BigDecimal);
inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build());
assertTrue(thing.getConfiguration().get("foo") instanceof BigDecimal);
assertEquals(new BigDecimal(3), thing.getConfiguration().get("foo"));
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class SampleConditionHandler method isSatisfied.
@Override
public boolean isSatisfied(Map<String, Object> inputs) {
String conditionInput = (String) inputs.get(CONDITION_INPUT_NAME);
if (conditionInput == null) {
conditionInput = "";
}
Configuration config = module.getConfiguration();
String operator = (String) config.get(PROPERTY_OPERATOR);
String constraint = (String) config.get(PROPERTY_CONSTRAINT);
boolean evaluation = false;
if (OPERATOR_EQUAL.equals(operator)) {
evaluation = conditionInput.equals(constraint);
} else if (OPERATOR_NOT_EQUAL.equals(operator)) {
evaluation = !(conditionInput.equals(constraint));
} else if (OPERATOR_LESS.equals(operator)) {
int compersion = conditionInput.compareTo(constraint);
evaluation = compersion < 0 ? true : false;
} else if (OPERATOR_GREATER.equals(operator)) {
int comperison = conditionInput.compareTo(constraint);
evaluation = comperison > 0 ? true : false;
} else {
throw new IllegalArgumentException("[SampleConditionHandler]Invalid comparison operator: " + operator);
}
return evaluation;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class ThingHelper method merge.
/**
* Merges the content of a ThingDTO with an existing Thing.
* Where ever the DTO has null values, the content of the original Thing is kept.
* Where ever the DTO has non-null values, these are used.
* In consequence, care must be taken when the content of a list (like configuration, properties or channels) is to
* be updated - the DTO must contain the full list, otherwise entries will be deleted.
*
* @param thing the Thing instance to merge the new content into
* @param updatedContents a DTO which carries the updated content
* @return A Thing instance, which is the result of the merge
*/
public static Thing merge(Thing thing, ThingDTO updatedContents) {
ThingBuilder builder;
if (thing instanceof Bridge) {
builder = BridgeBuilder.create(thing.getThingTypeUID(), thing.getUID());
} else {
builder = ThingBuilder.create(thing.getThingTypeUID(), thing.getUID());
}
// Update the label
if (updatedContents.label != null) {
builder.withLabel(updatedContents.label);
} else {
builder.withLabel(thing.getLabel());
}
// Update the location
if (updatedContents.location != null) {
builder.withLocation(updatedContents.location);
} else {
builder.withLocation(thing.getLocation());
}
// update bridge UID
if (updatedContents.bridgeUID != null) {
builder.withBridge(new ThingUID(updatedContents.bridgeUID));
} else {
builder.withBridge(thing.getBridgeUID());
}
// update thing configuration
if (updatedContents.configuration != null && !updatedContents.configuration.keySet().isEmpty()) {
builder.withConfiguration(new Configuration(updatedContents.configuration));
} else {
builder.withConfiguration(thing.getConfiguration());
}
// update thing properties
if (updatedContents.properties != null) {
builder.withProperties(updatedContents.properties);
} else {
builder.withProperties(thing.getProperties());
}
// Update the channels
if (updatedContents.channels != null) {
for (ChannelDTO channelDTO : updatedContents.channels) {
builder.withChannel(ChannelDTOMapper.map(channelDTO));
}
} else {
builder.withChannels(thing.getChannels());
}
if (updatedContents.location != null) {
builder.withLocation(updatedContents.location);
} else {
builder.withLocation(thing.getLocation());
}
Thing mergedThing = builder.build();
// keep all child things in place on a merged bridge
if (mergedThing instanceof BridgeImpl && thing instanceof Bridge) {
Bridge bridge = (Bridge) thing;
BridgeImpl mergedBridge = (BridgeImpl) mergedThing;
for (Thing child : bridge.getThings()) {
mergedBridge.addThing(child);
}
}
return mergedThing;
}
Aggregations