org.eclipse.smarthome.core.items.Item.getState()方法的使用及代码示例

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

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

Item.getState介绍

[英]returns the current state of the item
[中]返回项的当前状态

代码示例

代码示例来源:origin: eclipse/smarthome

@Override
public State calculate(Set<Item> items) {
  if (items.size() > 0) {
    Iterator<Item> it = items.iterator();
    State state = it.next().getState();
    while (it.hasNext()) {
      if (!state.equals(it.next().getState())) {
        return UnDefType.UNDEF;
      }
    }
    return state;
  } else {
    return UnDefType.UNDEF;
  }
}

代码示例来源:origin: eclipse/smarthome

@Override
public State calculate(Set<Item> items) {
  int count = 0;
  if (items != null) {
    for (Item item : items) {
      Matcher matcher = pattern.matcher(item.getState().toString());
      if (matcher.matches()) {
        count++;
      }
    }
  }
  return new DecimalType(count);
}

代码示例来源:origin: eclipse/smarthome

@Override
public void setState(State state) {
  State oldState = this.state;
  if (baseItem != null && baseItem instanceof GenericItem) {
    ((GenericItem) baseItem).setState(state);
    this.state = baseItem.getState();
  } else {
    this.state = state;
  }
  notifyListeners(oldState, state);
}

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

@Override
public State calculate(Set<Item> items) {
  if (items.size() > 0) {
    Iterator<Item> it = items.iterator();
    State state = it.next().getState();
    while (it.hasNext()) {
      if (!state.equals(it.next().getState())) {
        return UnDefType.UNDEF;
      }
    }
    return state;
  } else {
    return UnDefType.UNDEF;
  }
}

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

public void keepCurrentState(Item item) {
  scheduler.schedule(() -> {
    constructAndSendEvents(item, item.getState());
  }, REVERT_INTERVAL, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: org.eclipse.smarthome.ui/org.eclipse.smarthome.ui

@Override
public State getItemState(String itemName) {
  try {
    Item item = itemRegistry.getItem(itemName);
    return item.getState();
  } catch (ItemNotFoundException e) {
    return null;
  }
}

代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope

@Override
public State get(Object key) {
  final Item item = itemRegistry.get((String) key);
  if (item == null) {
    return null;
  }
  return item.getState();
}

代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope

@Override
public Collection<State> values() {
  Set<State> values = new HashSet<>();
  for (Item item : itemRegistry.getAll()) {
    values.add(item.getState());
  }
  return values;
}

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

@Override
public State getItemState(String itemName) {
  try {
    Item item = itemRegistry.getItem(itemName);
    return item.getState();
  } catch (ItemNotFoundException e) {
    return null;
  }
}

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

@Override
public State get(Object key) {
  final Item item = itemRegistry.get((String) key);
  if (item == null) {
    return null;
  }
  return item.getState();
}

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

@Override
public Collection<State> values() {
  Set<State> values = new HashSet<>();
  for (Item item : itemRegistry.getAll()) {
    values.add(item.getState());
  }
  return values;
}

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

@Override
public State calculate(Set<Item> items) {
  int count = 0;
  if (items != null) {
    for (Item item : items) {
      Matcher matcher = pattern.matcher(item.getState().toString());
      if (matcher.matches()) {
        count++;
      }
    }
  }
  return new DecimalType(count);
}

代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope

/**
 * Stores the current states for a list of items in a map.
 * A group item is not itself put into the map, but instead all its members.
 *
 * @param items the items for which the state should be stored
 * @return the map of items with their states
 */
public Map<Item, State> storeStates(Item... items) {
  Map<Item, State> statesMap = new HashMap<>();
  if (items != null) {
    for (Item item : items) {
      if (item instanceof GroupItem) {
        GroupItem groupItem = (GroupItem) item;
        for (Item member : groupItem.getAllMembers()) {
          statesMap.put(member, member.getState());
        }
      } else {
        statesMap.put(item, item.getState());
      }
    }
  }
  return statesMap;
}

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

/**
 * Stores the current states for a list of items in a map.
 * A group item is not itself put into the map, but instead all its members.
 *
 * @param items the items for which the state should be stored
 * @return the map of items with their states
 */
public Map<Item, State> storeStates(Item... items) {
  Map<Item, State> statesMap = new HashMap<>();
  if (items != null) {
    for (Item item : items) {
      if (item instanceof GroupItem) {
        GroupItem groupItem = (GroupItem) item;
        for (Item member : groupItem.getAllMembers()) {
          statesMap.put(member, member.getState());
        }
      } else {
        statesMap.put(item, item.getState());
      }
    }
  }
  return statesMap;
}

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

/**
 * Stores the current states for a list of items in a map.
 * A group item is not itself put into the map, but instead all its members.
 *
 * @param items the items for which the state should be stored
 * @return the map of items with their states
 */
static public Map<Item, State> storeStates(Item... items) {
  Map<Item, State> statesMap = new HashMap<>();
  if (items != null) {
    for (Item item : items) {
      if (item instanceof GroupItem) {
        GroupItem groupItem = (GroupItem) item;
        for (Item member : groupItem.getAllMembers()) {
          statesMap.put(member, member.getState());
        }
      } else {
        statesMap.put(item, item.getState());
      }
    }
  }
  return statesMap;
}

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

@Override
public Set<java.util.Map.Entry<String, State>> entrySet() {
  Set<Map.Entry<String, State>> entries = new HashSet<Map.Entry<String, State>>();
  for (Item item : itemRegistry.getAll()) {
    entries.add(new AbstractMap.SimpleEntry<>(item.getName(), item.getState()));
  }
  return entries;
}

代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope

@Override
public Set<java.util.Map.Entry<String, State>> entrySet() {
  Set<Map.Entry<String, State>> entries = new HashSet<Map.Entry<String, State>>();
  for (Item item : itemRegistry.getAll()) {
    entries.add(new AbstractMap.SimpleEntry<>(item.getName(), item.getState()));
  }
  return entries;
}

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

@Override
public void setState(State state) {
  State oldState = this.state;
  if (baseItem != null && baseItem instanceof GenericItem) {
    ((GenericItem) baseItem).setState(state);
    this.state = baseItem.getState();
  } else {
    this.state = state;
  }
  notifyListeners(oldState, state);
}

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

@Override
public State getState(Widget w) {
  String itemName = w.getItem();
  if (itemName != null) {
    try {
      Item item = getItem(itemName);
      return convertState(w, item, item.getState());
    } catch (ItemNotFoundException e) {
      logger.error("Cannot retrieve item '{}' for widget {}",
          new Object[] { itemName, w.eClass().getInstanceTypeName() });
    }
  }
  return UnDefType.UNDEF;
}

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

@Override
public void execute(String[] args, Console console) {
  if (args.length > 0) {
    String itemName = args[0];
    try {
      Item item = this.itemRegistry.getItemByPattern(itemName);
      console.println(item.getState().toString());
    } catch (ItemNotFoundException e) {
      console.println("Error: Item '" + itemName + "' does not exist.");
    } catch (ItemNotUniqueException e) {
      console.print("Error: Multiple items match this pattern: ");
      for (Item item : e.getMatchingItems()) {
        console.print(item.getName() + " ");
      }
    }
  } else {
    printUsage(console);
  }
}

相关文章