Search in sources :

Example 1 with DmxChannel

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

the class ChaserThingHandler method dispose.

@Override
public void dispose() {
    if (channels.size() != 0) {
        Bridge bridge = getBridge();
        if (bridge != null) {
            DmxBridgeHandler bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
            if (bridgeHandler != null) {
                bridgeHandler.unregisterDmxChannels(this.thing);
                logger.debug("removing {} channels from {}", channels.size(), this.thing.getUID());
            }
            ChannelUID switchChannelUID = new ChannelUID(this.thing.getUID(), CHANNEL_SWITCH);
            for (DmxChannel channel : channels) {
                channel.removeListener(switchChannelUID);
            }
        }
        channels.clear();
    }
}
Also used : BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 2 with DmxChannel

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

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) {
                Vector<ValueSet> oldValues = new Vector<ValueSet>(values);
                if (parseChaserConfig(((StringType) command).toString())) {
                    logger.debug("updated chase config in {}", this.thing.getUID());
                } else {
                    // restore old chase config
                    values = oldValues;
                    logger.debug("could not update chase config in {}, malformed", this.thing.getUID());
                }
            } 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.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) StringType(org.eclipse.smarthome.core.library.types.StringType) ResumeAction(org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Vector(java.util.Vector)

Example 3 with DmxChannel

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

the class FadeActionTest method checkWithFadingWithoutHold.

@Test
public void checkWithFadingWithoutHold() {
    FadeAction fadeAction = new FadeAction(testFadeTime, testValue, 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 + testFadeTime / 2), is(256 * testValue / 2));
    assertThat(fadeAction.getNewValue(testChannel, startTime + 1000), is(256 * testValue));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.Test)

Example 4 with DmxChannel

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

the class FadeActionTest method checkWithoutFadingWithInfiniteHold.

@Test
public void checkWithoutFadingWithInfiniteHold() {
    FadeAction fadeAction = new FadeAction(0, testValue, -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 * testValue));
    assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL));
    fadeAction.reset();
    assertThat(fadeAction.getState(), is(ActionState.WAITING));
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) Test(org.junit.Test)

Example 5 with DmxChannel

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

the class DmxChannelTest method setup.

@Before
public void setup() {
    dimmerThingHandler = Mockito.mock(DimmerThingHandler.class);
    dmxChannel = new DmxChannel(0, 1, 0);
    dmxChannel.addListener(valueChannelUID, dimmerThingHandler, ListenerType.VALUE);
    dmxChannel.setValue(0);
    currentTime = System.currentTimeMillis();
}
Also used : DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) DimmerThingHandler(org.eclipse.smarthome.binding.dmx.handler.DimmerThingHandler) Before(org.junit.Before)

Aggregations

DmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel)10 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)8 Test (org.junit.Test)6 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)2 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)2 RefreshType (org.eclipse.smarthome.core.types.RefreshType)2 Vector (java.util.Vector)1 DimmerThingHandler (org.eclipse.smarthome.binding.dmx.handler.DimmerThingHandler)1 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)1 ResumeAction (org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1 Bridge (org.eclipse.smarthome.core.thing.Bridge)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1 Before (org.junit.Before)1