Search in sources :

Example 6 with ValueSet

use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.

the class ValueSetTest method valueAndRepetition.

@Test
public void valueAndRepetition() {
    ValueSet valueSet = new ValueSet(0, 0);
    valueSet.addValue(100);
    valueSet.addValue(200);
    // stored values
    assertThat(valueSet.getValue(0), is(100));
    assertThat(valueSet.getValue(1), is(200));
    // repetitions
    assertThat(valueSet.getValue(2), is(100));
    assertThat(valueSet.getValue(5), is(200));
}
Also used : ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Test(org.junit.Test)

Example 7 with ValueSet

use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.

the class ColorThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.trace("received command {} in channel {}", command, channelUID);
    ValueSet targetValueSet = new ValueSet(fadeTime, -1);
    switch(channelUID.getId()) {
        case CHANNEL_BRIGHTNESS_R:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_r", this.thing.getUID());
                currentValues.set(0, channels.get(0).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(0)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_r", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_G:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_g", this.thing.getUID());
                currentValues.set(1, channels.get(1).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(1)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_g", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_B:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_b", this.thing.getUID());
                currentValues.set(2, channels.get(2).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(2)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_b", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_COLOR:
            {
                if (command instanceof OnOffType) {
                    logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
                    targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
                } else if (command instanceof HSBType) {
                    logger.trace("adding color fade to channels in thing {}", this.thing.getUID());
                    targetValueSet.addValue(((HSBType) command).getRed());
                    targetValueSet.addValue(((HSBType) command).getGreen());
                    targetValueSet.addValue(((HSBType) command).getBlue());
                } else if ((command instanceof PercentType) || (command instanceof DecimalType)) {
                    logger.trace("adding brightness fade to channels in thing {}", this.thing.getUID());
                    PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
                    HSBType targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), brightness);
                    targetValueSet.addValue(targetColor.getRed());
                    targetValueSet.addValue(targetColor.getGreen());
                    targetValueSet.addValue(targetColor.getBlue());
                } else if (command instanceof IncreaseDecreaseType) {
                    if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                        logger.trace("stopping fade in thing {}", this.thing.getUID());
                        channels.forEach(DmxChannel::clearAction);
                        isDimming = false;
                        return;
                    } else {
                        logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
                        HSBType targetColor;
                        if (((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.HUNDRED);
                        } else {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.ZERO);
                        }
                        targetValueSet.addValue(targetColor.getRed());
                        targetValueSet.addValue(targetColor.getGreen());
                        targetValueSet.addValue(targetColor.getBlue());
                        targetValueSet.setFadeTime(dimTime);
                        isDimming = true;
                    }
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:color", this.thing.getUID());
                    currentValues.set(0, channels.get(0).getValue());
                    currentValues.set(1, channels.get(1).getValue());
                    currentValues.set(2, channels.get(2).getValue());
                    updateCurrentColor();
                    updateState(channelUID, currentColor);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:color", command.getClass(), this.thing.getUID());
                    return;
                }
                break;
            }
        default:
            logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
            return;
    }
    final ValueSet valueSet = targetValueSet;
    IntStream.range(0, channels.size()).forEach(i -> {
        channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 8 with ValueSet

use of org.eclipse.smarthome.binding.dmx.internal.ValueSet 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 9 with ValueSet

use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.

the class DimmerThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.trace("received command {} in channel {}", command, channelUID);
    ValueSet targetValueSet = new ValueSet(fadeTime, -1);
    switch(channelUID.getId()) {
        case CHANNEL_BRIGHTNESS:
            {
                if (command instanceof PercentType || command instanceof DecimalType) {
                    PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
                    logger.trace("adding fade to channels in thing {}", this.thing.getUID());
                    targetValueSet.addValue(brightness);
                } else if (command instanceof OnOffType) {
                    logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
                    targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
                } else if (command instanceof IncreaseDecreaseType) {
                    if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                        logger.trace("stopping fade in thing {}", this.thing.getUID());
                        channels.forEach(DmxChannel::clearAction);
                        isDimming = false;
                        return;
                    } else {
                        logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
                        targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue;
                        targetValueSet.setFadeTime(dimTime);
                        isDimming = true;
                    }
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:brightness", this.thing.getUID());
                    currentBrightness = Util.toPercentValue(channels.get(0).getValue());
                    updateState(channelUID, currentBrightness);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:brightness", command.getClass(), this.thing.getUID());
                    return;
                }
                break;
            }
        default:
            logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
            return;
    }
    final ValueSet valueSet = targetValueSet;
    IntStream.range(0, channels.size()).forEach(i -> {
        channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet)

Example 10 with ValueSet

use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.

the class TunableWhiteThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.trace("received command {} in channel {}", command, channelUID);
    ValueSet targetValueSet = new ValueSet(fadeTime, -1);
    switch(channelUID.getId()) {
        case CHANNEL_BRIGHTNESS:
            {
                if (command instanceof PercentType || command instanceof DecimalType) {
                    PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
                    logger.trace("adding fade to channels in thing {}", this.thing.getUID());
                    targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(brightness) * (100 - currentColorTemperature.intValue()) / 100));
                    targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(brightness) * currentColorTemperature.intValue() / 100));
                } else if (command instanceof OnOffType) {
                    logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
                    targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
                } else if (command instanceof IncreaseDecreaseType) {
                    if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                        logger.trace("stopping fade in thing {}", this.thing.getUID());
                        channels.forEach(DmxChannel::clearAction);
                        isDimming = false;
                        return;
                    } else {
                        logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
                        targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue;
                        targetValueSet.setFadeTime(dimTime);
                        isDimming = true;
                    }
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:brightness", this.thing.getUID());
                    currentValues.set(0, channels.get(0).getValue());
                    currentValues.set(1, channels.get(1).getValue());
                    updateCurrentBrightnessAndTemperature();
                    updateState(channelUID, currentBrightness);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:brightness", command.getClass(), this.thing.getUID());
                    return;
                }
                break;
            }
        case CHANNEL_BRIGHTNESS_CW:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_cw", this.thing.getUID());
                currentValues.set(0, channels.get(0).getValue());
                updateState(channelUID, Util.toPercentValue(currentValues.get(0)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_cw", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_WW:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_ww", this.thing.getUID());
                currentValues.set(1, channels.get(1).getValue());
                updateState(channelUID, Util.toPercentValue(currentValues.get(1)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_ww", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_COLOR_TEMPERATURE:
            {
                if (command instanceof PercentType) {
                    PercentType colorTemperature = (PercentType) command;
                    targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(currentBrightness) * (100 - colorTemperature.intValue()) / 100));
                    targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(currentBrightness) * colorTemperature.intValue() / 100));
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:color_temperature", this.thing.getUID());
                    currentValues.set(0, channels.get(0).getValue());
                    currentValues.set(1, channels.get(1).getValue());
                    updateCurrentBrightnessAndTemperature();
                    updateState(channelUID, currentColorTemperature);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:color_temperature", command.getClass(), this.thing.getUID());
                    return;
                }
                break;
            }
        default:
            logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
            return;
    }
    final ValueSet valueSet = targetValueSet;
    IntStream.range(0, channels.size()).forEach(i -> {
        channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet)

Aggregations

ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)11 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)5 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)4 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)4 RefreshType (org.eclipse.smarthome.core.types.RefreshType)4 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)3 Configuration (org.eclipse.smarthome.config.core.Configuration)3 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)3 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)3 PercentType (org.eclipse.smarthome.core.library.types.PercentType)3 Bridge (org.eclipse.smarthome.core.thing.Bridge)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 DmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel)2 Test (org.junit.Test)2 Vector (java.util.Vector)1 ResumeAction (org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1