本文整理汇总了Java中org.openhab.core.types.State类的典型用法代码示例。如果您正苦于以下问题:Java State类的具体用法?Java State怎么用?Java State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
State类属于org.openhab.core.types包,在下文中一共展示了State类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convertToState
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Converts a value to a openhab state
* @param value A value to converrt
* @return A converted state or null
*/
public static State convertToState(Object value) {
if(value instanceof BigDecimal) {
return new DecimalType((BigDecimal)value);
} else if(value instanceof Boolean) {
return (Boolean)value ? OnOffType.ON : OnOffType.OFF;
} else if(value instanceof String) {
return new StringType((String)value);
} else if(value == null) {
return null;
} else {
logger.error("Unknown data type!");
return null;
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:StateUtils.java
示例2: createState
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Creates an openHAB {@link State} in accordance to the class of the given
* {@code propertyValue}. Currently {@link Date}, {@link BigDecimal} and
* {@link Boolean} are handled explicitly. All other {@code dataTypes} are
* mapped to {@link StringType}.
* <p>
* If {@code propertyValue} is {@code null}, {@link UnDefType#NULL} will be
* returned.
*
* @param propertyValue
*
* @return the new {@link State} in accordance to {@code dataType}. Will
* never be {@code null}.
*/
private State createState(Object propertyValue) {
if(propertyValue == null) {
return UnDefType.NULL;
}
Class<?> dataType = propertyValue.getClass();
if (Date.class.isAssignableFrom(dataType)) {
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) propertyValue);
return new DateTimeType(calendar);
} else if (BigDecimal.class.isAssignableFrom(dataType)) {
return new DecimalType((BigDecimal) propertyValue);
} else if (Boolean.class.isAssignableFrom(dataType)) {
if((Boolean) propertyValue) {
return OnOffType.ON;
} else {
return OnOffType.OFF;
}
} else {
return new StringType(propertyValue.toString());
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:38,代码来源:KoubachiBinding.java
示例3: createItemBean
import org.openhab.core.types.State; //导入依赖的package包/类
public static ItemBean createItemBean(Item item, boolean drillDown, Class<? extends State> stateClass, String clientItemName) {
ItemBean bean;
if (item instanceof GroupItem && drillDown) {
GroupItem groupItem = (GroupItem) item;
GroupItemBean groupBean = new GroupItemBean();
Collection<ItemBean> members = new HashSet<ItemBean>();
for (Item member : groupItem.getMembers()) {
members.add(createItemBean(member, false, null, null));
}
groupBean.members = members.toArray(new ItemBean[members.size()]);
bean = groupBean;
} else {
String state = stateClass==null ? item.getState().toString() : item.getStateAs(stateClass).toString();
String name = clientItemName==null ? item.getName() : clientItemName;
bean = new ItemBean(name, state);
}
return bean;
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:ReadResource.java
示例4: getStateAs
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public State getStateAs(Class<? extends State> typeClass) {
if(typeClass==UpDownType.class) {
if(state.equals(PercentType.ZERO)) {
return UpDownType.UP;
} else if(state.equals(PercentType.HUNDRED)) {
return UpDownType.DOWN;
} 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);
}
开发者ID:Neulinet,项目名称:Zoo,代码行数:21,代码来源:RollershutterItem.java
示例5: publishToAllBindings
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Publishes the event to all items bound to the same Homematic item.
*/
private void publishToAllBindings(final Event event) {
new ProviderItemIterator().iterate(event.getBindingConfig(), new ProviderItemIteratorCallback() {
@Override
public void next(HomematicBindingConfig providerBindingConfig, Item item, Converter<?> converter) {
if (!item.getName().equals(event.getItem().getName())) {
if (event.isCommand()) {
context.getEventPublisher().postCommand(item.getName(), (Command) event.getType());
} else {
State state = converter.convertFromBinding(event.getHmValueItem());
context.getEventPublisher().postUpdate(item.getName(), state);
}
}
}
});
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:HomematicCommunicator.java
示例6: parseBuffer
import org.openhab.core.types.State; //导入依赖的package包/类
/**
*
* Main function to parse ASCII string received
* @return
*
*/
@Override
protected void parseBuffer(String itemName, Command aCommand, Direction theDirection,ByteBuffer byteBuffer){
String theUpdate = "";
try {
theUpdate = new String(byteBuffer.array(), charset).split("\0")[0];
} catch (UnsupportedEncodingException e) {
logger.warn("Exception while attempting an unsupported encoding scheme");
}
ProtocolBindingProvider provider = findFirstMatchingBindingProvider(itemName);
List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,aCommand);
String transformedResponse = transformResponse(provider.getProtocolCommand(itemName, aCommand),theUpdate);
State newState = createStateFromString(stateTypeList,transformedResponse);
if(newState != null) {
eventPublisher.postUpdate(itemName, newState);
} else {
logger.warn("Can not parse input "+theUpdate+" to match command {} on item {} ",aCommand,itemName);
}
}
开发者ID:Neulinet,项目名称:Zoo,代码行数:30,代码来源:TCPBinding.java
示例7: internalReceiveCommand
import org.openhab.core.types.State; //导入依赖的package包/类
@Override
protected void internalReceiveCommand(String itemName, Command command) {
for (EnoceanBindingProvider provider : providers) {
logger.debug("Checking provider with names {}", provider.getItemNames());
ParameterAddress parameterAddress = provider.getParameterAddress(itemName);
State actualState = provider.getItem(itemName).getState();
String parameterKey = parameterAddress.getParameterId();
CommandConverter<?, ?> commandConverter = converterFactory.getCommandConverter(parameterKey, command);
if (commandConverter == null) {
logger.debug("No command converter found for {}. No command will be executed.", parameterAddress);
return;
}
State newState = commandConverter.convertFrom(actualState, command);
setStateOnDevice(newState, parameterAddress);
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:EnoceanBinding.java
示例8: processTitleCommand
import org.openhab.core.types.State; //导入依赖的package包/类
private void processTitleCommand(String command, String value) {
if (DISPLAY_PATTERN.matcher(value).matches()) {
Integer commandNo = Integer.valueOf(value.substring(1, 2));
String titleValue = value.substring(2);
if (commandNo == 0) {
displayNowplaying = titleValue.contains("Now Playing");
}
State state = displayNowplaying ? new StringType(cleanupDisplayInfo(titleValue)) : UnDefType.UNDEF;
switch (commandNo) {
case 1:
sendUpdate(DenonProperty.TRACK.getCode(), state);
break;
case 2:
sendUpdate(DenonProperty.ARTIST.getCode(), state);
break;
case 4:
sendUpdate(DenonProperty.ALBUM.getCode(), state);
break;
}
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:DenonConnector.java
示例9: handleEvent
import org.openhab.core.types.State; //导入依赖的package包/类
@Override
void handleEvent(ZWaveCommandClassValueEvent event, Item item, Map<String, String> arguments) {
if(arguments.get("scene")==null)
return;
int scene = Integer.parseInt(arguments.get("scene"));
if(scene != (Integer)event.getValue())
return;
Integer state = Integer.parseInt(arguments.get("state"));
ZWaveStateConverter<?,?> converter = this.getStateConverter(item, state);
if (converter == null) {
logger.warn("No converter found for item = {}, node = {} endpoint = {}, ignoring event.", item.getName(), event.getNodeId(), event.getEndpoint());
return;
}
State itemState = converter.convertFromValueToState(event.getValue());
this.getEventPublisher().postUpdate(item.getName(), itemState);
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:ZWaveSceneConverter.java
示例10: getStateAs
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* @{inheritDoc
*/
public State getStateAs(List<Item> items, Class<? extends State> stateClass) {
State state = calculate(items);
if(stateClass.isInstance(state)) {
return state;
} else {
if(stateClass == DecimalType.class) {
if(items!=null) {
return new DecimalType(items.size() - count(items, activeState));
} else {
return DecimalType.ZERO;
}
} else {
return null;
}
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:ArithmeticGroupFunction.java
示例11: internalReceiveUpdate
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveUpdate(String itemName, State newState) {
// the code being executed when a state was sent on the openHAB
// event bus goes here. This method is only called if one of the
// BindingProviders provide a binding for the given 'itemName'.
if (logger.isDebugEnabled()) {
logger.debug("internalReceiveUpdate({},{}) is called!", itemName, newState);
}
}
开发者ID:docbender,项目名称:openHAB-Simatic,代码行数:13,代码来源:SimaticBinding.java
示例12: postState
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Method post item state into openHAB
*
* @param itemName
* @param state
*/
public void postState(String itemName, State state) {
if (state == null) {
logger.warn("{} - Incoming data item {} - Unknown state", toString(), itemName);
} else {
if (logger.isDebugEnabled()) {
logger.debug("{} - Incoming data - item:{}/state:{}", toString(), itemName, state);
}
if (eventPublisher != null) {
eventPublisher.postUpdate(itemName, state);
}
}
}
开发者ID:docbender,项目名称:openHAB-Simatic,代码行数:20,代码来源:SimaticGenericDevice.java
示例13: resourceValueUpdateReceived
import org.openhab.core.types.State; //导入依赖的package包/类
@Override
public void resourceValueUpdateReceived(EventObject event,
WSResourceValue value) {
for (IhcBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
int resourceId = provider.getResourceIdForInBinding(itemName);
if (value.getResourceID() == resourceId) {
if (!provider.hasInBinding(itemName)) {
logger.trace(
"{} has no inbinding...skip update to OpenHAB bus",
itemName);
} else {
Class<? extends Item> itemType = provider
.getItemType(itemName);
State state = IhcDataConverter
.convertResourceValueToState(itemType, value);
logger.trace(
"Received resource value update (item='{}', state='{}')",
new Object[] { itemName, state });
eventPublisher.postUpdate(itemName, state);
}
}
}
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:37,代码来源:IhcBinding.java
示例14: internalReceiveUpdate
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveUpdate(String itemName, State newState) {
// the code being executed when a state was sent on the openHAB
// event bus goes here. This method is only called if one of the
// BindingProviders provide a binding for the given 'itemName'.
logger.debug("internalReceiveUpdate() is called!");
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:11,代码来源:k8055Binding.java
示例15: getOnOffState
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Returns the current heating state
* @param itemType
* @return
*/
public State getOnOffState(Class<? extends Item> itemType) {
if (itemType == StringItem.class)
return dcbState == 1 ? StringType.valueOf("ON") : StringType
.valueOf("OFF");
if (itemType == SwitchItem.class)
return dcbState == 1 ? OnOffType.ON : OnOffType.OFF;
// Default to DecimalType
return DecimalType.valueOf(Integer.toString(dcbState));
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:16,代码来源:HeatmiserThermostat.java
示例16: getFrostTemperature
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* Returns the current frost temperature
* @param itemType
* @return
*/
public State getFrostTemperature(Class<? extends Item> itemType) {
if (itemType == StringItem.class)
return StringType.valueOf(Double.toString(dcbFrostTemperature));
// Default to DecimalType
return DecimalType.valueOf(Double.toString(dcbFrostTemperature));
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:13,代码来源:HeatmiserThermostat.java
示例17: postUpdate
import org.openhab.core.types.State; //导入依赖的package包/类
private void postUpdate(Enigma2BindingProvider provider, Item item,
final String value) {
Class<? extends Item> itemType = provider.getItemType(item.getName());
State state = createState(itemType, value);
if (state != null) {
if (item instanceof GenericItem) {
((GenericItem) item).setState(state);
}
eventPublisher.postUpdate(item.getName(), state);
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:13,代码来源:Enigma2Binding.java
示例18: getAcceptedDataTypes
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public List<Class<? extends State>> getAcceptedDataTypes(String itemName, Command command) {
if(itemName != null) {
IRtransBindingConfig config = (IRtransBindingConfig) bindingConfigs.get(itemName);
if(config != null) {
IRtransBindingConfigElement element = config.get(command);
if(element != null) {
return element.getAcceptedTypes();
}
}
}
return null;
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:16,代码来源:IRtransGenericBindingProvider.java
示例19: calculate
import org.openhab.core.types.State; //导入依赖的package包/类
/**
* @{inheritDoc
*/
public State calculate(List<Item> items) {
if(items.size()>0) {
State state = items.get(0).getState();
for(int i=1; i<items.size(); i++) {
if(!state.equals(items.get(i).getState())) {
return UnDefType.UNDEF;
}
}
return state;
} else {
return UnDefType.UNDEF;
}
}
开发者ID:Neulinet,项目名称:Zoo,代码行数:17,代码来源:GroupFunction.java
示例20: getAcceptedDataTypes
import org.openhab.core.types.State; //导入依赖的package包/类
public List<Class<? extends State>> getAcceptedDataTypes() {
List<Class<? extends State>> list = new ArrayList<Class<? extends State>>();
/*list.add(OnOffType.class);
list.add(PercentType.class);
list.add(UnDefType.class);*/
return list;
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:8,代码来源:SysteminfoGenericBindingProviderTest.java
注:本文中的org.openhab.core.types.State类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论