Package org.openhab.core.items

Examples of org.openhab.core.items.Item


  }

  @Test
  public void getLabel_labelFromUIProvider() throws ItemNotFoundException {
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    ItemUIProvider provider = mock(ItemUIProvider.class);
    uiRegistry.addItemUIProvider(provider);
    when(provider.getLabel(anyString())).thenReturn("ProviderLabel");
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
View Full Code Here


  @Test
  public void getLabel_labelForUndefinedStringItemState() throws ItemNotFoundException {
    String testLabel = "Label [%s]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(UnDefType.UNDEF);
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [-]", label);
  }
View Full Code Here

  @Test
  public void getLabel_labelForUndefinedIntegerItemState() throws ItemNotFoundException {
    String testLabel = "Label [%d]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(UnDefType.UNDEF);
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [-]", label);
  }
View Full Code Here

  @Test
  public void getLabel_labelForUndefinedDecimalItemState() throws ItemNotFoundException {
    String testLabel = "Label [%.2f]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(UnDefType.UNDEF);
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [-]", label);
  }
View Full Code Here

  @Test
  public void getLabel_labelForUndefinedDateItemState() throws ItemNotFoundException {
    String testLabel = "Label [%1$td.%1$tm.%1$tY]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(UnDefType.UNDEF);
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [-.-.-]", label);
  }
View Full Code Here

  @Test
  public void getLabel_itemNotFound() throws ItemNotFoundException {
    String testLabel = "Label [%s]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(w.eClass()).thenReturn(SitemapFactory.eINSTANCE.createText().eClass());
    when(registry.getItem("Item")).thenThrow(new ItemNotFoundException("Item"));
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [-]", label);
  }
View Full Code Here

 
  @Test
  public void getLabel_labelWithFunctionValue() throws ItemNotFoundException {
    String testLabel = "Label [MAP(de.map):%s]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [State]", label);
  }
View Full Code Here

 
  @Test
  public void getLabel_groupLabelWithValue() throws ItemNotFoundException {
    String testLabel = "Label [%d]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(OnOffType.ON);
    when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(5));
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [5]", label);
  }
View Full Code Here

   */
  public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Switch s = (Switch) w;
   
    String snippetName = null;
    Item item;
    try {
      item = itemUIRegistry.getItem(w.getItem());
      if(s.getMappings().size()==0) {
        if(item instanceof RollershutterItem) {
          snippetName = "rollerblind";
View Full Code Here

      String itemName = key.toString();
     
      if(!itemName.startsWith("__")) { // all additional webapp params start with "__" and should be ignored
        String commandName = req.getParameter(itemName);
        try {
          Item item = itemRegistry.getItem(itemName);
         
          // we need a special treatment for the "TOGGLE" command of switches;
          // this is no command officially supported and must be translated
          // into real commands by the webapp.
          if ((item instanceof SwitchItem || item instanceof GroupItem) && commandName.equals("TOGGLE")) {
            commandName = OnOffType.ON.equals(item.getStateAs(OnOffType.class)) ? "OFF" : "ON";
          }
         
          Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
          if(command!=null) {
            eventPublisher.sendCommand(itemName, command);
          } else {
            logger.warn("Received unknown command '{}' for item '{}'", commandName, itemName);           
          }
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.