org.openhab.core.items.Item.getStateAs()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(67)

本文整理了Java中org.openhab.core.items.Item.getStateAs()方法的一些代码示例,展示了Item.getStateAs()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getStateAs()方法的具体详情如下:
包路径:org.openhab.core.items.Item
类名称:Item
方法名:getStateAs

Item.getStateAs介绍

[英]returns the current state of the item as a specific type
[中]以特定类型返回项的当前状态

代码示例

代码示例来源:origin: openhab/openhab1-addons

private int count(List<Item> items, State state) {
    int count = 0;
    if (items != null && state != null) {
      for (Item item : items) {
        if (state.equals(item.getStateAs(state.getClass()))) {
          count++;
        }
      }
    }
    return count;
  }
}

代码示例来源:origin: openhab/openhab1-addons

private int count(List<Item> items, State state) {
    int count = 0;
    if (items != null && state != null) {
      for (Item item : items) {
        if (state.equals(item.getStateAs(state.getClass()))) {
          count++;
        }
      }
    }
    return count;
  }
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null) {
    for (Item item : items) {
      if (activeState.equals(item.getStateAs(activeState.getClass()))) {
        return activeState;
      }
    }
  }
  return passiveState;
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    for (Item item : items) {
      if (!activeState.equals(item.getStateAs(activeState.getClass()))) {
        return passiveState;
      }
    }
    return activeState;
  } else {
    // if we do not have any items, we return the passive state
    return passiveState;
  }
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  BigDecimal sum = BigDecimal.ZERO;
  int count = 0;
  if (items != null) {
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        sum = sum.add(itemState.toBigDecimal());
        count++;
      }
    }
  }
  if (count > 0) {
    return new DecimalType(sum.divide(new BigDecimal(count), RoundingMode.HALF_UP));
  } else {
    return UnDefType.UNDEF;
  }
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  BigDecimal sum = BigDecimal.ZERO;
  if (items != null) {
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        sum = sum.add(itemState.toBigDecimal());
      }
    }
  }
  return new DecimalType(sum);
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    BigDecimal min = null;
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        if (min == null || min.compareTo(itemState.toBigDecimal()) > 0) {
          min = itemState.toBigDecimal();
        }
      }
    }
    if (min != null) {
      return new DecimalType(min);
    }
  }
  return UnDefType.UNDEF;
}

代码示例来源:origin: openhab/openhab1-addons

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    BigDecimal max = null;
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        if (max == null || max.compareTo(itemState.toBigDecimal()) < 0) {
          max = itemState.toBigDecimal();
        }
      }
    }
    if (max != null) {
      return new DecimalType(max);
    }
  }
  return UnDefType.UNDEF;
}

代码示例来源:origin: openhab/openhab-core

private int count(List<Item> items, State state) {
    int count = 0;
    if (items != null && state != null) {
      for (Item item : items) {
        if (state.equals(item.getStateAs(state.getClass()))) {
          count++;
        }
      }
    }
    return count;
  }
}

代码示例来源:origin: openhab/openhab-core

private int count(List<Item> items, State state) {
    int count = 0;
    if (items != null && state != null) {
      for (Item item : items) {
        if (state.equals(item.getStateAs(state.getClass()))) {
          count++;
        }
      }
    }
    return count;
  }
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null) {
    for (Item item : items) {
      if (activeState.equals(item.getStateAs(activeState.getClass()))) {
        return activeState;
      }
    }
  }
  return passiveState;
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    for (Item item : items) {
      if (!activeState.equals(item.getStateAs(activeState.getClass()))) {
        return passiveState;
      }
    }
    return activeState;
  } else {
    // if we do not have any items, we return the passive state
    return passiveState;
  }
}

代码示例来源:origin: org.openhab.binding/org.openhab.binding.zwave

/**
 * {@inheritDoc}
 */
@Override
protected Integer convert(Item item, IncreaseDecreaseType command) {
  int value = ((PercentType)item.getStateAs(PercentType.class)).intValue();
  
  switch (command) {
    case DECREASE:
      if (value >= 0x63)
        value = ((((int)(0x63 / DIMMER_STEP_SIZE)) + 1) * DIMMER_STEP_SIZE) - DIMMER_STEP_SIZE; 
      else if (value > 0x00)
        value -= DIMMER_STEP_SIZE;
      else
        value = 0x00;
      break;
    case INCREASE:
      value += DIMMER_STEP_SIZE;
      
      if (value >= 0x63)
        value = 0x63;
      break;
  }
  
  return value;
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  BigDecimal sum = BigDecimal.ZERO;
  int count = 0;
  if (items != null) {
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        sum = sum.add(itemState.toBigDecimal());
        count++;
      }
    }
  }
  if (count > 0) {
    return new DecimalType(sum.divide(new BigDecimal(count), RoundingMode.HALF_UP));
  } else {
    return UnDefType.UNDEF;
  }
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  BigDecimal sum = BigDecimal.ZERO;
  if (items != null) {
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        sum = sum.add(itemState.toBigDecimal());
      }
    }
  }
  return new DecimalType(sum);
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    BigDecimal min = null;
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        if (min == null || min.compareTo(itemState.toBigDecimal()) > 0) {
          min = itemState.toBigDecimal();
        }
      }
    }
    if (min != null) {
      return new DecimalType(min);
    }
  }
  return UnDefType.UNDEF;
}

代码示例来源:origin: openhab/openhab-core

/**
 * @{inheritDoc
 */
@Override
public State calculate(List<Item> items) {
  if (items != null && items.size() > 0) {
    BigDecimal max = null;
    for (Item item : items) {
      DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
      if (itemState != null) {
        if (max == null || max.compareTo(itemState.toBigDecimal()) < 0) {
          max = itemState.toBigDecimal();
        }
      }
    }
    if (max != null) {
      return new DecimalType(max);
    }
  }
  return UnDefType.UNDEF;
}

相关文章