Search in sources :

Example 6 with FadeAction

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

the class FadeActionTest method checkWithFadingWithoutHold.

@Test
public void checkWithFadingWithoutHold() {
    FadeAction fadeAction = new FadeAction(TEST_FADE_TIME, TEST_VALUE, 0);
    DmxChannel testChannel = new DmxChannel(0, 1, 0);
    testChannel.setValue(0);
    long startTime = System.currentTimeMillis();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
    assertThat(fadeAction.getNewValue(testChannel, startTime), is(0));
    assertThat(fadeAction.getState(), is(ActionState.RUNNING));
    assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME / 2), is(256 * TEST_VALUE / 2));
    assertThat(fadeAction.getNewValue(testChannel, startTime + 1000), is(256 * TEST_VALUE));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.jupiter.api.Test)

Example 7 with FadeAction

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

the class FadeActionTest method checkWithoutFadingWithoutHold.

@Test
public void checkWithoutFadingWithoutHold() {
    FadeAction fadeAction = new FadeAction(0, TEST_VALUE, 0);
    DmxChannel testChannel = new DmxChannel(0, 1, 0);
    testChannel.setValue(0);
    long startTime = System.currentTimeMillis();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
    assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * TEST_VALUE));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.jupiter.api.Test)

Example 8 with FadeAction

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

the class FadeActionTest method checkWithoutFadingWithInfiniteHold.

@Test
public void checkWithoutFadingWithInfiniteHold() {
    FadeAction fadeAction = new FadeAction(0, TEST_VALUE, -1);
    DmxChannel testChannel = new DmxChannel(0, 1, 0);
    testChannel.setValue(0);
    long startTime = System.currentTimeMillis();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
    assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * TEST_VALUE));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.jupiter.api.Test)

Example 9 with FadeAction

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

the class FadeActionTest method checkWithFadingWithInfiniteHold.

@Test
public void checkWithFadingWithInfiniteHold() {
    FadeAction fadeAction = new FadeAction(TEST_FADE_TIME, TEST_VALUE, -1);
    DmxChannel testChannel = new DmxChannel(0, 1, 0);
    testChannel.setValue(0);
    long startTime = System.currentTimeMillis();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
    assertThat(fadeAction.getNewValue(testChannel, startTime), is(0));
    assertThat(fadeAction.getState(), is(ActionState.RUNNING));
    assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME / 2), is(256 * TEST_VALUE / 2));
    assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME), is(256 * TEST_VALUE));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.smarthomej.binding.dmx.internal.action.FadeAction) DmxChannel(org.smarthomej.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.jupiter.api.Test)

Example 10 with FadeAction

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

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());
                    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 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.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) HSBType(org.openhab.core.library.types.HSBType)

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