当前位置: 首页>>代码示例>>Java>>正文


Java Item类代码示例

本文整理汇总了Java中org.openhab.core.items.Item的典型用法代码示例。如果您正苦于以下问题:Java Item类的具体用法?Java Item怎么用?Java Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Item类属于org.openhab.core.items包,在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processBindingConfiguration

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void processBindingConfiguration(String context, Item item,
		String bindingConfig) throws BindingConfigParseException {
	super.processBindingConfiguration(context, item, bindingConfig);
	BenqProjectorBindingConfig config = new BenqProjectorBindingConfig();

	if (bindingConfig.equalsIgnoreCase("power")) {
		config.mode = BenqProjectorItemMode.POWER;
	} else if (bindingConfig.equalsIgnoreCase("mute")) {
		config.mode = BenqProjectorItemMode.MUTE;
	} else if (bindingConfig.equalsIgnoreCase("volume")) {
		config.mode = BenqProjectorItemMode.VOLUME;
	} else if (bindingConfig.equalsIgnoreCase("lamp_hours")) {
		config.mode = BenqProjectorItemMode.LAMP_HOURS;
	} else if (bindingConfig.equalsIgnoreCase("source_number")) {
		config.mode = BenqProjectorItemMode.SOURCE_NUMBER;
	} else if (bindingConfig.equalsIgnoreCase("source_string")) {
		config.mode = BenqProjectorItemMode.SOURCE_STRING;
	} else {
		throw new BindingConfigParseException("Unable to parse '"
				+ bindingConfig + "' to create a valid item binding.");
	}
	logger.debug("Adding " + item.getName() + " as " + config.mode);
	addBindingConfig(item, config);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:29,代码来源:BenqProjectorGenericBindingProvider.java

示例2: updateItemState

import org.openhab.core.items.Item; //导入依赖的package包/类
private void updateItemState(String itemName, int value) {
   	Class<? extends Item> itemType = getItemType(itemName);
   	if (itemType.equals(SwitchItem.class)) {
    	if (value == 0) {
    		eventPublisher.postUpdate(itemName, OnOffType.OFF);
    	} else if (value == 1) {
    		eventPublisher.postUpdate(itemName, OnOffType.ON);
    	}
   	} 
   	
   	if (itemType.equals(ContactItem.class)) {
    	if (value == 0) {
    		eventPublisher.postUpdate(itemName, OpenClosedType.OPEN);
    	} else if (value == 1) {
    		eventPublisher.postUpdate(itemName, OpenClosedType.CLOSED);
    	}
   	}		
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:PifaceBinding.java

示例3: parseAndAddBindingConfig

import org.openhab.core.items.Item; //导入依赖的package包/类
private void parseAndAddBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
	ProtocolBindingConfig newConfig = new ProtocolBindingConfig();
	Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig);

	if (!matcher.matches()) {
		throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration");
	}
	matcher.reset();

	while (matcher.find()) {
		String bindingConfigPart = matcher.group(1);
		if (StringUtils.isNotBlank(bindingConfigPart)) {
			parseBindingConfig(newConfig,item, bindingConfigPart);
			addBindingConfig(item, newConfig);
		}
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:18,代码来源:ProtocolGenericBindingProvider.java

示例4: processBindingConfiguration

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig)
		throws BindingConfigParseException {
	super.processBindingConfiguration(context, item, bindingConfig);

	try {
		MiosBindingConfig config = parseBindingConfig(context, item, bindingConfig);
		config.validateItemType(item);

		logger.debug("processBindingConfiguration: Adding Item '{}' Binding '{}', from '{}'",
				new Object[] { item.getName(), config, context });
		addBindingConfig(item, config);
	} catch (BindingConfigParseException bcpe) {
		logger.debug(String
				.format("processBindingConfiguration: Exception parsing/validating context '%s', item'%s', bindingConfig '%s'.  Exception is %s.",
						context, item, bindingConfig, bcpe.getMessage()));

		throw bcpe;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:24,代码来源:MiosBindingProviderImpl.java

示例5: getAllItems

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * Collects all items that are represented by a given list of widgets
 * 
 * @param widgets the widget list to get the items for
 * @return all items that are represented by the list of widgets
 */
private Set<GenericItem> getAllItems(EList<Widget> widgets) {
	Set<GenericItem> items = new HashSet<GenericItem>();
	if(itemRegistry!=null) {
		for(Widget widget : widgets) {
			String itemName = widget.getItem();
			if(itemName!=null) {
				try {
					Item item = itemRegistry.getItem(itemName);
					if (item instanceof GenericItem) {
						final GenericItem gItem = (GenericItem) item;
						items.add(gItem);
					}
				} catch (ItemNotFoundException e) {
					// ignore
				}
			} else {
				if(widget instanceof Frame) {
					items.addAll(getAllItems(((Frame) widget).getChildren()));
				}
			}
		}
	}
	return items;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:31,代码来源:WebAppServlet.java

示例6: handleItems

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * This method handles an items command. 
 * 
 * @param args array which contains the arguments for the items command
 * @param console the console for printing messages for the user
 */
static public void handleItems(String[] args, Console console) {
	ItemRegistry registry = (ItemRegistry) CompatibilityActivator.itemRegistryTracker.getService();
	if(registry!=null) {
		String pattern = (args.length == 0) ? "*" : args[0];
		Collection<Item> items = registry.getItems(pattern);
		if(items.size()>0) {
			for(Item item : items) {
				console.println(item.toString());
			}
		} else {
			console.println("No items found for this pattern.");
		}
	} else {
		console.println("Sorry, no item registry service available!");
	}
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:23,代码来源:ConsoleInterpreter.java

示例7: sumSince

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * Gets the sum of the state of a given <code>item</code> since a certain point in time. 
 * The {@link PersistenceService} identified by the <code>serviceName</code> is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return the sum state value since the given point in time
 */

static public DecimalType sumSince(Item item, AbstractInstant timestamp, String serviceName) {
	Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
	Iterator<HistoricItem> it = result.iterator();
	
	double sum = 0;
	while(it.hasNext()) {
		State state = it.next().getState();
		if (state instanceof DecimalType) {
			sum += ((DecimalType) state).doubleValue();
		}
	}

	return new DecimalType(sum);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:PersistenceExtensions.java

示例8: receiveCommand

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node,
		ZWaveMeterCommandClass commandClass, int endpointId, Map<String,String> arguments) {
	
	// It's not an ON command from a button switch, do not reset
	if (command != OnOffType.ON)
		return;
	
	// get the reset message - will return null if not supported
	SerialMessage serialMessage = node.encapsulate(commandClass.getResetMessage(), commandClass, endpointId);
	
	if (serialMessage == null) {
		logger.warn("NODE {}: Meter reset not supported for item = {}, endpoint = {}, ignoring event.", node.getNodeId(), item.getName(), endpointId);
		return;
	}
	
	// send reset message
	this.getController().sendData(serialMessage);
	
	// poll the device
	for (SerialMessage serialGetMessage : commandClass.getDynamicValues(true)) {
		this.getController().sendData(node.encapsulate(serialGetMessage, commandClass, endpointId));
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:28,代码来源:ZWaveMeterConverter.java

示例9: processBindingConfiguration

import org.openhab.core.items.Item; //导入依赖的package包/类
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig)
		throws BindingConfigParseException {
	super.processBindingConfiguration(context, item, bindingConfig);

	final String[] configParts = bindingConfig.trim().split(":");
	if (configParts.length != 2) {
		throw new BindingConfigParseException(
				"FrontierSiliconRadio configuration must contain of two parts separated by a ':'");
	}

	final String deviceId = configParts[0];
	final String property = configParts[1];
	final Class<? extends Item> itemType = item.getClass();
	final FrontierSiliconRadioBindingConfig config = new FrontierSiliconRadioBindingConfig(deviceId, property,
			itemType);

	addBindingConfig(item, config);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:FrontierSiliconRadioGenericBindingProvider.java

示例10: handleItems

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * This method handles an items command. 
 * 
 * @param args array which contains the arguments for the items command
 * @param console the console for printing messages for the user
 */
static public void handleItems(String[] args, Console console) {
	ItemRegistry registry = (ItemRegistry) ConsoleActivator.itemRegistryTracker.getService();
	if(registry!=null) {
		String pattern = (args.length == 0) ? "*" : args[0];
		Collection<Item> items = registry.getItems(pattern);
		if(items.size()>0) {
			for(Item item : items) {
				console.println(item.toString());
			}
		} else {
			console.println("No items found for this pattern.");
		}
	} else {
		console.println("Sorry, no item registry service available!");
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:ConsoleInterpreter.java

示例11: createOneWireDeviceProperty

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * @param pvItem
 * @param pvBindingConfig
 * @return a new BindingConfig, corresponding to the given <code><pvItem/code> and <code><pvBindingConfig/code>
 * @throws BindingConfigParseException
 */
public static OneWireBindingConfig createOneWireDeviceProperty(Item pvItem, String pvBindingConfig) throws BindingConfigParseException {
	logger.debug("createOneWireDeviceProperty: " + pvItem.getName() + " - bindingConfig:" + pvBindingConfig);

	OneWireBindingConfig lvNewBindingConfig = null;
	if (OneWireClearCacheControlBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
		lvNewBindingConfig = new OneWireClearCacheControlBindingConfig(pvBindingConfig);
	} else if (OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
		lvNewBindingConfig = new OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(pvBindingConfig);
	} else if (pvItem instanceof NumberItem) {
		lvNewBindingConfig = new OneWireDevicePropertyNumberBindingConfig(pvBindingConfig);
	} else if (pvItem instanceof ContactItem) {
		lvNewBindingConfig = new OneWireDevicePropertyContactBindingConfig(pvBindingConfig);
	} else if (pvItem instanceof SwitchItem) {
		lvNewBindingConfig = new OneWireDevicePropertySwitchBindingConfig(pvBindingConfig);
	} else if (pvItem instanceof StringItem) {
		lvNewBindingConfig = new OneWireDevicePropertyStringBindingConfig(pvBindingConfig);
	} else {
		throw new UnsupportedOperationException("the item-type " + pvItem.getClass() + " cannot be a onewire device");
	}

	logger.debug("created newBindingConfig: " + lvNewBindingConfig.toString());

	return lvNewBindingConfig;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:31,代码来源:OneWireBindingConfigFactory.java

示例12: processBindingConfiguration

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * Binding config in the style {em=
 * "type=01|02|03;address=AA;datapoint=CUMULATED_VALUE;correctionFactor=NN"}
 * {@inheritDoc}
 */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig)
		throws BindingConfigParseException {
	super.processBindingConfiguration(context, item, bindingConfig);
	String[] parts = bindingConfig.split(";");
	String address = null;
	EMType type = null;
	Datapoint datapoint = null;
	double correctionFactor = 0;
	for (String part : parts) {
		String[] keyValue = part.split("=");
		if ("type".equals(keyValue[0])) {
			type = EMType.getFromTypeValue(keyValue[1]);
		} else if ("address".equals(keyValue[0])) {
			address = keyValue[1];
		} else if ("datapoint".equals(keyValue[0])) {
			datapoint = Datapoint.valueOf(keyValue[1]);
		} else if ("correctionFactor".equals(keyValue[0])) {
			correctionFactor = Double.parseDouble(keyValue[1]);
		}
	}
	EMBindingConfig config = new EMBindingConfig(type, address, datapoint, item, correctionFactor);

	addBindingConfig(item, config);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:31,代码来源:EMGenericBindingProvider.java

示例13: changedSince

import org.openhab.core.items.Item; //导入依赖的package包/类
/**
 * Checks if the state of a given <code>item</code> has changed since a certain point in time. 
 * The {@link PersistenceService} identified by the <code>serviceName</code> is used. 
 * 
 * @param item the item to check for state changes
 * @param the point in time to start the check 
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return true, if item state had changed
 */
static public Boolean changedSince(Item item, AbstractInstant timestamp, String serviceName) {
	Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
	Iterator<HistoricItem> it = result.iterator();
	HistoricItem itemThen = historicState(item, timestamp);
	if(itemThen == null) {
		// Can't get the state at the start time
		// If we've got results more recent that this, it must have changed
		return(it.hasNext());
	}

	State state = itemThen.getState();
	while(it.hasNext()) {
		HistoricItem hItem = it.next();
		if(state!=null && !hItem.getState().equals(state)) {
			return true;
		}
		state = hItem.getState();
	}
	return false;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:30,代码来源:PersistenceExtensions.java

示例14: getSingleResponseObject

import org.openhab.core.items.Item; //导入依赖的package包/类
@Override
protected Object getSingleResponseObject(Item item, HttpServletRequest request) {
	ItemStateListBean responseBean ;
	Collection<ItemBean> beans = new LinkedList<ItemBean>();
	if (itemNames.containsKey(item.getName())) {
		for (ReturnType rt : itemNames.get(item.getName())) {
			if (rt.getStateClass()!=null) {
				beans.add(new ItemBean(rt.getClientItemName(), item.getStateAs(rt.getStateClass()).toString()));
			} else {
				beans.add(new ItemBean(rt.getClientItemName(), item.getState().toString()));
			}
		}
	} else {
		beans.add(new ItemBean(item.getName(), item.getState().toString()));
	}
	responseBean = new ItemStateListBean( new ItemListBean(beans));
	responseBean.index = System.currentTimeMillis();
	return responseBean;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:ItemStateChangeListener.java

示例15: putItemState

import org.openhab.core.items.Item; //导入依赖的package包/类
@PUT @Path("/{itemname: [a-zA-Z_0-9]*}/state")
@Consumes(MediaType.TEXT_PLAIN)	
public Response putItemState(@PathParam("itemname") String itemname, String value) {
   	final Item item = getItem(itemname);
   	if(item!=null) {
   		final State state = TypeParser.parseState(item.getAcceptedDataTypes(), value);
   		if(state!=null) {
   			if (logger.isDebugEnabled()) logger.debug("Received HTTP PUT request at '{}' with value '{}'.", uriInfo.getPath(), value);
   			RESTApplication.getEventPublisher().postUpdate(itemname, state);
   			return Response.ok().build();
   		} else {
   			if (logger.isDebugEnabled()) logger.warn("Received HTTP PUT request at '{}' with an invalid status value '{}'.", uriInfo.getPath(), value);
   			return Response.status(Status.BAD_REQUEST).build();
   		}
   	} else {
   		logger.info("Received HTTP PUT request at '{}' for the unknown item '{}'.", uriInfo.getPath(), itemname);
   		throw new WebApplicationException(404);
   	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:ItemResource.java


注:本文中的org.openhab.core.items.Item类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。