use of org.eclipse.smarthome.binding.dmx.internal.ValueSet 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());
}
}
use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.
the class ChaserThingHandler method parseChaserConfig.
private boolean parseChaserConfig(String configString) {
values.clear();
String strippedConfig = configString.replaceAll("(\\s)+", "");
for (String singleStepString : strippedConfig.split("\\|")) {
ValueSet value = ValueSet.fromString(singleStepString);
if (!value.isEmpty()) {
values.add(value);
logger.trace("added step value {} to thing {}", value, this.thing.getUID());
} else {
logger.debug("could not add step value: {} to thing {}, malformed", singleStepString, this.thing.getUID());
}
}
return (values.size() > 0);
}
use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.
the class ColorThingHandler 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;
}
currentValues.add(DmxChannel.MIN_VALUE);
currentValues.add(DmxChannel.MIN_VALUE);
currentValues.add(DmxChannel.MIN_VALUE);
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.size() == 3) {
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.size() == 3) {
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 listeners
channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_R), this, ListenerType.VALUE);
channels.get(1).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_G), this, ListenerType.VALUE);
channels.get(2).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_B), this, ListenerType.VALUE);
if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
updateStatus(ThingStatus.ONLINE);
dmxHandlerStatus = ThingStatusDetail.NONE;
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
}
use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.
the class TunableWhiteThingHandler 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 (channels.size() % 2 != 0) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Tunable white dimmers require an even number of channels");
dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
return;
}
currentValues.add(DmxChannel.MIN_VALUE);
currentValues.add(DmxChannel.MIN_VALUE);
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.size() % 2 == 0) {
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.size() % 2 == 0) {
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 listeners
channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_CW), this, ListenerType.VALUE);
channels.get(1).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_WW), this, ListenerType.VALUE);
if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
updateStatus(ThingStatus.ONLINE);
dmxHandlerStatus = ThingStatusDetail.NONE;
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
}
use of org.eclipse.smarthome.binding.dmx.internal.ValueSet in project smarthome by eclipse.
the class ValueSetTest method fadeAndHoldTime.
@Test
public void fadeAndHoldTime() {
ValueSet valueSet = new ValueSet(100, 200);
assertThat(valueSet.getFadeTime(), is(100));
assertThat(valueSet.getHoldTime(), is(200));
}
Aggregations