本文整理了Java中org.eclipse.smarthome.core.items.Item.getAcceptedCommandTypes()
方法的一些代码示例,展示了Item.getAcceptedCommandTypes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getAcceptedCommandTypes()
方法的具体详情如下:
包路径:org.eclipse.smarthome.core.items.Item
类名称:Item
方法名:getAcceptedCommandTypes
[英]This method provides a list of all command types that can be used for this item
Imagine e.g. a dimmer device: You could ask it to dim to 0%, 10%, 50%, 100%, but also to turn OFF or ON. So the accepted command types would be in this case PercentType, OnOffType
[中]此方法提供可用于此项的所有命令类型的列表
例如,想象一个调光器设备:您可以要求它调暗到0%、10%、50%、100%,但也可以关闭或打开。因此,在本例中,接受的命令类型是PercentType,OnOffType
代码示例来源:origin: eclipse/smarthome
/**
* The accepted command types of a group item is the same as of the underlying base item.
* If none is defined, the intersection of all sets of accepted command types of all group
* members is used instead.
*
* @return the accepted command types of this group item
*/
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends Command>> getAcceptedCommandTypes() {
if (baseItem != null) {
return baseItem.getAcceptedCommandTypes();
} else {
List<Class<? extends Command>> acceptedCommandTypes = null;
for (Item item : members) {
if (acceptedCommandTypes == null) {
acceptedCommandTypes = new ArrayList<>(item.getAcceptedCommandTypes());
} else {
acceptedCommandTypes.retainAll(item.getAcceptedCommandTypes());
}
}
return acceptedCommandTypes == null ? Collections.unmodifiableList(Collections.EMPTY_LIST)
: Collections.unmodifiableList(acceptedCommandTypes);
}
}
代码示例来源:origin: openhab/openhab-core
private static <T extends State> List<String> getAcceptedCommandNames(Item item) {
return item.getAcceptedCommandTypes().stream().map(t -> t.getSimpleName()).collect(Collectors.toList());
}
代码示例来源:origin: openhab/openhab-core
/**
* The accepted command types of a group item is the same as of the underlying base item.
* If none is defined, the intersection of all sets of accepted command types of all group
* members is used instead.
*
* @return the accepted command types of this group item
*/
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends Command>> getAcceptedCommandTypes() {
if (baseItem != null) {
return baseItem.getAcceptedCommandTypes();
} else {
List<Class<? extends Command>> acceptedCommandTypes = null;
for (Item item : members) {
if (acceptedCommandTypes == null) {
acceptedCommandTypes = new ArrayList<>(item.getAcceptedCommandTypes());
} else {
acceptedCommandTypes.retainAll(item.getAcceptedCommandTypes());
}
}
return acceptedCommandTypes == null ? Collections.unmodifiableList(Collections.EMPTY_LIST)
: Collections.unmodifiableList(acceptedCommandTypes);
}
}
代码示例来源:origin: openhab/openhab-core
private synchronized void calculateAcceptedTypes() {
acceptedCommandTypeMap.clear();
acceptedStateTypeMap.clear();
for (ItemFactory itemFactory : itemFactories) {
for (String itemTypeName : itemFactory.getSupportedItemTypes()) {
Item item = itemFactory.createItem(itemTypeName, "tmp");
if (item != null) {
acceptedCommandTypeMap.put(itemTypeName, item.getAcceptedCommandTypes());
acceptedStateTypeMap.put(itemTypeName, item.getAcceptedDataTypes());
} else {
logger.error("Item factory {} suggested it can create items of type {} but returned null",
itemFactory, itemTypeName);
}
}
}
}
代码示例来源:origin: openhab/openhab-core
if (commandType == null || item.getAcceptedCommandTypes().contains(commandType)) {
String name = item.getName();
boolean insert = true;
代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope
/**
* Sends a command for a specified item to the event bus.
*
* @param itemName the name of the item to send the command to
* @param commandString the command to send
*/
public Object sendCommand(String itemName, String commandString) {
if (eventPublisher != null && itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} catch (ItemNotFoundException e) {
LoggerFactory.getLogger(ScriptBusEvent.class).warn("Item '{}' does not exist.", itemName);
}
}
return null;
}
代码示例来源:origin: openhab/openhab-core
/**
* Sends a command for a specified item to the event bus.
*
* @param itemName the name of the item to send the command to
* @param commandString the command to send
*/
public Object sendCommand(String itemName, String commandString) {
if (eventPublisher != null && itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} catch (ItemNotFoundException e) {
LoggerFactory.getLogger(ScriptBusEvent.class).warn("Item '{}' does not exist.", itemName);
}
}
return null;
}
代码示例来源:origin: org.eclipse.smarthome.extension.ui/org.eclipse.smarthome.ui.basic
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
for (Object key : req.getParameterMap().keySet()) {
String itemName = key.toString();
if (!itemName.startsWith("__")) { // all additional webapp params start with "__" and should be ignored
String commandName = req.getParameter(itemName);
try {
Item item = itemRegistry.getItem(itemName);
// we need a special treatment for the "TOGGLE" command of switches;
// this is no command officially supported and must be translated
// into real commands by the webapp.
if ((item instanceof SwitchItem || item instanceof GroupItem) && commandName.equals("TOGGLE")) {
commandName = OnOffType.ON.equals(item.getStateAs(OnOffType.class)) ? "OFF" : "ON";
}
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
if (command != null) {
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} else {
logger.warn("Received unknown command '{}' for item '{}'", commandName, itemName);
}
} catch (ItemNotFoundException e) {
logger.warn("Received command '{}' for item '{}', but the item does not exist in the registry",
commandName, itemName);
}
}
}
}
代码示例来源:origin: openhab/openhab-core
command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), value);
代码示例来源:origin: openhab/openhab-core
if (item.getAcceptedCommandTypes().contains(cmd.getClass())) {
commandObj = (Command) cmd;
commandObj = TypeParser.parseCommand(item.getAcceptedCommandTypes(), command);
代码示例来源:origin: openhab/openhab-core
/**
* Sends a command for a specified item to the event bus.
*
* @param itemName the name of the item to send the command to
* @param commandString the command to send
*/
static public Object sendCommand(String itemName, String commandString) {
ItemRegistry registry = ScriptServiceUtil.getItemRegistry();
EventPublisher publisher = ScriptServiceUtil.getEventPublisher();
if (publisher != null && registry != null) {
try {
Item item = registry.getItem(itemName);
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
if (command != null) {
publisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} else {
LoggerFactory.getLogger(BusEvent.class).warn(
"Cannot convert '{}' to a command type which item '{}' accepts: {}.", commandString,
itemName, getAcceptedCommandNames(item));
}
} catch (ItemNotFoundException e) {
LoggerFactory.getLogger(BusEvent.class).warn("Item '{}' does not exist.", itemName);
}
}
return null;
}
代码示例来源:origin: openhab/openhab-core
if (args.length > 1) {
String commandName = args[1];
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
if (command != null) {
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
"Error: Command '" + commandName + "' is not valid for item '" + itemName + "'");
console.println("Valid command types are:");
for (Class<? extends Command> acceptedType : item.getAcceptedCommandTypes()) {
console.print(" " + acceptedType.getSimpleName());
if (acceptedType.isEnum()) {
代码示例来源:origin: openhab/openhab-core
case COMMAND:
if (newType instanceof Command) {
List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
final Command command = (Command) newType;
internalGetCommandRules(item.getName(), false, acceptedCommandTypes, command, result);
内容来源于网络,如有侵权,请联系作者删除!