Search in sources :

Example 86 with Configuration

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

the class ChaserThingHandler 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 (configuration.get(CONFIG_CHASER_STEPS) != null) {
        if (parseChaserConfig((String) configuration.get(CONFIG_CHASER_STEPS))) {
            if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
                updateStatus(ThingStatus.ONLINE);
                dmxHandlerStatus = ThingStatusDetail.NONE;
            } else {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
            }
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Chase configuration malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        }
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Chase configuration missing");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
    }
    if (configuration.get(CONFIG_CHASER_RESUME_AFTER) != null) {
        resumeAfter = (Boolean) configuration.get(CONFIG_CHASER_RESUME_AFTER);
        logger.trace("set resumeAfter to {}", resumeAfter);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 87 with Configuration

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

the class DimmerThingHandler 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 (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.isEmpty()) {
            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.isEmpty()) {
            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 listener
    channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS), 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 88 with Configuration

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

the class Lib485BridgeHandler method updateConfiguration.

@Override
protected void updateConfiguration() {
    Configuration configuration = getConfig();
    universe = new Universe(MIN_UNIVERSE_ID);
    receiverNodes.clear();
    if (configuration.get(CONFIG_ADDRESS) == null) {
        receiverNodes.put(new IpNode("localhost:9020"), null);
        logger.debug("sending to {} for {}", receiverNodes, this.thing.getUID());
    } else {
        try {
            for (IpNode receiverNode : IpNode.fromString((String) configuration.get(CONFIG_ADDRESS), DEFAULT_PORT)) {
                receiverNodes.put(receiverNode, null);
                logger.debug("sending to {} for {}", receiverNode, this.thing.getUID());
            }
        } catch (IllegalArgumentException e) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
            return;
        }
    }
    super.updateConfiguration();
    updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE);
    logger.debug("updated configuration for Lib485 bridge {}", this.thing.getUID());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode) Universe(org.eclipse.smarthome.binding.dmx.internal.multiverse.Universe)

Example 89 with Configuration

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

the class SacnBridgeHandler 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_SACN_MODE).equals("unicast"))) {
        if (configuration.get(CONFIG_ADDRESS) == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not initialize unicast sender (address not set)");
            return;
        } else {
            try {
                receiverNodes = IpNode.fromString((String) configuration.get(CONFIG_ADDRESS), SacnNode.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;
            }
        }
    } else {
        receiverNodes = new ArrayList<IpNode>();
        receiverNodes.add(SacnNode.getBroadcastNode(universe.getUniverseId()));
        logger.debug("using multicast mode to {} for {}", receiverNodes, this.thing.getUID());
    }
    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 sACN/E1.31 bridge {}", this.thing.getUID());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode)

Example 90 with Configuration

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

the class DmxBridgeHandler method updateConfiguration.

/**
 * get the configuration and update the bridge
 */
protected void updateConfiguration() {
    Configuration configuration = getConfig();
    if (configuration.get(CONFIG_APPLY_CURVE) != null) {
        universe.setDimCurveChannels((String) configuration.get(CONFIG_APPLY_CURVE));
    }
    if (configuration.get(CONFIG_REFRESH_RATE) != null) {
        float refreshRate = ((BigDecimal) configuration.get(CONFIG_REFRESH_RATE)).floatValue();
        if (refreshRate > 0) {
            refreshTime = (int) (1000.0 / refreshRate);
        } else {
            refreshTime = 0;
        }
    } else {
        refreshTime = 1000 / DEFAULT_REFRESH_RATE;
    }
    logger.debug("set refreshTime to {} ms in thing {}", refreshTime, this.thing.getUID());
    installScheduler();
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BigDecimal(java.math.BigDecimal)

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