Package org.openhab.core.items

Examples of org.openhab.core.items.Item


    ItemRegistry registry = (ItemRegistry) ConsoleActivator.itemRegistryTracker.getService();
    if(registry!=null) {
      if(args.length>0) {
        String itemName = args[0];
        try {
          Item item = registry.getItemByPattern(itemName);
          console.println(item.getState().toString());
        } 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.getStatusUsage());
      }
View Full Code Here


      if(word.startsWith("%") && word.endsWith("%") && word.length()>2) {
        String itemName = word.substring(1, word.length()-1);
        ItemRegistry registry = (ItemRegistry) ConsoleActivator.itemRegistryTracker.getService();
        if(registry!=null) {
          try {
            Item item = registry.getItemByPattern(itemName);
            msg.append(item.getState().toString());
          } 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.println("Sorry, no item registry service available!");
        }       
View Full Code Here

      }
      if (itemCfg instanceof GroupConfig) {
        GroupConfig groupItemCfg = (GroupConfig) itemCfg;
        String groupName = groupItemCfg.getGroup();
        try {
          Item gItem = itemRegistry.getItem(groupName);
          if (gItem instanceof GroupItem) {
            GroupItem groupItem = (GroupItem) gItem;
            if(groupItem.getAllMembers().contains(item)) {
              return true;
            }
View Full Code Here

    Set<Item> items = new HashSet<Item>();
    for(EObject itemCfg : config.getItems()) {
      if (itemCfg instanceof ItemConfig) {
        ItemConfig singleItemConfig = (ItemConfig) itemCfg;
        try {
          Item item = itemRegistry.getItem(singleItemConfig.getItem());
          items.add(item);
        } catch (ItemNotFoundException e) {
          logger.debug("Item '{}' does not exist.", singleItemConfig.getItem());
        }
      }
      if (itemCfg instanceof GroupConfig) {
        GroupConfig groupItemCfg = (GroupConfig) itemCfg;
        String groupName = groupItemCfg.getGroup();
        try {
          Item gItem = itemRegistry.getItem(groupName);
          if (gItem instanceof GroupItem) {
            GroupItem groupItem = (GroupItem) gItem;
            items.addAll(groupItem.getAllMembers());
          }
        } catch (ItemNotFoundException e) {
View Full Code Here

    if (!isConnected())
      return Collections.emptyList();

    String name = filter.getItemName();
    Item item = getItem(name);

    List<HistoricItem> items = new ArrayList<HistoricItem>();
    DBObject query = new BasicDBObject();
    if (filter.getItemName() != null) {
      query.put(FIELD_ITEM, filter.getItemName());
View Full Code Here

      return null;
    }
  }

  private Item getItem(String itemName) {
    Item item = null;
    try {
      if (itemRegistry != null) {
        item = itemRegistry.getItem(itemName);
      }
    } catch (ItemNotFoundException e1) {
View Full Code Here

    public SuspendResponse<String> getPlainItemState(
        @PathParam("itemname") String itemname,
        @HeaderParam(HeaderConfig.X_ATMOSPHERE_TRANSPORT) String atmosphereTransport,
        @Context AtmosphereResource resource) {
      if(atmosphereTransport==null || atmosphereTransport.isEmpty()) {
        Item item = getItem(itemname);
        if(item!=null) {
        logger.debug("Received HTTP GET request at '{}'.", uriInfo.getPath());
        throw new WebApplicationException(Response.ok(item.getState().toString()).build());
        } else {
          logger.info("Received HTTP GET request at '{}' for the unknown item '{}'.", uriInfo.getPath(), itemname);
          throw new WebApplicationException(404);
        }
    }
View Full Code Here

    }
   
    @PUT @Path("/{itemname: [a-zA-Z_0-9]*}/state")
  @Consumes(MediaType.TEXT_PLAIN
  public Response putItemState(@PathParam("itemname") String itemname, String value) {
      Item item = getItem(itemname);
      if(item!=null) {
        State state = TypeParser.parseState(item.getAcceptedDataTypes(), value);
        if(state!=null) {
          logger.debug("Received HTTP PUT request at '{}' with value '{}'.", uriInfo.getPath(), value);
          RESTApplication.getEventPublisher().postUpdate(itemname, state);
          return Response.ok().build();
        } else {
View Full Code Here

  @Context UriInfo localUriInfo;
    @POST @Path("/{itemname: [a-zA-Z_0-9]*}")
  @Consumes(MediaType.TEXT_PLAIN
  public Response postItemCommand(@PathParam("itemname") String itemname, String value) {
      Item item = getItem(itemname);
      Command command = null;
      if(item!=null) {
        // support for TOGGLE, see https://code.google.com/p/openhab/issues/detail?id=336
        if("toggle".equalsIgnoreCase(value) &&
            (item instanceof SwitchItem ||
             item instanceof RollershutterItem)) {
          if(OnOffType.ON.equals(item.getStateAs(OnOffType.class))) command = OnOffType.OFF;
          if(OnOffType.OFF.equals(item.getStateAs(OnOffType.class))) command = OnOffType.ON;
          if(UpDownType.UP.equals(item.getStateAs(UpDownType.class))) command = UpDownType.DOWN;
          if(UpDownType.DOWN.equals(item.getStateAs(UpDownType.class))) command = UpDownType.UP;
        } else {
          command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), value);
        }
        if(command!=null) {
          logger.debug("Received HTTP POST request at '{}' with value '{}'.", uriInfo.getPath(), value);
          RESTApplication.getEventPublisher().postCommand(itemname, command);
          return Response.created(localUriInfo.getAbsolutePathBuilder().path("state").build()).build();
View Full Code Here

    }
  }

  private void registerChangeListenerOnItem(
      StateChangeListener stateChangeListener, String itemName) {
    Item item = ItemResource.getItem(itemName);
    if (item instanceof GenericItem) {
      GenericItem genericItem = (GenericItem) item;
      genericItem.addStateChangeListener(stateChangeListener);
     
    }
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.