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

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

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

Item.getAcceptedDataTypes介绍

[英]This method provides a list of all data types that can be used to update the item state

Imagine e.g. a dimmer device: It's status could be 0%, 10%, 50%, 100%, but also OFF or ON and maybe UNDEFINED. So the accepted data types would be in this case PercentType, OnOffTypeand UnDefType
[中]此方法提供可用于更新项目状态的所有数据类型的列表
想象一下,例如一个调光器设备:它的状态可能是0%、10%、50%、100%,但也可能是关闭或打开,并且可能是未定义的。因此,在本例中,接受的数据类型将是PercentType、OnOffType和UndeType

代码示例

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

/**
 * The accepted data types of a group item is the same as of the underlying base item.
 * If none is defined, the intersection of all sets of accepted data types of all group
 * members is used instead.
 *
 * @return the accepted data types of this group item
 */
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends State>> getAcceptedDataTypes() {
  if (baseItem != null) {
    return baseItem.getAcceptedDataTypes();
  } else {
    List<Class<? extends State>> acceptedDataTypes = null;
    for (Item item : members) {
      if (acceptedDataTypes == null) {
        acceptedDataTypes = item.getAcceptedDataTypes();
      } else {
        acceptedDataTypes = ListUtils.intersection(acceptedDataTypes, item.getAcceptedDataTypes());
      }
    }
    return acceptedDataTypes == null ? ListUtils.EMPTY_LIST : acceptedDataTypes;
  }
}

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

private boolean isDataTypeSupported(Item item, Type type) {
  boolean result = false;
  for (Class<? extends State> supportedState : item.getAcceptedDataTypes()) {
    if (supportedState.isAssignableFrom(type.getClass())) {
      result = true;
    }
  }
  return result;
}

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

/**
 * The accepted data types of a group item is the same as of the underlying base item.
 * If none is defined, the intersection of all sets of accepted data types of all group
 * members is used instead.
 *
 * @return the accepted data types of this group item
 */
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends State>> getAcceptedDataTypes() {
  if (baseItem != null) {
    return baseItem.getAcceptedDataTypes();
  } else {
    List<Class<? extends State>> acceptedDataTypes = null;
    for (Item item : members) {
      if (acceptedDataTypes == null) {
        acceptedDataTypes = item.getAcceptedDataTypes();
      } else {
        acceptedDataTypes = ListUtils.intersection(acceptedDataTypes, item.getAcceptedDataTypes());
      }
    }
    return acceptedDataTypes == null ? ListUtils.EMPTY_LIST : acceptedDataTypes;
  }
}

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

/**
 * Gets a {@link ZWaveStateConverter} that is suitable for this {@link CommandClass} and the data types supported by
 * the {@link Item}
 * @param commandClass the {@link CommandClass} that sent the value.
 * @param item the {@link Item} that has to receive the State;
 * @return a converter object that converts between the value and the state;
 */
protected ZWaveStateConverter<?,?> getStateConverter(Item item, Object value) {
  if(item == null) {
    return null;
  }
  List<Class<? extends State>> list = new ArrayList<Class<? extends State>>(item.getAcceptedDataTypes());
  Collections.sort(list, new StateComparator());
  for (Class<? extends State> stateClass : list) {
    ZWaveStateConverter<?,?> result = stateConverters.get(stateClass);
    if (result == null || !result.getType().isInstance(value)) {
      continue;
    }
    
    return result;
  }
  
  return null;
}

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

/**
 * Procedure to validate selector string.
 * 
 * @param valueSelector
 *            selector string e.g. RawData, Command, Temperature
 * @return true if item is valid.
 * @throws IllegalArgumentException
 *             Not valid value selector.
 * @throws InvalidClassException
 *             Not valid class for value selector.
 */
public static boolean validateBinding(String valueSelector,
    Item item) throws IllegalArgumentException,
    InvalidClassException {
  for (OceanicValueSelector c : OceanicValueSelector.values()) {
    if (c.text.equals(valueSelector) && item !=null) {
      if (item.getAcceptedDataTypes().contains(c.getTypeClass()))
        return true;
      else
        throw new InvalidClassException(
            "Not valid class for value selector");
    }
  }
  throw new IllegalArgumentException("Not valid value selector");
}

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

List<Class<? extends State>> itemTypes = new ArrayList<Class<? extends State>>(item.getAcceptedDataTypes());
List<Class<? extends State>> matchingTypes = converters.getMatchingStates(protocolValue);
  for (Class<? extends State> matchingType : matchingTypes) {

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

if (this.connectedSince == null) {
  return UnDefType.NULL;
} else if (item.getAcceptedDataTypes().contains(DateTimeType.class)) {
  return new DateTimeType(this.connectedSince);
if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
  return new DecimalType(this.connectionFailures);

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

if (item.getAcceptedDataTypes().contains(DateTimeType.class)) {
  return new DateTimeType(statusEvent.getIntegraTime());
} else {

相关文章