Search in sources :

Example 1 with FadeAction

use of org.smarthomej.binding.dmx.internal.action.FadeAction in project addons by smarthomej.

the class DmxBridgeHandler method immediateFade.

/**
 * sends an immediate fade to the DMX output (for rule actions)
 *
 * @param channelString a String containing the channels
 * @param fadeString a String containing the fade/chase definition
 * @param resumeAfter a boolean if the previous state should be restored
 */
public void immediateFade(String channelString, String fadeString, Boolean resumeAfter) {
    // parse channel config
    List<DmxChannel> channels = new ArrayList<>();
    try {
        List<BaseDmxChannel> configChannels = BaseDmxChannel.fromString(channelString, getUniverseId());
        logger.trace("found {} channels in {}", configChannels.size(), this.thing.getUID());
        for (BaseDmxChannel channel : configChannels) {
            channels.add(getDmxChannel(channel, this.thing));
        }
    } catch (IllegalArgumentException e) {
        logger.warn("invalid channel configuration: {}", channelString);
        return;
    }
    // parse fade config
    List<ValueSet> value = ValueSet.parseChaseConfig(fadeString);
    if (value.isEmpty()) {
        logger.warn("invalid fade configuration: {}", fadeString);
        return;
    }
    // do action
    Integer channelCounter = 0;
    for (DmxChannel channel : channels) {
        if (resumeAfter) {
            channel.suspendAction();
        } else {
            channel.clearAction();
        }
        for (ValueSet step : value) {
            channel.addChannelAction(new FadeAction(step.getFadeTime(), step.getValue(channelCounter), step.getHoldTime()));
        }
        if (resumeAfter) {
            channel.addChannelAction(new ResumeAction());
        }
        channelCounter++;
    }
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) BaseDmxChannel(org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel) ArrayList(java.util.ArrayList) ResumeAction(org.smarthomej.binding.dmx.internal.action.ResumeAction)

Example 2 with FadeAction

use of org.smarthomej.binding.dmx.internal.action.FadeAction in project addons by smarthomej.

the class ChaserThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    switch(channelUID.getId()) {
        case CHANNEL_SWITCH:
            if (command instanceof OnOffType) {
                if (((OnOffType) command).equals(OnOffType.ON)) {
                    Integer channelCounter = 0;
                    for (DmxChannel channel : channels) {
                        if (resumeAfter) {
                            channel.suspendAction();
                        } else {
                            channel.clearAction();
                        }
                        for (ValueSet value : values) {
                            channel.addChannelAction(new FadeAction(value.getFadeTime(), value.getValue(channelCounter), value.getHoldTime()));
                        }
                        if (resumeAfter) {
                            channel.addChannelAction(new ResumeAction());
                        }
                        channel.addListener(channelUID, this, ListenerType.ACTION);
                        channelCounter++;
                    }
                } else {
                    for (DmxChannel channel : channels) {
                        if (resumeAfter && channel.isSuspended()) {
                            channel.setChannelAction(new ResumeAction());
                        } else {
                            channel.clearAction();
                        }
                    }
                }
            } else if (command instanceof RefreshType) {
                updateState(channelUID, isRunning);
            } else {
                logger.debug("command {} not supported in channel {}:switch", command.getClass(), this.thing.getUID());
            }
            break;
        case CHANNEL_CONTROL:
            if (command instanceof StringType) {
                List<ValueSet> newValues = ValueSet.parseChaseConfig(((StringType) command).toString());
                if (!newValues.isEmpty()) {
                    values = newValues;
                    logger.debug("updated chase config in {}", this.thing.getUID());
                } else {
                    logger.debug("could not update chase config in {}, malformed: {}", this.thing.getUID(), command);
                }
            } else {
                logger.debug("command {} not supported in channel {}:control", command.getClass(), this.thing.getUID());
            }
            break;
        default:
            logger.debug("Channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
    }
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) ResumeAction(org.smarthomej.binding.dmx.internal.action.ResumeAction) RefreshType(org.openhab.core.types.RefreshType) ValueSet(org.smarthomej.binding.dmx.internal.ValueSet)

Example 3 with FadeAction

use of org.smarthomej.binding.dmx.internal.action.FadeAction in project addons by smarthomej.

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());
                    if (((OnOffType) command) == OnOffType.ON) {
                        targetValueSet = turnOnValue;
                    } else {
                        if (dynamicTurnOnValue) {
                            turnOnValue.clear();
                            for (DmxChannel channel : channels) {
                                turnOnValue.addValue(channel.getValue());
                            }
                            logger.trace("stored channel values fort next turn-on");
                        }
                        targetValueSet = 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.smarthomej.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) ValueSet(org.smarthomej.binding.dmx.internal.ValueSet)

Example 4 with FadeAction

use of org.smarthomej.binding.dmx.internal.action.FadeAction in project addons by smarthomej.

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());
                    if (((OnOffType) command) == OnOffType.ON) {
                        targetValueSet = turnOnValue;
                    } else {
                        if (dynamicTurnOnValue) {
                            turnOnValue.clear();
                            for (DmxChannel channel : channels) {
                                turnOnValue.addValue(channel.getValue());
                            }
                            logger.trace("stored channel values fort next turn-on");
                        }
                        targetValueSet = 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.smarthomej.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) ValueSet(org.smarthomej.binding.dmx.internal.ValueSet)

Example 5 with FadeAction

use of org.smarthomej.binding.dmx.internal.action.FadeAction in project addons by smarthomej.

the class DmxChannelTest method setAndClearAction.

@Test
public void setAndClearAction() {
    // has action
    dmxChannel.setChannelAction(new FadeAction(0, 100, -1));
    assertThat(dmxChannel.hasRunningActions(), is(true));
    // clear action
    dmxChannel.clearAction();
    assertThat(dmxChannel.hasRunningActions(), is(false));
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) Test(org.junit.jupiter.api.Test)

Aggregations

FadeAction (org.smarthomej.binding.dmx.internal.action.FadeAction)15 DmxChannel (org.smarthomej.binding.dmx.internal.multiverse.DmxChannel)11 Test (org.junit.jupiter.api.Test)10 BaseDmxChannel (org.smarthomej.binding.dmx.internal.multiverse.BaseDmxChannel)5 OnOffType (org.openhab.core.library.types.OnOffType)4 RefreshType (org.openhab.core.types.RefreshType)4 ValueSet (org.smarthomej.binding.dmx.internal.ValueSet)4 DecimalType (org.openhab.core.library.types.DecimalType)3 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)3 PercentType (org.openhab.core.library.types.PercentType)3 ResumeAction (org.smarthomej.binding.dmx.internal.action.ResumeAction)3 ArrayList (java.util.ArrayList)1 HSBType (org.openhab.core.library.types.HSBType)1 StringType (org.openhab.core.library.types.StringType)1