Package org.openhab.core.items

Examples of org.openhab.core.items.Item


    if(itemRegistry!=null) {
      for(Widget widget : widgets) {
        String itemName = widget.getItem();
        if(itemName!=null) {
          try {
            Item item = itemRegistry.getItem(itemName);
            if (item instanceof GenericItem) {
              final GenericItem gItem = (GenericItem) item;
              items.add(gItem);
            }
          } catch (ItemNotFoundException e) {
View Full Code Here


      logger.warn("Trying to create EntityManagerFactory but we don't have configuration yet!");
      return Collections.emptyList();
    }

    String itemName = filter.getItemName();
    Item item = getItemFromRegistry(itemName);
   
    String sortOrder;
    if(filter.getOrdering() == Ordering.ASCENDING) sortOrder = "ASC";
    else sortOrder = "DESC";

    boolean hasBeginDate = false;
    boolean hasEndDate = false;
    String queryString = "SELECT n FROM " + JpaPersistentItem.class.getSimpleName() + " n WHERE n.realName = :itemName";
    if(filter.getBeginDate() != null) {
      queryString += " AND n.timestamp >= :beginDate";
      hasBeginDate = true;
    }
    if(filter.getEndDate() != null) {
       queryString += " AND n.timestamp <= :endDate";
       hasEndDate = true;
    }
    queryString += " ORDER BY n.timestamp " + sortOrder;
   
    logger.debug("The query: " + queryString);

    EntityManager em = getEntityManagerFactory().createEntityManager();
    try {
      // In RESOURCE_LOCAL calls to EntityManager require a begin/commit
      em.getTransaction().begin();
     
      logger.debug("Creating query...");
      Query query = em.createQuery(queryString);
      query.setParameter("itemName", item.getName());
      if(hasBeginDate) query.setParameter("beginDate", filter.getBeginDate());
      if(hasEndDate) query.setParameter("endDate", filter.getEndDate());
     
      query.setFirstResult(filter.getPageNumber() * filter.getPageSize());
      query.setMaxResults(filter.getPageSize());
 
View Full Code Here

   * Retrieves the item for the given name from the item registry
   * @param itemName
   * @return
   */
  private Item getItemFromRegistry(String itemName) {
    Item item = null;
    try {
      if (itemRegistry != null) {
        item = itemRegistry.getItem(itemName);
      }
    } catch (ItemNotFoundException e1) {
View Full Code Here

  @Override
  public void receiveCommand(String itemName, Command command) { 
    // if the item is a group, we have to pass the command to it as it needs to pass the command to its members
    if(itemRegistry!=null) {
      try {
        Item item = itemRegistry.getItem(itemName);
        if (item instanceof GroupItem) {
          GroupItem groupItem = (GroupItem) item;
          groupItem.send(command);
        }
      } catch (ItemNotFoundException e) {
View Full Code Here

  }

  private ConsolFun getConsolidationFunction(String itemName) {
    if(itemRegistry!=null) {
      try {
        Item item = itemRegistry.getItem(itemName);
        return getConsolidationFunction(item);
      } catch (ItemNotFoundException e) {
        logger.debug("Could not find item '{}' in registry", itemName);
      }
    }
View Full Code Here

  }

  private State mapToState(double value, String itemName) {
    if(itemRegistry!=null) {
      try {
        Item item = itemRegistry.getItem(itemName);
        if(item instanceof SwitchItem && !(item instanceof DimmerItem)) {
          return value==0.0d ? OnOffType.OFF : OnOffType.ON;
        } else if(item instanceof ContactItem) {
          return value==0.0d ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
        }
View Full Code Here

        }
      }
      // add the item to all relevant groups
      for(String groupName : item.getGroupNames()) {
        try {
          Item groupItem = getItem(groupName);
          if(groupItem instanceof GroupItem) {
            ((GroupItem)groupItem).addMember(item);
          }
        } catch (ItemNotFoundException e) {
          // the group might not yet be registered, let's ignore this
View Full Code Here

    // Loop through all the items
    if (items != null) {
      String[] itemNames = items.split(",");
      for (String itemName : itemNames) {
        Item item = itemUIRegistry.getItem(itemName);
        addLine(graphDef, item, seriesCounter++);
      }
    }

    // Loop through all the groups and add each item from each group
    if (groups != null) {
      String[] groupNames = groups.split(",");
      for (String groupName : groupNames) {
        Item item = itemUIRegistry.getItem(groupName);
        if (item instanceof GroupItem) {
          GroupItem groupItem = (GroupItem) item;
          for (Item member : groupItem.getMembers()) {
            addLine(graphDef, member, seriesCounter++);
          }
        } else {
          throw new ItemNotFoundException("Item '" + item.getName() + "' defined in groups is not a group.");
        }
      }
    }

    // Write the chart as a PNG image
View Full Code Here

    if(publisher!=null) {
      if(registry!=null) {
        if(args.length>0) {
          String itemName = args[0];
          try {
            Item item = registry.getItemByPattern(itemName);
            if(args.length>1) {
              String stateName = args[1];
              State state = TypeParser.parseState(item.getAcceptedDataTypes(), stateName);
              if(state!=null) {
                publisher.postUpdate(item.getName(), state);
                console.println("Update has been sent successfully.");
              } else {
                console.println("Error: State '" + stateName +
                    "' is not valid for item '" + itemName + "'");
                console.print("Valid data types are: ( ");
                for(Class<? extends State> acceptedType : item.getAcceptedDataTypes()) {
                  console.print(acceptedType.getSimpleName() + " ");
                }
                console.println(")");
              }
            } else {
              console.printUsage(ConsoleInterpreter.getUpdateUsage());
            }
          } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
          } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for(Item item : e.getMatchingItems()) {
              console.print(item.getName() + " ");
            }
          }
        } else {
          console.printUsage(ConsoleInterpreter.getUpdateUsage());
        }
View Full Code Here

    if(publisher!=null) {
      if(registry!=null) {
        if(args.length>0) {
          String itemName = args[0];
          try {
            Item item = registry.getItemByPattern(itemName);
            if(args.length>1) {
              String commandName = args[1];
              Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
              if(command!=null) {
                publisher.sendCommand(itemName, command);
                console.println("Command has been sent successfully.");
              } else {
                console.println("Error: Command '" + commandName +
                    "' is not valid for item '" + itemName + "'");
                console.print("Valid command types are: ( ");
                for(Class<? extends Command> acceptedType : item.getAcceptedCommandTypes()) {
                  console.print(acceptedType.getSimpleName() + " ");
                }
                console.println(")");
              }
            } else {
              console.printUsage(ConsoleInterpreter.getCommandUsage());
            }
          } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
          } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for(Item item : e.getMatchingItems()) {
              console.print(item.getName() + " ");
            }
          }
        } else {
          console.printUsage(ConsoleInterpreter.getCommandUsage());
        }
View Full Code Here

TOP

Related Classes of org.openhab.core.items.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.