Search in sources :

Example 41 with Configuration

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());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 42 with Configuration

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);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) Before(org.junit.Before)

Example 43 with Configuration

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"));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) Thing(org.eclipse.smarthome.core.thing.Thing) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 44 with Configuration

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;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 45 with Configuration

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;
}
Also used : BridgeImpl(org.eclipse.smarthome.core.thing.internal.BridgeImpl) ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) Bridge(org.eclipse.smarthome.core.thing.Bridge) Thing(org.eclipse.smarthome.core.thing.Thing)

Aggregations

Configuration (org.eclipse.smarthome.config.core.Configuration)119 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 ArrayList (java.util.ArrayList)18 Thing (org.eclipse.smarthome.core.thing.Thing)18 Action (org.eclipse.smarthome.automation.Action)16 Trigger (org.eclipse.smarthome.automation.Trigger)16 Rule (org.eclipse.smarthome.automation.Rule)15 Before (org.junit.Before)14 Condition (org.eclipse.smarthome.automation.Condition)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 HashMap (java.util.HashMap)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)8 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 BigDecimal (java.math.BigDecimal)6 Consumes (javax.ws.rs.Consumes)6 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)6