Package org.openhab.core.library.types

Examples of org.openhab.core.library.types.DecimalType


    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


    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) {
        state = OnOffType.valueOf(i.getValue());
      } else if (item instanceof ContactItem) {
View Full Code Here

      }
      try {
        Sample sample = db.createSample();
              sample.setTime(now);
             
              DecimalType state = (DecimalType) item.getStateAs(DecimalType.class);
              if (state!=null) {
                    double value = state.toBigDecimal().doubleValue();
                    sample.setValue(DATASOURCE_STATE, value);
                    sample.update();
                    logger.debug("Stored '{}' with state '{}' in rrd4j database", name, item.getState());
              }
      } catch (IllegalArgumentException e) {
View Full Code Here

      } catch (ItemNotFoundException e) {
        logger.debug("Could not find item '{}' in registry", itemName);
      }
    }
    // just return a DecimalType as a fallback
    return new DecimalType(value);
  }
View Full Code Here

   */
  static public HistoricItem maximumSince(final Item item, AbstractInstant timestamp, String serviceName) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
    Iterator<HistoricItem> it = result.iterator();
    HistoricItem maximumHistoricItem = null;
    DecimalType maximum = (DecimalType) item.getStateAs(DecimalType.class);
    while(it.hasNext()) {
      HistoricItem historicItem = it.next();
      State state = historicItem.getState();
      if (state instanceof DecimalType) {
        DecimalType value = (DecimalType) state;
        if(maximum==null || value.compareTo(maximum)>0) {
          maximum = value;
          maximumHistoricItem = historicItem;
        }
      }
    }
    if(maximumHistoricItem==null && maximum!=null) {
      // the maximum state is the current one, so construct a historic item on the fly
      final DecimalType state = maximum;
      return new HistoricItem() {
       
        public Date getTimestamp() {
          return Calendar.getInstance().getTime();
        }
View Full Code Here

   */
  static public HistoricItem minimumSince(final Item item, AbstractInstant timestamp, String serviceName) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
    Iterator<HistoricItem> it = result.iterator();
    HistoricItem minimumHistoricItem = null;
    DecimalType minimum = (DecimalType) item.getStateAs(DecimalType.class);
    while(it.hasNext()) {
      HistoricItem historicItem = it.next();
      State state = historicItem.getState();
      if (state instanceof DecimalType) {
        DecimalType value = (DecimalType) state;
        if(minimum==null || value.compareTo(minimum)<0) {
          minimum = value;
          minimumHistoricItem = historicItem;
        }
      }
    }
    if(minimumHistoricItem==null && minimum!=null) {
      // the minimal state is the current one, so construct a historic item on the fly
      final DecimalType state = minimum;
      return new HistoricItem() {
       
        public Date getTimestamp() {
          return Calendar.getInstance().getTime();
        }
View Full Code Here

   */
  static public DecimalType averageSince(Item item, AbstractInstant timestamp, String serviceName) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
    Iterator<HistoricItem> it = result.iterator();
   
    DecimalType value = (DecimalType) item.getStateAs(DecimalType.class);
    if (value == null) {
      value = DecimalType.ZERO;
    }
   
    double average = value.doubleValue();
    int quantity = 1;
    while(it.hasNext()) {
      State state = it.next().getState();
      if (state instanceof DecimalType) {
        value = (DecimalType) state;
        average += value.doubleValue();
        quantity++;
      }
    }
    average /= quantity;
   
    return new DecimalType(average);
  }
View Full Code Here

   * @param serviceName the name of the {@link PersistenceService} to use
   * @return the difference between now and then, null if not calculable
   */
  static public DecimalType deltaSince(Item item, AbstractInstant timestamp, String serviceName) {
    HistoricItem itemThen = historicState(item, timestamp);
    DecimalType valueThen = (DecimalType) itemThen.getState();
    DecimalType valueNow = (DecimalType) item.getStateAs(DecimalType.class);
    DecimalType result = null;
    if (( valueThen != null) && ( valueNow != null)) {
      result = new DecimalType(valueNow.doubleValue() - valueThen.doubleValue());
    };
    return result;
   }
View Full Code Here

   * @return the evolution rate in percent (positive and negative) between now and then,
   *       null if not calculable
   */
  static public DecimalType evolutionRate(Item item, AbstractInstant timestamp, String serviceName) {
    HistoricItem itemThen = historicState(item, timestamp);
    DecimalType valueThen = (DecimalType) itemThen.getState();
    DecimalType valueNow = (DecimalType) item.getStateAs(DecimalType.class);
    DecimalType result = null;
    if (( valueThen != null) && ( valueNow != null)) {
      result = new DecimalType(100 * (valueNow.doubleValue() - valueThen.doubleValue()) / valueThen.doubleValue());
    };
    return result;
   }
View Full Code Here

    @Override
    public void setState(State state) {
      State currentState = this.state;
     
      if(currentState instanceof HSBType) {
        DecimalType hue = ((HSBType) currentState).getHue();
        PercentType saturation = ((HSBType) currentState).getSaturation();
        // we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed
        if(state==OnOffType.OFF) {
          super.setState(new HSBType(hue, saturation, PercentType.ZERO));
        } else if(state==OnOffType.ON) {
View Full Code Here

TOP

Related Classes of org.openhab.core.library.types.DecimalType

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.