Search in sources :

Example 46 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class GenericItemProvider method internalDispatchBindings.

private void internalDispatchBindings(BindingConfigReader reader, String modelName, Item item, EList<ModelBinding> bindings) {
    for (ModelBinding binding : bindings) {
        String bindingType = binding.getType();
        String config = binding.getConfiguration();
        Configuration configuration = new Configuration();
        binding.getProperties().forEach(p -> configuration.put(p.getKey(), p.getValue()));
        BindingConfigReader localReader = reader;
        if (reader == null) {
            logger.trace("Given binding config reader is null > query cache to find appropriate reader!");
            localReader = bindingConfigReaders.get(bindingType);
        } else {
            if (!localReader.getBindingType().equals(binding.getType())) {
                logger.trace("The Readers' binding type '{}' and the Bindings' type '{}' doesn't match > continue processing next binding.", localReader.getBindingType(), binding.getType());
                continue;
            } else {
                logger.debug("Start processing binding configuration of Item '{}' with '{}' reader.", item, localReader.getClass().getSimpleName());
            }
        }
        if (localReader != null) {
            try {
                localReader.validateItemType(item.getType(), config);
                localReader.processBindingConfiguration(modelName, item.getType(), item.getName(), config, configuration);
            } catch (BindingConfigParseException e) {
                logger.error("Binding configuration of type '{}' of item '{}' could not be parsed correctly.", bindingType, item.getName(), e);
            } catch (Exception e) {
                // Catch badly behaving binding exceptions and continue processing
                logger.error("Binding configuration of type '{}' of item '{}' could not be parsed correctly.", bindingType, item.getName(), e);
            }
        } else {
            logger.trace("Couldn't find config reader for binding type '{}' > " + "parsing binding configuration of Item '{}' aborted!", bindingType, item);
        }
    }
}
Also used : ModelBinding(org.eclipse.smarthome.model.items.ModelBinding) Configuration(org.eclipse.smarthome.config.core.Configuration) BindingConfigReader(org.eclipse.smarthome.model.item.BindingConfigReader) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException)

Example 47 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method offlineIfWrongPIN.

/**
 * Verify OFFLINE Thing status when the PIN is wrong.
 */
@Test
public void offlineIfWrongPIN() {
    final String wrongPin = "5678";
    Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, wrongPin, String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
    initializeRadioThing(config);
    waitForAssert(() -> {
        String exceptionMessage = "java.lang.RuntimeException: Radio does not allow connection, maybe wrong pin?";
        verifyCommunicationError(exceptionMessage);
    });
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 48 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method offlineIfEmptyPIN.

/**
 * Verify OFFLINE Thing status when the PIN is empty String.
 */
@Test
public void offlineIfEmptyPIN() {
    Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, "", String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
    Thing radioThingWithEmptyPIN = initializeRadioThing(config);
    testRadioThingConsideringConfiguration(radioThingWithEmptyPIN);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 49 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class AbstractDmxThingTest method initializeBridge.

private void initializeBridge() {
    bridgeProperties = new HashMap<>();
    bridge = BridgeBuilder.create(THING_TYPE_TEST_BRIDGE, "testbridge").withLabel("Test Bridge").withConfiguration(new Configuration(bridgeProperties)).build();
    dmxBridgeHandler = new TestBridgeHandler(bridge);
    bridge.setHandler(dmxBridgeHandler);
    ThingHandlerCallback bridgeHandler = mock(ThingHandlerCallback.class);
    doAnswer(answer -> {
        ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
        return null;
    }).when(bridgeHandler).statusUpdated(any(), any());
    dmxBridgeHandler.setCallback(bridgeHandler);
    dmxBridgeHandler.initialize();
}
Also used : TestBridgeHandler(org.eclipse.smarthome.binding.dmx.test.TestBridgeHandler) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 50 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class DimmerThingHandlerTest method setUp.

@Before
public void setUp() {
    super.setup();
    thingProperties = new HashMap<>();
    thingProperties.put(CONFIG_DMX_ID, TEST_CHANNEL_CONFIG);
    thingProperties.put(CONFIG_DIMMER_FADE_TIME, TEST_FADE_TIME);
    dimmerThing = ThingBuilder.create(THING_TYPE_DIMMER, "testdimmer").withLabel("Dimmer Thing").withBridge(bridge.getUID()).withConfiguration(new Configuration(thingProperties)).withChannel(ChannelBuilder.create(CHANNEL_UID_BRIGHTNESS, "Brightness").withType(BRIGHTNESS_CHANNEL_TYPEUID).build()).build();
    dimmerThingHandler = new DimmerThingHandler(dimmerThing) {

        @Override
        @Nullable
        protected Bridge getBridge() {
            return bridge;
        }
    };
    initializeHandler(dimmerThingHandler);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) DimmerThingHandler(org.eclipse.smarthome.binding.dmx.handler.DimmerThingHandler) Nullable(org.eclipse.jdt.annotation.Nullable) Bridge(org.eclipse.smarthome.core.thing.Bridge) Before(org.junit.Before)

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