Package org.openhab.core.types

Examples of org.openhab.core.types.State


    // set the default send-update frequency to 200ms 
    String frequency = cp.getFrequency()==0 ? "200" : Integer.toString(cp.getFrequency());
   
    // get RGB hex value
    State state = itemUIRegistry.getState(cp);
    String hexValue = "#ffffff";
    if(state instanceof HSBType) {
      HSBType hsbState = (HSBType) state;
      Color color = hsbState.toColor();
      hexValue = "#" + Integer.toHexString(color.getRGB()).substring(2);
View Full Code Here


   * {@inheritDoc}
   */
  public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Setpoint sp = (Setpoint) w;

    State state = itemUIRegistry.getState(w);
    String newLowerState = state.toString();
    String newHigherState = state.toString();

    // set defaults for min, max and step
    BigDecimal step = sp.getStep();
    if(step==null) {
      step = BigDecimal.ONE;
    }
    BigDecimal minValue = sp.getMinValue();
    if(minValue==null) {
      minValue = BigDecimal.ZERO;
    }
    BigDecimal maxValue = sp.getMaxValue();
    if(maxValue==null) {
      maxValue = BigDecimal.valueOf(100);
    }

    // if the current state is a valid value, we calculate the up and down step values
    if(state instanceof DecimalType) {
      DecimalType actState = (DecimalType) state;
      BigDecimal newLower = actState.toBigDecimal().subtract(step);
      BigDecimal newHigher = actState.toBigDecimal().add(step);
      if(newLower.compareTo(minValue) < 0) {
        newLower = minValue;
      }
      if(newHigher.compareTo(maxValue) > 0) {
        newHigher = maxValue;
      }
      newLowerState = newLower.toString();
      newHigherState = newHigher.toString();
    }
   
    String snippetName = "setpoint";
    String snippet = getSnippet(snippetName);

    snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
    snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(w)));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%state%", state.toString());
    snippet = StringUtils.replace(snippet, "%newlowerstate%", newLowerState);
    snippet = StringUtils.replace(snippet, "%newhigherstate%", newHigherState);
    snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
    snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString());
View Full Code Here

    snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(w)));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
   
    State state = itemUIRegistry.getState(w);
   
    if(s.getMappings().size()==0) {
      if(state instanceof PercentType) {
        state = ((PercentType) state).intValue() > 0 ? OnOffType.ON : OnOffType.OFF;
      }
      if(state.equals(OnOffType.ON)) {
        snippet = snippet.replaceAll("%checked%", "checked=true");
      } else {
        snippet = snippet.replaceAll("%checked%", "");
      }
    } else {
      StringBuilder buttons = new StringBuilder();
      for(Mapping mapping : s.getMappings()) {
        String button = getSnippet("button");
        button = StringUtils.replace(button, "%item%",w.getItem());
        button = StringUtils.replace(button, "%cmd%", mapping.getCmd());
        button = StringUtils.replace(button, "%label%", mapping.getLabel());
        if(s.getMappings().size()>1 && state.toString().equals(mapping.getCmd())) {
          button = StringUtils.replace(button, "%type%", "Warn"); // button with red color
        } else {
          button = StringUtils.replace(button, "%type%", "Action"); // button with blue color
        }
        buttons.insert(0, button);
View Full Code Here

   */
  public static List<HistoricItem> fromResultList(List<JpaPersistentItem> jpaQueryResult, Item item) {
    List<HistoricItem> ret = new ArrayList<HistoricItem>();
    for(JpaPersistentItem i : jpaQueryResult) {
     
      State state;
      if (item instanceof NumberItem) {
        state = new DecimalType(Double.valueOf(i.getValue()));
      } else if (item instanceof DimmerItem) {
        state = new PercentType(Integer.valueOf(i.getValue()));
      } else if (item instanceof SwitchItem) {
View Full Code Here

          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 +
View Full Code Here

    items.add(new TestItem("TestItem3", OpenClosedType.OPEN));
    items.add(new TestItem("TestItem4", OpenClosedType.CLOSED));
    items.add(new TestItem("TestItem5", UnDefType.UNDEF));
   
    function = new ArithmeticGroupFunction.Or(OpenClosedType.OPEN, OpenClosedType.CLOSED);
    State state = function.calculate(items);
   
    Assert.assertEquals(OpenClosedType.OPEN, state);
  }
View Full Code Here

    items.add(new TestItem("TestItem3", OpenClosedType.CLOSED));
    items.add(new TestItem("TestItem4", OpenClosedType.CLOSED));
    items.add(new TestItem("TestItem5", UnDefType.UNDEF));
   
    function = new ArithmeticGroupFunction.Or(OpenClosedType.OPEN, OpenClosedType.CLOSED);
    State state = function.calculate(items);
   
    Assert.assertEquals(OpenClosedType.CLOSED, state);
  }
View Full Code Here

  @Test
  public void testOrFunction_justsOneItem() {
    items.add(new TestItem("TestItem1", UnDefType.UNDEF));
   
    function = new ArithmeticGroupFunction.Or(OpenClosedType.OPEN, OpenClosedType.CLOSED);
    State state = function.calculate(items);
   
    Assert.assertEquals(OpenClosedType.CLOSED, state);
  }
View Full Code Here

    items.add(dimmer2);
    items.add(switch1);
    items.add(switch2);
   
    function = new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF);
    State state = function.calculate(items);
    State decimalState = function.getStateAs(items, DecimalType.class);
   
    Assert.assertEquals(OnOffType.ON, state);
    Assert.assertEquals(new DecimalType("2"), decimalState);
  }
View Full Code Here

    items.add(new TestItem("TestItem3", OpenClosedType.OPEN));
    items.add(new TestItem("TestItem4", OpenClosedType.CLOSED));
    items.add(new TestItem("TestItem5", UnDefType.UNDEF));
   
    function = new ArithmeticGroupFunction.NOr(OpenClosedType.OPEN, OpenClosedType.CLOSED);
    State state = function.calculate(items);
   
    Assert.assertEquals(OpenClosedType.CLOSED, state);
  }
View Full Code Here

TOP

Related Classes of org.openhab.core.types.State

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.