本文整理汇总了Java中org.openhab.core.items.Item.getAcceptedDataTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Item.getAcceptedDataTypes方法的具体用法?Java Item.getAcceptedDataTypes怎么用?Java Item.getAcceptedDataTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openhab.core.items.Item
的用法示例。
在下文中一共展示了Item.getAcceptedDataTypes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getToStateConverter
import org.openhab.core.items.Item; //导入方法依赖的package包/类
/**
* Returns the first matching converter for the given protocolValue and the
* item. It considers the possible types (states) the item can accept.
*
* This method is to be used for getting a converter for the direction from
* a protocolValue to a State.
*
* @param protocolValue
* The value key for the binding specific protocol.
* @param item
* The item for the converter.
* @return A new {@link StateConverter} to convert a value of the
* protocolKey to a state for the item.
*/
public StateConverter<?, ?> getToStateConverter(String protocolValue, Item item) {
List<Class<? extends State>> acceptedTypes = new ArrayList<Class<? extends State>>();
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) {
for (Class<? extends State> itemType : itemTypes) {
if(itemType.isAssignableFrom(matchingType)){
acceptedTypes.add(matchingType);
break;
}
}
}
if (acceptedTypes.isEmpty()) {
return null;
}
// Take best matching as accepted Type. Best matching is calculated by
// ordering by importance of state.
Collections.sort(acceptedTypes, new StateComparator());
Class<? extends State> acceptedType = acceptedTypes.get(acceptedTypes.size() - 1);
return (StateConverter<?, ?>) instantiate(converters.getStateConverter(protocolValue, acceptedType));
}
示例2: getStateConverter
import org.openhab.core.items.Item; //导入方法依赖的package包/类
/**
* 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;
}
示例3: createConverter
import org.openhab.core.items.Item; //导入方法依赖的package包/类
/**
* Returns the converter for an item or a custom converter if specified in
* the binding.
*/
public Converter<? extends State> createConverter(Item item, HomematicBindingConfig bindingConfig) {
if (bindingConfig != null && bindingConfig instanceof ValueBindingConfig
&& ((ValueBindingConfig) bindingConfig).getConverter() != null) {
logger.debug("Using custom converter for {}", bindingConfig);
return ((ValueBindingConfig) bindingConfig).getConverter();
}
List<Class<? extends State>> acceptedTypes = new ArrayList<Class<? extends State>>(item.getAcceptedDataTypes());
Collections.sort(acceptedTypes, typeComparator);
for (Class<? extends State> clazz : acceptedTypes) {
String converterName = clazz.getSimpleName() + "Converter";
Converter<?> converter = converterCache.get(converterName);
if (converter == null) {
try {
converter = (Converter<?>) Class.forName(CONVERTER_PACKAGE + converterName).newInstance();
converterCache.put(converterName, converter);
} catch (Exception e) {
// ignore
}
}
if (converter != null) {
return converter;
}
}
logger.warn("Can't find converter for {}, value is not published!", bindingConfig);
return null;
}
示例4: parseBindingConfig
import org.openhab.core.items.Item; //导入方法依赖的package包/类
/**
* Parses the configuration string and update the provided config
*
* @param config - the Configuration that needs to be updated with the parsing results
* @param item - the Item that this configuration is intented for
* @param bindingConfig - the configuration string that will be parsed
* @throws BindingConfigParseException
*/
private void parseBindingConfig(ProtocolBindingConfig config,Item item,
String bindingConfig) throws BindingConfigParseException {
String direction = null;
Direction directionType = null;
String commandAsString = null;
String host = null;
String port = null;
String protocolCommand = null;
if(bindingConfig != null){
Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if ((!actionMatcher.matches() && !statusMatcher.matches())) {
throw new BindingConfigParseException(getBindingType()+
" binding configuration must consist of four [config="+statusMatcher+"] or five parts [config="
+ actionMatcher + "]");
} else {
if(actionMatcher.matches()) {
direction = actionMatcher.group(1);
commandAsString = actionMatcher.group(2);
host = actionMatcher.group(3);
port = actionMatcher.group(4);
protocolCommand = actionMatcher.group(5);
} else if (statusMatcher.matches()) {
direction = statusMatcher.group(1);
commandAsString = null;
host = statusMatcher.group(2);
port = statusMatcher.group(3);
protocolCommand = statusMatcher.group(4);
}
if (direction.equals(">")){
directionType = Direction.OUT;
} else if (direction.equals("<")){
directionType = Direction.IN;
}
ProtocolBindingConfigElement newElement = new ProtocolBindingConfigElement(host,port,directionType,protocolCommand,item.getAcceptedDataTypes());
Command command = null;
if(commandAsString == null) {
// for those configuration strings that are not really linked to a openHAB command we
// create a dummy Command to be able to store the configuration information
// I have choosen to do that with NumberItems
NumberItem dummy = new NumberItem(Integer.toString(counter));
command = createCommandFromString(dummy,Integer.toString(counter));
counter++;
} else {
command = createCommandFromString(item, commandAsString);
}
config.put(command, newElement);
}
}
else
{
return;
}
}
示例5: parseBindingConfig
import org.openhab.core.items.Item; //导入方法依赖的package包/类
/**
* Parses the binding config.
*
* @param config the config
* @param item the item
* @param bindingConfig the binding config
* @throws BindingConfigParseException the binding config parse exception
*/
private void parseBindingConfig(IRtransBindingConfig config,Item item,
String bindingConfig) throws BindingConfigParseException {
String commandAsString = null;
String host = null;
String port = null;
String led = null;
String remote = null;
String irCommand = null;
Leds ledType = Leds.DEFAULT;
if(bindingConfig != null){
Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if ((!actionMatcher.matches() && !statusMatcher.matches())) {
throw new BindingConfigParseException(getBindingType()+
" binding configuration must consist of five [config="+statusMatcher.pattern()+"] or six parts [config="
+ actionMatcher.pattern() + "]");
} else {
if(actionMatcher.matches()) {
commandAsString = actionMatcher.group(1);
host = actionMatcher.group(2);
port = actionMatcher.group(3);
led = actionMatcher.group(4);
remote = actionMatcher.group(5);
irCommand = actionMatcher.group(6);
} else if (statusMatcher.matches()) {
host = statusMatcher.group(1);
port = statusMatcher.group(2);
led = statusMatcher.group(3);
remote = statusMatcher.group(4);
irCommand = statusMatcher.group(5);
}
if(led.equals("*")){
ledType = Leds.ALL;
} else {
ledType = Leds.valueOf(led);
}
IRtransBindingConfigElement newElement = new IRtransBindingConfigElement(host,port,ledType,remote,irCommand,item.getAcceptedDataTypes());
Command command = null;
if(commandAsString == null) {
// for those configuration strings that are not really linked to a openHAB command we
// create a dummy Command to be able to store the configuration information
// I have choosen to do that with NumberItems
NumberItem dummy = new NumberItem(Integer.toString(counter));
command = createCommandFromString(dummy,Integer.toString(counter));
counter++;
config.put(command, newElement);
} else {
command = createCommandFromString(item, commandAsString);
config.put(command, newElement);
}
config.put(command, newElement);
}
}
else
return;
}
示例6: parseBindingConfig
import org.openhab.core.items.Item; //导入方法依赖的package包/类
private void parseBindingConfig(SonosBindingConfig config,Item item,
String bindingConfig) throws BindingConfigParseException {
String sonosID = null;
String commandAsString = null;
String sonosCommand = null;
if(bindingConfig != null){
Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if (!actionMatcher.matches() && !statusMatcher.matches()) {
throw new BindingConfigParseException(
"Sonos binding configuration must consist of either two [config="
+ statusMatcher + "] or three parts [config="+actionMatcher+"]");
} else {
if(actionMatcher.matches()) {
commandAsString = actionMatcher.group(1);
sonosID = actionMatcher.group(2);
sonosCommand = actionMatcher.group(3);
} else if(statusMatcher.matches()){
commandAsString = null;
sonosID = statusMatcher.group(1);
sonosCommand = statusMatcher.group(2);
}
SonosBindingConfigElement newElement = new SonosBindingConfigElement(sonosCommand,sonosID,item.getAcceptedDataTypes());
Command command = null;
if(commandAsString == null) {
command = createCommandFromString(null,Integer.toString(counter));
counter++;
config.put(command, newElement);
} else {
command = createCommandFromString(item, commandAsString);
config.put(command, newElement);
}
}
}
else
return;
}