本文整理了Java中org.eclipse.smarthome.core.items.Item.getStateAs()
方法的一些代码示例,展示了Item.getStateAs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getStateAs()
方法的具体详情如下:
包路径:org.eclipse.smarthome.core.items.Item
类名称:Item
方法名:getStateAs
[英]returns the current state of the item as a specific type
[中]以特定类型返回项的当前状态
代码示例来源:origin: eclipse/smarthome
private int count(Set<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: eclipse/smarthome
private int count(Set<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: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
if (items != null) {
for (Item item : items) {
if (activeState.equals(item.getStateAs(activeState.getClass()))) {
return activeState;
}
}
}
return passiveState;
}
代码示例来源:origin: eclipse/smarthome
@Override
public State calculate(Set<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: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
BigDecimal sum = BigDecimal.ZERO;
if (items != null) {
for (Item item : items) {
DecimalType itemState = item.getStateAs(DecimalType.class);
if (itemState != null) {
sum = sum.add(itemState.toBigDecimal());
}
}
}
return new DecimalType(sum);
}
代码示例来源:origin: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
BigDecimal sum = BigDecimal.ZERO;
int count = 0;
if (items != null) {
for (Item item : items) {
DecimalType itemState = item.getStateAs(DecimalType.class);
if (itemState != null) {
sum = sum.add(itemState.toBigDecimal());
count++;
}
}
}
if (count > 0) {
return new DecimalType(sum.divide(BigDecimal.valueOf(count), RoundingMode.HALF_UP));
} else {
return UnDefType.UNDEF;
}
}
代码示例来源:origin: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
if (items != null && items.size() > 0) {
BigDecimal min = null;
for (Item item : items) {
DecimalType itemState = 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: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
if (items != null && items.size() > 0) {
BigDecimal max = null;
for (Item item : items) {
DecimalType itemState = 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: eclipse/smarthome
@Override
public <T extends State> @Nullable T getStateAs(Class<T> typeClass) {
// if a group does not have a function it cannot have a state
@Nullable
T newState = null;
if (function != null) {
newState = function.getStateAs(getStateMembers(getMembers()), typeClass);
}
if (newState == null && baseItem != null && baseItem instanceof GenericItem) {
// we use the transformation method from the base item
((GenericItem) baseItem).setState(state);
newState = baseItem.getStateAs(typeClass);
}
if (newState == null) {
newState = super.getStateAs(typeClass);
}
return newState;
}
代码示例来源:origin: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
if (items != null && items.size() > 0) {
ZonedDateTime max = null;
for (Item item : items) {
DateTimeType itemState = item.getStateAs(DateTimeType.class);
if (itemState != null) {
if (max == null || max.isAfter(itemState.getZonedDateTime())) {
max = itemState.getZonedDateTime();
}
}
}
if (max != null) {
return new DateTimeType(max);
}
}
return UnDefType.UNDEF;
}
代码示例来源:origin: eclipse/smarthome
@Override
public State calculate(Set<Item> items) {
if (items != null && items.size() > 0) {
ZonedDateTime max = null;
for (Item item : items) {
DateTimeType itemState = item.getStateAs(DateTimeType.class);
if (itemState != null) {
if (max == null || max.isBefore(itemState.getZonedDateTime())) {
max = itemState.getZonedDateTime();
}
}
}
if (max != null) {
return new DateTimeType(max);
}
}
return UnDefType.UNDEF;
}
代码示例来源:origin: eclipse/smarthome
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public State calculate(Set<Item> items) {
if (items == null || items.size() <= 0) {
return UnDefType.UNDEF;
}
QuantityType<?> sum = null;
int count = 0;
for (Item item : items) {
if (isSameDimension(item)) {
QuantityType itemState = item.getStateAs(QuantityType.class);
if (itemState != null) {
if (sum == null) {
sum = itemState; // initialise the sum from the first item
count++;
} else {
sum = sum.add(itemState);
count++;
}
}
}
}
if (sum != null && count > 0) {
BigDecimal result = sum.toBigDecimal().divide(BigDecimal.valueOf(count), RoundingMode.HALF_UP);
return new QuantityType(result, sum.getUnit());
}
return UnDefType.UNDEF;
}
代码示例来源:origin: eclipse/smarthome
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public State calculate(Set<Item> items) {
if (items == null || items.size() <= 0) {
return UnDefType.UNDEF;
}
QuantityType<?> max = null;
for (Item item : items) {
if (isSameDimension(item)) {
QuantityType itemState = item.getStateAs(QuantityType.class);
if (itemState != null) {
if (max == null
|| (max.getUnit().isCompatible(itemState.getUnit()) && max.compareTo(itemState) < 0)) {
max = itemState;
}
}
}
}
return max != null ? max : UnDefType.UNDEF;
}
代码示例来源:origin: eclipse/smarthome
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public State calculate(Set<Item> items) {
if (items == null || items.size() <= 0) {
return UnDefType.UNDEF;
}
QuantityType<?> sum = null;
for (Item item : items) {
if (isSameDimension(item)) {
QuantityType itemState = item.getStateAs(QuantityType.class);
if (itemState != null) {
if (sum == null) {
sum = itemState; // initialise the sum from the first item
} else if (sum.getUnit().isCompatible(itemState.getUnit())) {
sum = sum.add(itemState);
}
}
}
}
return sum != null ? sum : UnDefType.UNDEF;
}
代码示例来源:origin: eclipse/smarthome
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public State calculate(Set<Item> items) {
if (items == null || items.size() <= 0) {
return UnDefType.UNDEF;
}
QuantityType<?> min = null;
for (Item item : items) {
if (isSameDimension(item)) {
QuantityType itemState = item.getStateAs(QuantityType.class);
if (itemState != null) {
if (min == null
|| (min.getUnit().isCompatible(itemState.getUnit()) && min.compareTo(itemState) > 0)) {
min = itemState;
}
}
}
}
return min != null ? min : UnDefType.UNDEF;
}
代码示例来源:origin: openhab/openhab-core
private int count(Set<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(Set<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
@Override
public State calculate(Set<Item> items) {
if (items != null) {
for (Item item : items) {
if (activeState.equals(item.getStateAs(activeState.getClass()))) {
return activeState;
}
}
}
return passiveState;
}
代码示例来源:origin: openhab/openhab-core
@Override
public State calculate(Set<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/openhab-core
@Override
public State calculate(Set<Item> items) {
BigDecimal sum = BigDecimal.ZERO;
if (items != null) {
for (Item item : items) {
DecimalType itemState = item.getStateAs(DecimalType.class);
if (itemState != null) {
sum = sum.add(itemState.toBigDecimal());
}
}
}
return new DecimalType(sum);
}
内容来源于网络,如有侵权,请联系作者删除!