use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class RuleTriggerManager method internalGetRules.
private Iterable<Rule> internalGetRules(TriggerTypes triggerType, Item item, Type oldType, Type newType) {
List<Rule> result = new ArrayList<>();
switch(triggerType) {
case STARTUP:
return systemStartupTriggeredRules;
case SHUTDOWN:
return systemShutdownTriggeredRules;
case TIMER:
return timerEventTriggeredRules;
case UPDATE:
if (newType instanceof State) {
List<Class<? extends State>> acceptedDataTypes = item.getAcceptedDataTypes();
final State state = (State) newType;
internalGetUpdateRules(item.getName(), false, acceptedDataTypes, state, result);
for (String groupName : item.getGroupNames()) {
internalGetUpdateRules(groupName, true, acceptedDataTypes, state, result);
}
}
break;
case CHANGE:
if (newType instanceof State && oldType instanceof State) {
List<Class<? extends State>> acceptedDataTypes = item.getAcceptedDataTypes();
final State newState = (State) newType;
final State oldState = (State) oldType;
internalGetChangeRules(item.getName(), false, acceptedDataTypes, newState, oldState, result);
for (String groupName : item.getGroupNames()) {
internalGetChangeRules(groupName, true, acceptedDataTypes, newState, oldState, result);
}
}
break;
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);
for (String groupName : item.getGroupNames()) {
internalGetCommandRules(groupName, true, acceptedCommandTypes, command, result);
}
}
break;
default:
break;
}
return result;
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class ItemCommandTriggerHandler method receive.
@Override
public void receive(Event event) {
if (ruleEngineCallback != null) {
logger.trace("Received Event: Source: {} Topic: {} Type: {} Payload: {}", event.getSource(), event.getTopic(), event.getType(), event.getPayload());
Map<String, Object> values = new HashMap<>();
if (event instanceof ItemCommandEvent) {
Command command = ((ItemCommandEvent) event).getItemCommand();
if (this.command == null || this.command.equals(command.toFullString())) {
values.put("command", command);
values.put("event", event);
ruleEngineCallback.triggered(this.module, values);
}
}
}
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class SendConsoleCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
if (args.length > 0) {
String itemName = args[0];
try {
Item item = this.itemRegistry.getItemByPattern(itemName);
if (args.length > 1) {
String commandName = args[1];
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
if (command != null) {
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
console.println("Command has been sent successfully.");
} else {
console.println("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()) {
console.print(": ");
for (Object e : acceptedType.getEnumConstants()) {
console.print(e + " ");
}
}
console.println("");
}
}
} else {
printUsage(console);
}
} catch (ItemNotFoundException e) {
console.println("Error: Item '" + itemName + "' does not exist.");
} catch (ItemNotUniqueException e) {
console.print("Error: Multiple items match this pattern: ");
for (Item item : e.getMatchingItems()) {
console.print(item.getName() + " ");
}
}
} else {
printUsage(console);
}
}
Aggregations