use of org.openhab.core.items.ItemNotFoundException in project openhab1-addons by openhab.
the class RRD4jChartServlet method service.
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
logger.debug("RRD4J Received incoming chart request: ", req);
int width = 480;
try {
width = Integer.parseInt(req.getParameter("w"));
} catch (Exception e) {
}
int height = 240;
try {
height = Integer.parseInt(req.getParameter("h"));
} catch (Exception e) {
}
Long period = PERIODS.get(req.getParameter("period"));
if (period == null) {
// use a day as the default period
period = PERIODS.get("D");
}
// Create the start and stop time
Date timeEnd = new Date();
Date timeBegin = new Date(timeEnd.getTime() + period);
// Set the content type to that provided by the chart provider
res.setContentType("image/" + getChartType());
try {
BufferedImage chart = createChart(null, null, timeBegin, timeEnd, height, width, req.getParameter("items"), req.getParameter("groups"));
ImageIO.write(chart, getChartType().toString(), res.getOutputStream());
} catch (ItemNotFoundException e) {
logger.debug("Item not found error while generating chart.");
} catch (IllegalArgumentException e) {
logger.debug("Illegal argument in chart: {}", e);
}
}
use of org.openhab.core.items.ItemNotFoundException in project openhab1-addons by openhab.
the class CaldavPersistenceService method query.
@Override
public Iterable<HistoricItem> query(final FilterCriteria filter) {
List<CalDavEvent> events = calDavLoader.getEvents(new CalDavQuery(calendarId));
List<HistoricItem> outList = new ArrayList<HistoricItem>();
for (CalDavEvent calDavEvent : events) {
if (filter.getBeginDate() != null && calDavEvent.getEnd().toDate().before(filter.getBeginDate())) {
continue;
}
if (filter.getEndDate() != null && calDavEvent.getStart().toDate().after(filter.getEndDate())) {
continue;
}
Item item = null;
try {
item = this.itemRegistry.getItem(filter.getItemName());
} catch (ItemNotFoundException e) {
logger.error("item {} could not be found", filter.getItemName());
continue;
}
final List<EventUtils.EventContent> parseContent = EventUtils.parseContent(calDavEvent, item);
for (EventUtils.EventContent eventContent : parseContent) {
if (filter.getBeginDate() != null && eventContent.getTime().toDate().before(filter.getBeginDate())) {
continue;
}
if (filter.getEndDate() != null && eventContent.getTime().toDate().after(filter.getEndDate())) {
continue;
}
final State eventState = eventContent.getState();
if (filter.getState() != null && filter.getOperator() != null) {
switch(filter.getOperator()) {
case EQ:
{
if (!filter.getState().equals(eventState)) {
continue;
}
break;
}
case NEQ:
{
if (filter.getState().equals(eventState)) {
continue;
}
break;
}
case LTE:
{
if (eventState instanceof DecimalType && filter.getState() instanceof DecimalType) {
if (((DecimalType) eventState).longValue() > ((DecimalType) filter.getState()).longValue()) {
continue;
}
} else {
continue;
}
break;
}
case GTE:
{
if (eventState instanceof DecimalType && filter.getState() instanceof DecimalType) {
if (((DecimalType) eventState).longValue() < ((DecimalType) filter.getState()).longValue()) {
continue;
}
} else {
continue;
}
break;
}
case LT:
{
if (eventState instanceof DecimalType && filter.getState() instanceof DecimalType) {
if (((DecimalType) eventState).longValue() >= ((DecimalType) filter.getState()).longValue()) {
continue;
}
} else {
continue;
}
break;
}
case GT:
{
if (eventState instanceof DecimalType && filter.getState() instanceof DecimalType) {
if (((DecimalType) eventState).longValue() <= ((DecimalType) filter.getState()).longValue()) {
continue;
}
} else {
continue;
}
break;
}
}
}
// just filtered events are here...
final CaldavItem caldavItem = new CaldavItem(filter.getItemName(), eventState, eventContent.getTime().toDate());
caldavItem.setEvent(calDavEvent);
outList.add(caldavItem);
}
}
Collections.sort(outList, new Comparator<HistoricItem>() {
@Override
public int compare(HistoricItem arg0, HistoricItem arg1) {
if (filter.getOrdering().equals(FilterCriteria.Ordering.ASCENDING)) {
return (int) (arg0.getTimestamp().getTime() - arg1.getTimestamp().getTime());
} else {
return (int) (arg1.getTimestamp().getTime() - arg0.getTimestamp().getTime());
}
}
});
if (outList.size() < filter.getPageNumber() * filter.getPageSize()) {
return Collections.emptyList();
}
outList = outList.subList(filter.getPageNumber() * filter.getPageSize(), Math.min((filter.getPageNumber() * filter.getPageSize()) + filter.getPageSize(), outList.size()));
logger.trace("result size for query: {}", outList.size());
return outList;
}
use of org.openhab.core.items.ItemNotFoundException in project openhab1-addons by openhab.
the class ItemStateRequestProcessor method getItemState.
public ItemStateData getItemState(String itemId) throws ServiceException {
ItemRegistry itemRegistry = getItemRegistry();
ItemStateData itemState = null;
try {
Item item = itemRegistry.getItem(itemId);
StateTransformable state = getState(item);
itemState = new ItemStateData(System.currentTimeMillis(), itemId, state);
} catch (ItemNotFoundException ex) {
logger.info(itemId + " not found", ex);
}
return itemState;
}
use of org.openhab.core.items.ItemNotFoundException in project openhab1-addons by openhab.
the class LgTvMessageReader method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String remoteaddr = req.getRemoteAddr();
int start = remoteaddr.indexOf(":");
String t;
if (start > -1) {
t = remoteaddr.substring(0, start);
} else {
t = remoteaddr;
}
remoteaddr = t;
start = remoteaddr.indexOf("/");
if (start > -1) {
t = remoteaddr.substring(start + 1, remoteaddr.length());
} else {
t = remoteaddr;
}
remoteaddr = t;
PrintWriter out = res.getWriter();
res.setStatus(200);
String devicename = req.getParameter("devicename");
String value = req.getParameter("command");
if (value != null && !value.equals("")) {
res.setContentType("text/plain");
if (value.equals("geturl")) {
if (bindingprovider != null && itemregistry != null) {
for (String itemName : bindingprovider.getItemNames()) {
HashMap<String, String> values = bindingprovider.getDeviceCommands(itemName);
for (String cmd : values.keySet()) {
String[] commandParts = values.get(cmd).split(":");
String deviceCmd = commandParts[1];
String deviceId = commandParts[0];
if (deviceId.equals(devicename) && deviceCmd.equals("BROWSER_URL")) {
try {
Item i = itemregistry.getItem(itemName);
State state = i.getState();
String va = state.toString();
out.print(va);
} catch (ItemNotFoundException e) {
logger.error("item not found");
}
}
}
}
} else {
logger.error("itemregistry=null or bindingprovider=null");
}
} else {
out.println("command: " + value);
}
} else {
String url = req.getRequestURL().toString();
// String devicename=req.getParameter("devicename");
res.setContentType("text/html");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>LgTv Binding</TITLE>");
out.println("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>");
out.println("<script type=\"text/javascript\">");
out.println("var serviceaddress;");
out.println("var oldpage;");
out.println("function CallRegular(){");
out.println("$.ajax({ type:\'Get\', url: serviceaddress, success:function(data) ");
out.println(" { ");
out.println(" if (data!=\"Uninitialized\"&&data!=oldpage) {document.getElementById(\'content1\').src=data;oldpage=data;} ");
out.println(" } })");
out.println("}");
out.println("function LoadPage(){");
out.println(" serviceaddress=\'" + url + "?command=geturl&devicename=" + devicename + "\'");
out.println(" CallRegular(); ");
out.println(" setInterval(CallRegular,10000);");
out.println("}");
out.println(" </script>");
out.println("</HEAD>");
out.println("<frameset rows=\"100%,*\" onload=\"LoadPage();\">");
out.println("<frame src=\"#\" id=\"content1\">");
out.println("</frameset>");
out.println("<BODY>");
out.println("<BIG>Hello World</BIG>");
out.println("</BODY></HTML>");
}
out.close();
}
use of org.openhab.core.items.ItemNotFoundException in project openhab1-addons by openhab.
the class SappBinding method updateState.
/**
* updates item repository for a single item
*/
private void updateState(String pnmasId, SappAddressType sappAddressType, int addressToUpdate, int newState, SappBindingProvider provider) {
logger.debug("Updating {} {} with new value {}", sappAddressType, addressToUpdate, newState);
for (String itemName : provider.getItemNames()) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = (SappBindingConfigSwitchItem) provider.getBindingConfig(itemName);
if (!sappBindingConfigSwitchItem.isPollerSuspender()) {
SappAddressOnOffStatus statusAddress = sappBindingConfigSwitchItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigSwitchItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOnValue() ? OnOffType.ON : OnOffType.OFF;
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
}
} else if (item instanceof ContactItem) {
SappBindingConfigContactItem sappBindingConfigContactItem = (SappBindingConfigContactItem) provider.getBindingConfig(itemName);
SappAddressOpenClosedStatus statusAddress = sappBindingConfigContactItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigContactItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOpenValue() ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = (SappBindingConfigNumberItem) provider.getBindingConfig(itemName);
SappAddressDecimal address = sappBindingConfigNumberItem.getStatus();
if (address.getAddressType() == sappAddressType && address.getPnmasId().equals(pnmasId) && addressToUpdate == address.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigNumberItem);
int result = SappBindingConfigUtils.maskWithSubAddress(address.getSubAddress(), newState);
State stateToSet = new DecimalType(address.scaledValue(result, address.getSubAddress()));
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = (SappBindingConfigRollershutterItem) provider.getBindingConfig(itemName);
SappAddressRollershutterStatus statusAddress = sappBindingConfigRollershutterItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigRollershutterItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOpenValue() ? PercentType.HUNDRED : (result == statusAddress.getClosedValue() ? PercentType.ZERO : PercentType.valueOf("50"));
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = (SappBindingConfigDimmerItem) provider.getBindingConfig(itemName);
SappAddressDimmer statusAddress = sappBindingConfigDimmerItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigDimmerItem);
int result = statusAddress.scaledValue(SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState), statusAddress.getSubAddress()).round(new MathContext(0, RoundingMode.HALF_EVEN)).intValue();
State stateToSet;
if (result <= PercentType.ZERO.intValue()) {
stateToSet = PercentType.ZERO;
} else if (result >= PercentType.HUNDRED.intValue()) {
stateToSet = PercentType.HUNDRED;
} else {
stateToSet = PercentType.valueOf(String.valueOf(result));
}
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else {
logger.error("unimplemented item type: {}", item.getClass().getSimpleName());
}
} catch (ItemNotFoundException e) {
logger.error("Item {} not found", itemName);
}
}
}
Aggregations