Search in sources :

Example 6 with ItemNotFoundException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) NamespaceException(org.osgi.service.http.NamespaceException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException) IOException(java.io.IOException) Date(java.util.Date) BufferedImage(java.awt.image.BufferedImage) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 7 with ItemNotFoundException

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;
}
Also used : EventUtils(org.openhab.io.caldav.EventUtils) ArrayList(java.util.ArrayList) HistoricItem(org.openhab.core.persistence.HistoricItem) Item(org.openhab.core.items.Item) CalDavEvent(org.openhab.io.caldav.CalDavEvent) State(org.openhab.core.types.State) DecimalType(org.openhab.core.library.types.DecimalType) CalDavQuery(org.openhab.io.caldav.CalDavQuery) HistoricItem(org.openhab.core.persistence.HistoricItem) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 8 with ItemNotFoundException

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;
}
Also used : Item(org.openhab.core.items.Item) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) ItemStateData(org.creek.mailcontrol.model.data.ItemStateData) ItemRegistry(org.openhab.core.items.ItemRegistry) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 9 with ItemNotFoundException

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();
}
Also used : Item(org.openhab.core.items.Item) State(org.openhab.core.types.State) PrintWriter(java.io.PrintWriter) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 10 with ItemNotFoundException

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);
        }
    }
}
Also used : SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) ContactItem(org.openhab.core.library.items.ContactItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) MathContext(java.math.MathContext) SappAddressOpenClosedStatus(org.openhab.binding.sapp.internal.model.SappAddressOpenClosedStatus) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) Item(org.openhab.core.items.Item) ContactItem(org.openhab.core.library.items.ContactItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappAddressOnOffStatus(org.openhab.binding.sapp.internal.model.SappAddressOnOffStatus) SappAddressDimmer(org.openhab.binding.sapp.internal.model.SappAddressDimmer) SappAddressDecimal(org.openhab.binding.sapp.internal.model.SappAddressDecimal) State(org.openhab.core.types.State) SappAddressRollershutterStatus(org.openhab.binding.sapp.internal.model.SappAddressRollershutterStatus) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)16 Item (org.openhab.core.items.Item)15 NumberItem (org.openhab.core.library.items.NumberItem)7 ContactItem (org.openhab.core.library.items.ContactItem)6 DimmerItem (org.openhab.core.library.items.DimmerItem)6 State (org.openhab.core.types.State)6 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 SwitchItem (org.openhab.core.library.items.SwitchItem)5 DecimalType (org.openhab.core.library.types.DecimalType)5 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)3 SappBindingConfigDimmerItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem)3 SappBindingConfigNumberItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem)3 SappBindingConfigRollershutterItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem)3 SappBindingConfigSwitchItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem)3 SappAddressDecimal (org.openhab.binding.sapp.internal.model.SappAddressDecimal)3 SappAddressDimmer (org.openhab.binding.sapp.internal.model.SappAddressDimmer)3 GroupItem (org.openhab.core.items.GroupItem)3 ColorItem (org.openhab.core.library.items.ColorItem)3