Examples of DecimalType


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

   */
  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

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

   */
  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

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

   */
  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

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

   * @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

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

   * @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

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

    @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

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

          return hsbState.getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON;         
        }
      } else if(typeClass==DecimalType.class) {
        if(state instanceof HSBType) {
          HSBType hsbState = (HSBType) state;
          return new DecimalType(hsbState.getBrightness().toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
        }
      }
      return super.getStateAs(typeClass);
    }
View Full Code Here

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

      } else {
        return UnDefType.UNDEF;
      }
    } else if(typeClass==DecimalType.class) {
      if(state instanceof PercentType) {
        return new DecimalType(((PercentType) state).toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
      }
    }
    return super.getStateAs(typeClass);
  }
View Full Code Here

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

  }
 
  @Override
  public State getStateAs(Class<? extends State> typeClass) {
    if(typeClass==DecimalType.class) {
      return state==OnOffType.ON ? new DecimalType(1) : DecimalType.ZERO;
    } else if(typeClass==PercentType.class) {
      return state==OnOffType.ON ? PercentType.HUNDRED : PercentType.ZERO;
    } else {
      return super.getStateAs(typeClass);
    }
View Full Code Here

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

   * {@inheritDoc}
   */
  @Override
  public State getStateAs(Class<? extends State> typeClass) {
    if(typeClass==DecimalType.class) {
      return state==OpenClosedType.OPEN ? new DecimalType(1) : DecimalType.ZERO;
    } else if(typeClass==PercentType.class) {
      return state==OpenClosedType.OPEN ? PercentType.HUNDRED : PercentType.ZERO;
    } else {
      return super.getStateAs(typeClass);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.