use of org.smarthomej.binding.dmx.internal.action.ResumeAction 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++;
}
}
use of org.smarthomej.binding.dmx.internal.action.ResumeAction 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());
}
}
use of org.smarthomej.binding.dmx.internal.action.ResumeAction in project addons by smarthomej.
the class DmxChannelTest method checkFadeActionWithResume.
@Test
public void checkFadeActionWithResume() {
dmxChannel.setValue(127);
dmxChannel.suspendAction();
dmxChannel.addChannelAction(new FadeAction(1000, 243, 0));
dmxChannel.addChannelAction(new ResumeAction());
dmxChannel.getNewValue(currentTime);
assertThat(dmxChannel.hasRunningActions(), is(true));
Mockito.verify(dimmerThingHandler).updateChannelValue(valueChannelUID, 127);
// check action completes
dmxChannel.getNewValue(currentTime);
currentTime += 1000;
dmxChannel.getNewValue(currentTime);
assertThat(dmxChannel.hasRunningActions(), is(true));
Mockito.verify(dimmerThingHandler).updateChannelValue(valueChannelUID, 243);
// check state is restored
dmxChannel.getNewValue(currentTime);
assertThat(dmxChannel.hasRunningActions(), is(false));
Mockito.verify(dimmerThingHandler).updateChannelValue(valueChannelUID, 127);
}
Aggregations