Search in sources :

Example 51 with Configuration

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

the class ArtnetBridgeHandler method updateConfiguration.

@Override
protected void updateConfiguration() {
    Configuration configuration = getConfig();
    setUniverse(configuration.get(CONFIG_UNIVERSE), MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
    packetTemplate.setUniverse(universe.getUniverseId());
    receiverNodes.clear();
    if (configuration.get(CONFIG_ADDRESS) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not initialize sender (address not set)");
        uninstallScheduler();
        logger.debug("remote address not set for {}", this.thing.getUID());
        return;
    } else {
        try {
            receiverNodes = IpNode.fromString((String) configuration.get(CONFIG_ADDRESS), ArtnetNode.DEFAULT_PORT);
            logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
        } catch (IllegalArgumentException e) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
            return;
        }
    }
    if (configuration.get(CONFIG_LOCAL_ADDRESS) != null) {
        senderNode = new IpNode((String) configuration.get(CONFIG_LOCAL_ADDRESS));
    }
    logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
    if (configuration.get(CONFIG_REFRESH_MODE) != null) {
        refreshAlways = (((String) configuration.get(CONFIG_REFRESH_MODE)).equals("always"));
    }
    logger.debug("refresh mode set to always: {}", refreshAlways);
    updateStatus(ThingStatus.UNKNOWN);
    super.updateConfiguration();
    logger.debug("updated configuration for ArtNet bridge {}", this.thing.getUID());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode)

Example 52 with Configuration

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

the class ColorThingHandler method initialize.

@Override
public void initialize() {
    Configuration configuration = getConfig();
    Bridge bridge = getBridge();
    DmxBridgeHandler bridgeHandler;
    if (bridge == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge assigned");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    } else {
        bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
        if (bridgeHandler == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge handler available");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    if (configuration.get(CONFIG_DMX_ID) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "DMX channel configuration missing");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    try {
        List<BaseDmxChannel> configChannels = BaseDmxChannel.fromString((String) configuration.get(CONFIG_DMX_ID), bridgeHandler.getUniverseId());
        logger.trace("found {} channels in {}", configChannels.size(), this.thing.getUID());
        for (BaseDmxChannel channel : configChannels) {
            channels.add(bridgeHandler.getDmxChannel(channel, this.thing));
        }
    } catch (IllegalArgumentException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    currentValues.add(DmxChannel.MIN_VALUE);
    currentValues.add(DmxChannel.MIN_VALUE);
    currentValues.add(DmxChannel.MIN_VALUE);
    if (configuration.get(CONFIG_DIMMER_FADE_TIME) != null) {
        fadeTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_FADE_TIME)).intValue();
        logger.debug("setting fadeTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_DIM_TIME) != null) {
        dimTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_DIM_TIME)).intValue();
        logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_TURNONVALUE) != null) {
        String turnOnValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNONVALUE)) + ":-1";
        ValueSet turnOnValue = ValueSet.fromString(turnOnValueString);
        if (turnOnValue.size() == 3) {
            this.turnOnValue = turnOnValue;
            logger.trace("set turnonvalue to {} in {}", turnOnValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-on value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOnValue.setFadeTime(fadeTime);
    if (configuration.get(CONFIG_DIMMER_TURNOFFVALUE) != null) {
        String turnOffValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNOFFVALUE)) + ":-1";
        ValueSet turnOffValue = ValueSet.fromString(turnOffValueString);
        if (turnOffValue.size() == 3) {
            this.turnOffValue = turnOffValue;
            logger.trace("set turnoffvalue to {} in {}", turnOffValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-off value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOffValue.setFadeTime(fadeTime);
    // register feedback listeners
    channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_R), this, ListenerType.VALUE);
    channels.get(1).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_G), this, ListenerType.VALUE);
    channels.get(2).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_B), this, ListenerType.VALUE);
    if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
        updateStatus(ThingStatus.ONLINE);
        dmxHandlerStatus = ThingStatusDetail.NONE;
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 53 with Configuration

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

the class TunableWhiteThingHandler method initialize.

@Override
public void initialize() {
    Configuration configuration = getConfig();
    Bridge bridge = getBridge();
    DmxBridgeHandler bridgeHandler;
    if (bridge == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge assigned");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    } else {
        bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
        if (bridgeHandler == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge handler available");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    if (configuration.get(CONFIG_DMX_ID) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "DMX channel configuration missing");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    try {
        List<BaseDmxChannel> configChannels = BaseDmxChannel.fromString((String) configuration.get(CONFIG_DMX_ID), bridgeHandler.getUniverseId());
        logger.trace("found {} channels in {}", configChannels.size(), this.thing.getUID());
        for (BaseDmxChannel channel : configChannels) {
            channels.add(bridgeHandler.getDmxChannel(channel, this.thing));
        }
    } catch (IllegalArgumentException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    if (channels.size() % 2 != 0) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Tunable white dimmers require an even number of channels");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    currentValues.add(DmxChannel.MIN_VALUE);
    currentValues.add(DmxChannel.MIN_VALUE);
    if (configuration.get(CONFIG_DIMMER_FADE_TIME) != null) {
        fadeTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_FADE_TIME)).intValue();
        logger.debug("setting fadeTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_DIM_TIME) != null) {
        dimTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_DIM_TIME)).intValue();
        logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_TURNONVALUE) != null) {
        String turnOnValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNONVALUE)) + ":-1";
        ValueSet turnOnValue = ValueSet.fromString(turnOnValueString);
        if (turnOnValue.size() % 2 == 0) {
            this.turnOnValue = turnOnValue;
            logger.trace("set turnonvalue to {} in {}", turnOnValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-on value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOnValue.setFadeTime(fadeTime);
    if (configuration.get(CONFIG_DIMMER_TURNOFFVALUE) != null) {
        String turnOffValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNOFFVALUE)) + ":-1";
        ValueSet turnOffValue = ValueSet.fromString(turnOffValueString);
        if (turnOffValue.size() % 2 == 0) {
            this.turnOffValue = turnOffValue;
            logger.trace("set turnoffvalue to {} in {}", turnOffValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-off value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOffValue.setFadeTime(fadeTime);
    // register feedback listeners
    channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_CW), this, ListenerType.VALUE);
    channels.get(1).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_WW), this, ListenerType.VALUE);
    if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
        updateStatus(ThingStatus.ONLINE);
        dmxHandlerStatus = ThingStatusDetail.NONE;
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 54 with Configuration

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

the class HueLightDiscoveryServiceOSGiTest method setUp.

@Before
public void setUp() {
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    Configuration configuration = new Configuration();
    configuration.put(HOST, "1.2.3.4");
    configuration.put(USER_NAME, "testUserName");
    configuration.put(SERIAL_NUMBER, "testSerialNumber");
    hueBridge = (Bridge) thingRegistry.createThingOfType(BRIDGE_THING_TYPE_UID, BRIDGE_THING_UID, null, "Bridge", configuration);
    assertThat(hueBridge, is(notNullValue()));
    thingRegistry.add(hueBridge);
    hueBridgeHandler = getThingHandler(hueBridge, HueBridgeHandler.class);
    assertThat(hueBridgeHandler, is(notNullValue()));
    discoveryService = getService(DiscoveryService.class, HueLightDiscoveryService.class);
    assertThat(discoveryService, is(notNullValue()));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) HueBridgeHandler(org.eclipse.smarthome.binding.hue.handler.HueBridgeHandler) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) Before(org.junit.Before)

Example 55 with Configuration

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

the class Lib485BridgeHandlerTest method setUp.

@Before
public void setUp() {
    bridgeProperties = new HashMap<>();
    bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
    bridge = BridgeBuilder.create(THING_TYPE_LIB485_BRIDGE, "lib485bridge").withLabel("Lib485 Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
    ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
    doAnswer(answer -> {
        ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
        return null;
    }).when(mockCallback).statusUpdated(any(), any());
    bridgeHandler = new Lib485BridgeHandler(bridge) {

        @Override
        protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
        }
    };
    bridgeHandler.getThing().setHandler(bridgeHandler);
    bridgeHandler.setCallback(mockCallback);
    bridgeHandler.initialize();
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Lib485BridgeHandler(org.eclipse.smarthome.binding.dmx.handler.Lib485BridgeHandler) ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) Thing(org.eclipse.smarthome.core.thing.Thing) 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