use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class DialogProcessor method toggleProcessing.
private void toggleProcessing(boolean value) {
if (this.processing == value) {
return;
}
this.processing = value;
if (listeningItem != null && ItemUtil.isValidItemName(listeningItem)) {
OnOffType command = (value) ? OnOffType.ON : OnOffType.OFF;
eventPublisher.post(ItemEventFactory.createCommandEvent(listeningItem, command));
}
}
use of org.eclipse.smarthome.core.library.types.OnOffType 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.core.library.types.OnOffType in project smarthome by eclipse.
the class DmxChannel method getNewHiResValue.
/**
* Get the new value for this channel as determined by active actions or the
* current value.
*
* @param calculationTime UNIX timestamp
* @return value 0-65535
*/
public synchronized Integer getNewHiResValue(long calculationTime) {
if (hasRunningActions()) {
logger.trace("checking actions, list is {}", actions);
BaseAction action = actions.get(0);
value = action.getNewValue(this, calculationTime);
if (action.getState() == ActionState.COMPLETED && hasRunningActions()) {
switchToNextAction();
} else if (action.getState() == ActionState.COMPLETEDFINAL) {
clearAction();
}
}
// send updates not more than once in a second, and only on value change
if ((lastStateValue != value) && (calculationTime - lastStateTimestamp > refreshTime)) {
// notify value listeners if value changed
for (Entry<ChannelUID, DmxThingHandler> listener : valueListeners.entrySet()) {
int dmxValue = Util.toDmxValue(value >> 8);
(listener.getValue()).updateChannelValue(listener.getKey(), dmxValue);
logger.trace("sending VALUE={} (raw={}) status update to listener {} ({})", dmxValue, value, listener.getValue(), listener.getKey());
}
// notify on/off listeners if on/off state changed
if ((lastStateValue == 0) || (value == 0)) {
OnOffType state = (value == 0) ? OnOffType.OFF : OnOffType.ON;
for (Entry<ChannelUID, DmxThingHandler> listener : onOffListeners.entrySet()) {
(listener.getValue()).updateSwitchState(listener.getKey(), state);
logger.trace("sending ONOFF={} (raw={}), status update to listener {}", state, value, listener.getKey());
}
}
lastStateValue = value;
lastStateTimestamp = calculationTime;
}
return value;
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemWithRollershutterBaseItemConversionWorks.
@Test
public void assertThatGroupItemWithRollershutterBaseItemConversionWorks() {
// initially this group has State UndefType.NULL
GroupItem groupItem = new GroupItem("root", new RollershutterItem("myRollerShutter"));
State groupStateAsOnOff = groupItem.getStateAs(OnOffType.class);
// a state conversion from NULL to OnOffType should not be possible
assertNull(groupStateAsOnOff);
// init group
groupItem.setState(new PercentType(70));
groupStateAsOnOff = groupItem.getStateAs(OnOffType.class);
// any value >0 means on, so 50% means the group state should be ON
assertTrue(OnOffType.ON.equals(groupStateAsOnOff));
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class DefaultChartProvider method addItem.
boolean addItem(Chart chart, QueryablePersistenceService service, Date timeBegin, Date timeEnd, Item item, int seriesCounter, ChartTheme chartTheme, int dpi) {
Color color = chartTheme.getLineColor(seriesCounter);
// Get the item label
String label = null;
if (itemUIRegistry != null) {
// Get the item label
label = itemUIRegistry.getLabel(item.getName());
if (label != null && label.contains("[") && label.contains("]")) {
label = label.substring(0, label.indexOf('['));
}
}
if (label == null) {
label = item.getName();
}
Iterable<HistoricItem> result;
FilterCriteria filter;
// Generate data collections
List<Date> xData = new ArrayList<Date>();
List<Number> yData = new ArrayList<Number>();
// Declare state here so it will hold the last value at the end of the process
State state = null;
// First, get the value at the start time.
// This is necessary for values that don't change often otherwise data will start
// after the start of the graph (or not at all if there's no change during the graph period)
filter = new FilterCriteria();
filter.setEndDate(ZonedDateTime.ofInstant(timeBegin.toInstant(), timeZoneProvider.getTimeZone()));
filter.setItemName(item.getName());
filter.setPageSize(1);
filter.setOrdering(Ordering.DESCENDING);
result = service.query(filter);
if (result.iterator().hasNext()) {
HistoricItem historicItem = result.iterator().next();
state = historicItem.getState();
xData.add(timeBegin);
yData.add(convertData(state));
}
// Now, get all the data between the start and end time
filter.setBeginDate(ZonedDateTime.ofInstant(timeBegin.toInstant(), timeZoneProvider.getTimeZone()));
filter.setEndDate(ZonedDateTime.ofInstant(timeEnd.toInstant(), timeZoneProvider.getTimeZone()));
filter.setPageSize(Integer.MAX_VALUE);
filter.setOrdering(Ordering.ASCENDING);
// Get the data from the persistence store
result = service.query(filter);
Iterator<HistoricItem> it = result.iterator();
// Iterate through the data
while (it.hasNext()) {
HistoricItem historicItem = it.next();
// to avoid diagonal lines
if (state instanceof OnOffType || state instanceof OpenClosedType) {
Calendar cal = Calendar.getInstance();
cal.setTime(historicItem.getTimestamp());
cal.add(Calendar.MILLISECOND, -1);
xData.add(cal.getTime());
yData.add(convertData(state));
}
state = historicItem.getState();
xData.add(historicItem.getTimestamp());
yData.add(convertData(state));
}
// Lastly, add the final state at the endtime
if (state != null) {
xData.add(timeEnd);
yData.add(convertData(state));
}
// The chart engine will throw an exception if there's no data
if (xData.size() == 0) {
return false;
}
// If there's only 1 data point, plot it again!
if (xData.size() == 1) {
xData.add(xData.iterator().next());
yData.add(yData.iterator().next());
}
Series series = chart.addSeries(label, xData, yData);
float lineWidth = (float) chartTheme.getLineWidth(dpi);
series.setLineStyle(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
series.setMarker(SeriesMarker.NONE);
series.setLineColor(color);
// We use this to decide whether to put the legend in the top or bottom corner.
if (yData.iterator().next().floatValue() > ((series.getYMax() - series.getYMin()) / 2 + series.getYMin())) {
legendPosition++;
} else {
legendPosition--;
}
return true;
}
Aggregations