use of org.eclipse.smarthome.core.types.State 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;
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class ZonePlayerHandler method updateChannel.
protected void updateChannel(String channelId) {
if (!isLinked(channelId)) {
return;
}
String url;
State newState = UnDefType.UNDEF;
switch(channelId) {
case STATE:
if (stateMap.get("TransportState") != null) {
newState = new StringType(stateMap.get("TransportState"));
}
break;
case CONTROL:
if (stateMap.get("TransportState") != null) {
if (stateMap.get("TransportState").equals(STATE_PLAYING)) {
newState = PlayPauseType.PLAY;
} else if (stateMap.get("TransportState").equals(STATE_STOPPED)) {
newState = PlayPauseType.PAUSE;
} else if (stateMap.get("TransportState").equals(STATE_PAUSED_PLAYBACK)) {
newState = PlayPauseType.PAUSE;
}
}
break;
case STOP:
if (stateMap.get("TransportState") != null) {
if (stateMap.get("TransportState").equals(STATE_STOPPED)) {
newState = OnOffType.ON;
} else {
newState = OnOffType.OFF;
}
}
break;
case SHUFFLE:
if (stateMap.get("CurrentPlayMode") != null) {
newState = isShuffleActive() ? OnOffType.ON : OnOffType.OFF;
}
break;
case REPEAT:
if (stateMap.get("CurrentPlayMode") != null) {
newState = new StringType(getRepeatMode());
}
break;
case LED:
if (stateMap.get("CurrentLEDState") != null) {
newState = stateMap.get("CurrentLEDState").equals("On") ? OnOffType.ON : OnOffType.OFF;
}
break;
case ZONENAME:
if (stateMap.get("CurrentZoneName") != null) {
newState = new StringType(stateMap.get("CurrentZoneName"));
}
break;
case ZONEGROUPID:
if (stateMap.get("LocalGroupUUID") != null) {
newState = new StringType(stateMap.get("LocalGroupUUID"));
}
break;
case COORDINATOR:
newState = new StringType(getCoordinator());
break;
case LOCALCOORDINATOR:
if (stateMap.get("GroupCoordinatorIsLocal") != null) {
newState = stateMap.get("GroupCoordinatorIsLocal").equals("true") ? OnOffType.ON : OnOffType.OFF;
}
break;
case VOLUME:
if (stateMap.get("VolumeMaster") != null) {
newState = new PercentType(stateMap.get("VolumeMaster"));
}
break;
case MUTE:
if (stateMap.get("MuteMaster") != null) {
newState = stateMap.get("MuteMaster").equals("1") ? OnOffType.ON : OnOffType.OFF;
}
break;
case LINEIN:
if (stateMap.get("LineInConnected") != null) {
newState = stateMap.get("LineInConnected").equals("true") ? OnOffType.ON : OnOffType.OFF;
} else if (stateMap.get("TOSLinkConnected") != null) {
newState = stateMap.get("TOSLinkConnected").equals("true") ? OnOffType.ON : OnOffType.OFF;
}
break;
case ALARMRUNNING:
if (stateMap.get("AlarmRunning") != null) {
newState = stateMap.get("AlarmRunning").equals("1") ? OnOffType.ON : OnOffType.OFF;
}
break;
case ALARMPROPERTIES:
if (stateMap.get("RunningAlarmProperties") != null) {
newState = new StringType(stateMap.get("RunningAlarmProperties"));
}
break;
case CURRENTTRACK:
if (stateMap.get("CurrentURIFormatted") != null) {
newState = new StringType(stateMap.get("CurrentURIFormatted"));
}
break;
case CURRENTTITLE:
if (stateMap.get("CurrentTitle") != null) {
newState = new StringType(stateMap.get("CurrentTitle"));
}
break;
case CURRENTARTIST:
if (stateMap.get("CurrentArtist") != null) {
newState = new StringType(stateMap.get("CurrentArtist"));
}
break;
case CURRENTALBUM:
if (stateMap.get("CurrentAlbum") != null) {
newState = new StringType(stateMap.get("CurrentAlbum"));
}
break;
case CURRENTALBUMART:
newState = null;
updateAlbumArtChannel(false);
break;
case CURRENTALBUMARTURL:
url = getAlbumArtUrl();
if (url != null) {
newState = new StringType(url);
}
break;
case CURRENTTRANSPORTURI:
if (stateMap.get("CurrentURI") != null) {
newState = new StringType(stateMap.get("CurrentURI"));
}
break;
case CURRENTTRACKURI:
if (stateMap.get("CurrentTrackURI") != null) {
newState = new StringType(stateMap.get("CurrentTrackURI"));
}
break;
case TUNEINSTATIONID:
if (stateMap.get("CurrentTuneInStationId") != null) {
newState = new StringType(stateMap.get("CurrentTuneInStationId"));
}
break;
default:
newState = null;
break;
}
if (newState != null) {
updateState(channelId, newState);
}
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class CommunicationManager method receiveUpdate.
private void receiveUpdate(ItemStateEvent updateEvent) {
final String itemName = updateEvent.getItemName();
final State newState = updateEvent.getItemState();
handleEvent(itemName, newState, updateEvent.getSource(), s -> acceptedStateTypeMap.get(s), (profile, thing, convertedState) -> {
//
safeCaller.create(profile, Profile.class).withAsync().withIdentifier(//
thing).withTimeout(//
THINGHANDLER_EVENT_TIMEOUT).build().onStateUpdateFromItem(convertedState);
});
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class ProfileCallbackImpl method sendUpdate.
@Override
public void sendUpdate(State state) {
Item item = itemProvider.apply(link.getItemName());
State acceptedState = itemStateConverter.convertToAcceptedState(state, item);
eventPublisher.post(ItemEventFactory.createStateEvent(link.getItemName(), acceptedState, link.getLinkedUID().toString()));
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class RuleTriggerManager method internalGetRules.
private Iterable<Rule> internalGetRules(TriggerTypes triggerType, Item item, Type oldType, Type newType) {
List<Rule> result = new ArrayList<>();
switch(triggerType) {
case STARTUP:
return systemStartupTriggeredRules;
case SHUTDOWN:
return systemShutdownTriggeredRules;
case TIMER:
return timerEventTriggeredRules;
case UPDATE:
if (newType instanceof State) {
List<Class<? extends State>> acceptedDataTypes = item.getAcceptedDataTypes();
final State state = (State) newType;
internalGetUpdateRules(item.getName(), false, acceptedDataTypes, state, result);
for (String groupName : item.getGroupNames()) {
internalGetUpdateRules(groupName, true, acceptedDataTypes, state, result);
}
}
break;
case CHANGE:
if (newType instanceof State && oldType instanceof State) {
List<Class<? extends State>> acceptedDataTypes = item.getAcceptedDataTypes();
final State newState = (State) newType;
final State oldState = (State) oldType;
internalGetChangeRules(item.getName(), false, acceptedDataTypes, newState, oldState, result);
for (String groupName : item.getGroupNames()) {
internalGetChangeRules(groupName, true, acceptedDataTypes, newState, oldState, result);
}
}
break;
case COMMAND:
if (newType instanceof Command) {
List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
final Command command = (Command) newType;
internalGetCommandRules(item.getName(), false, acceptedCommandTypes, command, result);
for (String groupName : item.getGroupNames()) {
internalGetCommandRules(groupName, true, acceptedCommandTypes, command, result);
}
}
break;
default:
break;
}
return result;
}
Aggregations